{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "headless-disclosure", "type": "registry:ui", "title": "Headless Disclosure", "description": "A simple, accessible foundation for building custom UIs that show and hide content, like togglable accordion panels.", "dependencies": [ "@headlessui/react", "motion" ], "files": [ { "path": "registry/headless/disclosure/index.tsx", "content": "'use client';\n\nimport * as React from 'react';\nimport {\n Disclosure as DisclosurePrimitive,\n DisclosureButton as DisclosureButtonPrimitive,\n DisclosurePanel as DisclosurePanelPrimitive,\n type DisclosureProps as DisclosurePrimitiveProps,\n type DisclosureButtonProps as DisclosureButtonPrimitiveProps,\n type DisclosurePanelProps as DisclosurePanelPrimitiveProps,\n} from '@headlessui/react';\nimport {\n AnimatePresence,\n motion,\n type HTMLMotionProps,\n type Transition,\n} from 'motion/react';\n\nimport { cn } from '@/lib/utils';\n\ntype DisclosureContextType = {\n isOpen: boolean;\n};\n\nconst DisclosureContext = React.createContext<\n DisclosureContextType | undefined\n>(undefined);\n\nconst useDisclosure = (): DisclosureContextType => {\n const context = React.useContext(DisclosureContext);\n if (!context) {\n throw new Error('useDisclosure must be used within a Disclosure');\n }\n return context;\n};\n\ntype DisclosureProps =\n DisclosurePrimitiveProps & {\n as?: TTag;\n };\n\nfunction Disclosure({\n children,\n ...props\n}: DisclosureProps) {\n return (\n \n {(bag) => (\n \n {typeof children === 'function' ? children(bag) : children}\n \n )}\n \n );\n}\n\ntype DisclosureButtonProps =\n DisclosureButtonPrimitiveProps & {\n as?: TTag;\n };\n\nfunction DisclosureButton(\n props: DisclosureButtonProps,\n) {\n return ;\n}\n\ntype DisclosurePanelProps =\n Pick, 'static' | 'unmount' | 'children'> &\n Omit, 'children'> & {\n transition?: Transition;\n as?: TTag;\n };\n\nfunction DisclosurePanel(\n props: DisclosurePanelProps,\n) {\n const {\n className,\n children,\n transition = { type: 'spring', stiffness: 150, damping: 22 },\n as = motion.div,\n unmount,\n ...rest\n } = props;\n const { isOpen } = useDisclosure();\n\n return (\n \n {isOpen && (\n \n {(bag) => (\n \n {typeof children === 'function' ? children(bag) : children}\n \n )}\n \n )}\n \n );\n}\n\nexport {\n Disclosure,\n DisclosureButton,\n DisclosurePanel,\n useDisclosure,\n type DisclosureProps,\n type DisclosureButtonProps,\n type DisclosurePanelProps,\n};\n", "type": "registry:ui", "target": "components/animate-ui/headless/disclosure.tsx" } ] }