'use client'; import * as React from 'react'; import { Popover as PopoverPrimitive, PopoverButton as PopoverButtonPrimitive, PopoverPanel as PopoverPanelPrimitive, PopoverBackdrop as PopoverBackdropPrimitive, PopoverGroup as PopoverGroupPrimitive, type PopoverProps as PopoverPrimitiveProps, type PopoverButtonProps as PopoverButtonPrimitiveProps, type PopoverPanelProps as PopoverPanelPrimitiveProps, type PopoverBackdropProps as PopoverBackdropPrimitiveProps, type PopoverGroupProps as PopoverGroupPrimitiveProps, } from '@headlessui/react'; import { AnimatePresence, motion, type HTMLMotionProps, type Transition, } from 'motion/react'; import { cn } from '@workspace/ui/lib/utils'; type PopoverContextType = { isOpen: boolean; }; const PopoverContext = React.createContext( undefined, ); const usePopover = (): PopoverContextType => { const context = React.useContext(PopoverContext); if (!context) { throw new Error('usePopover must be used within a Popover'); } return context; }; type PopoverProps = PopoverPrimitiveProps & { as?: TTag; }; function Popover({ children, ...props }: PopoverProps) { return ( {(bag) => ( {typeof children === 'function' ? children(bag) : children} )} ); } type PopoverButtonProps = PopoverButtonPrimitiveProps & { as?: TTag; }; function PopoverButton( props: PopoverButtonProps, ) { return ; } type PopoverBackdropProps = PopoverBackdropPrimitiveProps & { as?: TTag; }; function PopoverBackdrop( props: PopoverBackdropProps, ) { return ; } type PopoverGroupProps = PopoverGroupPrimitiveProps & { as?: TTag; }; function PopoverGroup( props: PopoverGroupProps, ) { return ; } type PopoverPanelProps = Omit< PopoverPanelPrimitiveProps, 'transition' > & Omit, 'children'> & { transition?: Transition; as?: TTag; }; function PopoverPanel(props: PopoverPanelProps) { const { children, className, transition = { type: 'spring', stiffness: 300, damping: 25 }, anchor = { to: 'bottom', gap: 4 }, as = motion.div, ...rest } = props; const { isOpen } = usePopover(); return ( {isOpen && ( {children} )} ); } export { Popover, PopoverButton, PopoverPanel, PopoverBackdrop, PopoverGroup, type PopoverProps, type PopoverButtonProps, type PopoverPanelProps, type PopoverBackdropProps, type PopoverGroupProps, };