import {flip, offset, shift, useFloating} from '@floating-ui/react' import {Popover, PopoverButton, PopoverPanel} from '@headlessui/react' import clsx from 'clsx' import {NewBadge} from 'web/components/new-badge' import {AnimationOrNothing} from '../comments/dropdown-menu' export function CustomizeableDropdown(props: { menuWidth?: string buttonContent: (open: boolean) => React.ReactNode dropdownMenuContent: React.ReactNode | ((close: () => void) => React.ReactNode) buttonClass?: string className?: string buttonDisabled?: boolean closeOnClick?: boolean withinOverflowContainer?: boolean popoverClassName?: string showNewBadge?: boolean newBadgeClassName?: string }) { const { menuWidth, buttonContent, dropdownMenuContent, buttonClass, className, buttonDisabled, withinOverflowContainer, popoverClassName, showNewBadge, newBadgeClassName, } = props const {refs, floatingStyles} = useFloating({ strategy: withinOverflowContainer ? 'fixed' : 'absolute', middleware: [offset(8), flip(), shift({padding: 8})], }) return ( {({open, close}) => ( <> ) => e.stopPropagation()} disabled={buttonDisabled} > {showNewBadge && } {buttonContent(open)} {typeof dropdownMenuContent === 'function' ? dropdownMenuContent(close) : dropdownMenuContent} )} ) }