Skip to content

Commit

Permalink
fix: remove headlessui dist import (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
huyenltnguyen authored Apr 5, 2024
1 parent 0cb840a commit 1fe2aea
Showing 1 changed file with 17 additions and 37 deletions.
54 changes: 17 additions & 37 deletions src/drop-down/drop-down.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,29 @@ import React, { createContext, useContext, useRef } from "react";
import { Menu } from "@headlessui/react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCaretDown, faCaretUp } from "@fortawesome/free-solid-svg-icons";
import { Props } from "@headlessui/react/dist/types";

type MenuTag = React.ExoticComponent<{
children?: React.ReactNode;
}>;

interface MenuRenderPropArg {
open: boolean;
close: () => void;
interface MenuItemsProps {
children: React.ReactNode;
className?: string;
}

type DropdownMenuProps = Props<
MenuTag,
MenuRenderPropArg,
never,
{
__demoMode?: boolean;
}
>;

export type DropdownProps = DropdownMenuProps & {
export interface DropdownProps {
children: React.ReactNode;
dropup?: boolean;
id?: string;
};

export interface ButtonRenderPropArg {
open: boolean;
}

type ButtonPropsWeControl = "aria-controls" | "aria-expanded" | "aria-haspopup";

type DropDownButtonProps = Props<
"button",
ButtonRenderPropArg,
ButtonPropsWeControl,
{
disabled?: boolean;
}
>;
interface DropDownButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
children: React.ReactNode;
className?: string;
}

type DropDownContextProps = DropdownProps & {
interface DropDownContextProps {
dropup?: boolean;
menuButtonRef: React.MutableRefObject<HTMLButtonElement | null>;
};
}

const DropDownContext = createContext<DropDownContextProps>({
menuButtonRef: React.createRef(),
});
Expand All @@ -55,7 +35,7 @@ const dropUpItems = dropDownItems + " transform -translate-y-full top-0";
const toggleClassNames =
"cursor-pointer border-3 border-solid w-full block text-center touch-manipulation bg-background-quaternary text-foreground-secondary px-3 py-1.5 relative hover:bg-foreground-secondary hover:text-background-secondary btn-block border-foreground-secondary";

export const MenuItems = React.forwardRef<HTMLDivElement, DropDownButtonProps>(
export const MenuItems = React.forwardRef<HTMLDivElement, MenuItemsProps>(
({ children, className }, ref): JSX.Element => {
const { dropup, menuButtonRef } = useContext(DropDownContext);

Expand Down Expand Up @@ -95,14 +75,14 @@ const DropDownButton = ({

export const Dropdown = ({
children,
id,
dropup,
...props
}: DropdownProps): JSX.Element => {
const menuButtonRef = useRef(null);
const context = { dropup, menuButtonRef };
return (
<DropDownContext.Provider value={context}>
<Menu className="relative w-full" as="div" {...props}>
<Menu className="relative w-full" as="div" id={id}>
{children}
</Menu>
</DropDownContext.Provider>
Expand Down

0 comments on commit 1fe2aea

Please sign in to comment.