diff --git a/src/components/Common/ButtonWithDropdown/index.tsx b/src/components/Common/ButtonWithDropdown/index.tsx index b0d314d1a..bf98cdae9 100644 --- a/src/components/Common/ButtonWithDropdown/index.tsx +++ b/src/components/Common/ButtonWithDropdown/index.tsx @@ -2,7 +2,11 @@ import useClickOutside from '@app/hooks/useClickOutside'; import { withProperties } from '@app/utils/typeHelpers'; import { Transition } from '@headlessui/react'; import { ChevronDownIcon } from '@heroicons/react/24/solid'; -import type { AnchorHTMLAttributes, ButtonHTMLAttributes } from 'react'; +import type { + AnchorHTMLAttributes, + ButtonHTMLAttributes, + RefObject, +} from 'react'; import { Fragment, useRef, useState } from 'react'; interface DropdownItemProps extends AnchorHTMLAttributes { @@ -35,23 +39,33 @@ const DropdownItem = ({ ); }; -interface ButtonWithDropdownProps - extends ButtonHTMLAttributes { +interface ButtonWithDropdownProps { text: React.ReactNode; dropdownIcon?: React.ReactNode; buttonType?: 'primary' | 'ghost'; } +interface ButtonProps + extends ButtonHTMLAttributes, + ButtonWithDropdownProps { + as?: 'button'; +} +interface AnchorProps + extends AnchorHTMLAttributes, + ButtonWithDropdownProps { + as: 'a'; +} const ButtonWithDropdown = ({ + as, text, children, dropdownIcon, className, buttonType = 'primary', ...props -}: ButtonWithDropdownProps) => { +}: ButtonProps | AnchorProps) => { const [isOpen, setIsOpen] = useState(false); - const buttonRef = useRef(null); + const buttonRef = useRef(null); useClickOutside(buttonRef, () => setIsOpen(false)); const styleClasses = { @@ -78,16 +92,28 @@ const ButtonWithDropdown = ({ return ( - + {as === 'a' ? ( + } + {...(props as AnchorHTMLAttributes)} + > + {text} + + ) : ( + + )} {children && (