{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "headless-popover", "type": "registry:ui", "title": "Headless Popover", "description": "Popovers are perfect for floating panels with arbitrary content like navigation menus, mobile menus and flyout menus.", "dependencies": [ "@headlessui/react", "motion" ], "files": [ { "path": "registry/headless/popover/index.tsx", "content": "'use client';\n\nimport * as React from 'react';\nimport {\n Popover as PopoverPrimitive,\n PopoverButton as PopoverButtonPrimitive,\n PopoverPanel as PopoverPanelPrimitive,\n PopoverBackdrop as PopoverBackdropPrimitive,\n PopoverGroup as PopoverGroupPrimitive,\n type PopoverProps as PopoverPrimitiveProps,\n type PopoverButtonProps as PopoverButtonPrimitiveProps,\n type PopoverPanelProps as PopoverPanelPrimitiveProps,\n type PopoverBackdropProps as PopoverBackdropPrimitiveProps,\n type PopoverGroupProps as PopoverGroupPrimitiveProps,\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 PopoverContextType = {\n isOpen: boolean;\n};\n\nconst PopoverContext = React.createContext(\n undefined,\n);\n\nconst usePopover = (): PopoverContextType => {\n const context = React.useContext(PopoverContext);\n if (!context) {\n throw new Error('usePopover must be used within a Popover');\n }\n return context;\n};\n\ntype PopoverProps =\n PopoverPrimitiveProps & {\n as?: TTag;\n };\n\nfunction Popover({\n children,\n ...props\n}: PopoverProps) {\n return (\n \n {(bag) => (\n \n {typeof children === 'function' ? children(bag) : children}\n \n )}\n \n );\n}\n\ntype PopoverButtonProps =\n PopoverButtonPrimitiveProps & {\n as?: TTag;\n };\n\nfunction PopoverButton(\n props: PopoverButtonProps,\n) {\n return ;\n}\n\ntype PopoverBackdropProps =\n PopoverBackdropPrimitiveProps & {\n as?: TTag;\n };\n\nfunction PopoverBackdrop(\n props: PopoverBackdropProps,\n) {\n return ;\n}\n\ntype PopoverGroupProps =\n PopoverGroupPrimitiveProps & {\n as?: TTag;\n };\n\nfunction PopoverGroup(\n props: PopoverGroupProps,\n) {\n return ;\n}\n\ntype PopoverPanelProps = Omit<\n PopoverPanelPrimitiveProps,\n 'transition'\n> &\n Omit, 'children'> & {\n transition?: Transition;\n as?: TTag;\n };\n\nfunction PopoverPanel(props: PopoverPanelProps) {\n const {\n children,\n className,\n transition = { type: 'spring', stiffness: 300, damping: 25 },\n anchor = { to: 'bottom', gap: 4 },\n as = motion.div,\n ...rest\n } = props;\n const { isOpen } = usePopover();\n\n return (\n \n {isOpen && (\n \n {children}\n \n )}\n \n );\n}\n\nexport {\n Popover,\n PopoverButton,\n PopoverPanel,\n PopoverBackdrop,\n PopoverGroup,\n type PopoverProps,\n type PopoverButtonProps,\n type PopoverPanelProps,\n type PopoverBackdropProps,\n type PopoverGroupProps,\n};\n", "type": "registry:ui", "target": "components/animate-ui/headless/popover.tsx" } ] }