'use client'; import * as React from 'react'; import { Disclosure as DisclosurePrimitive, DisclosureButton as DisclosureButtonPrimitive, DisclosurePanel as DisclosurePanelPrimitive, type DisclosureProps as DisclosurePrimitiveProps, type DisclosureButtonProps as DisclosureButtonPrimitiveProps, type DisclosurePanelProps as DisclosurePanelPrimitiveProps, } from '@headlessui/react'; import { AnimatePresence, motion, type HTMLMotionProps, type Transition, } from 'motion/react'; import { cn } from '@workspace/ui/lib/utils'; type DisclosureContextType = { isOpen: boolean; }; const DisclosureContext = React.createContext< DisclosureContextType | undefined >(undefined); const useDisclosure = (): DisclosureContextType => { const context = React.useContext(DisclosureContext); if (!context) { throw new Error('useDisclosure must be used within a Disclosure'); } return context; }; type DisclosureProps = DisclosurePrimitiveProps & { as?: TTag; }; function Disclosure({ children, ...props }: DisclosureProps) { return ( {(bag) => ( {typeof children === 'function' ? children(bag) : children} )} ); } type DisclosureButtonProps = DisclosureButtonPrimitiveProps & { as?: TTag; }; function DisclosureButton( props: DisclosureButtonProps, ) { return ; } type DisclosurePanelProps = Pick, 'static' | 'unmount' | 'children'> & Omit, 'children'> & { transition?: Transition; as?: TTag; }; function DisclosurePanel( props: DisclosurePanelProps, ) { const { className, children, transition = { type: 'spring', stiffness: 150, damping: 22 }, as = motion.div, unmount, ...rest } = props; const { isOpen } = useDisclosure(); return ( {isOpen && ( {(bag) => ( {typeof children === 'function' ? children(bag) : children} )} )} ); } export { Disclosure, DisclosureButton, DisclosurePanel, useDisclosure, type DisclosureProps, type DisclosureButtonProps, type DisclosurePanelProps, };