{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "popover",
  "title": "Popover",
  "description": "A popover that grows out from under its trigger, as wide as the trigger at first, and folds back into it. Content taller than the space left on screen scrolls inside. With presentation auto, a small touch screen opens it as a sheet from the bottom edge, unless motion is reduced.",
  "dependencies": [
    "@ui-sdk/react",
    "@ui-sdk/core"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/panel.json",
    "https://kinoui.com/r/popup.json",
    "https://kinoui.com/r/refs.json",
    "https://kinoui.com/r/scroll.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/popover.tsx",
      "content": "'use client'\n\nimport {\n  PanelHandle,\n  panelBodyFrameClassName,\n  panelFooterTint,\n  panelSheetBackdropClassName,\n  popupSheetClassName,\n  popupSheetPanelClassName,\n  useScrollRegion,\n} from '@/registry/lib/panel'\nimport {\n  HOVER_DELAY,\n  POPUP_COLLISION_PADDING,\n  popupGrowBoxClassName,\n  popupGrowContentClassName,\n  popupPlacedClassName,\n  popupSurfaceClassName,\n  usePopupPresentation,\n} from '@/registry/lib/popup'\nimport { mergeRefs } from '@/registry/lib/refs'\nimport { edgeFadeClassName } from '@/registry/lib/scroll'\nimport {\n  Popover as PopoverPrimitive,\n  PopoverClose as PopoverClosePrimitive,\n  PopoverContent as PopoverContentPrimitive,\n  PopoverDescription as PopoverDescriptionPrimitive,\n  PopoverTitle as PopoverTitlePrimitive,\n  PopoverTrigger as PopoverTriggerPrimitive,\n} from '@ui-sdk/react/popover'\nimport { type PartProps, renderElement } from '@ui-sdk/react/primitive'\nimport {\n  type ComponentProps,\n  createContext,\n  type ReactNode,\n  type Ref,\n  use,\n  useMemo,\n  useRef,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/** Why the popover opened or closed, as `onOpenChange` hears it. */\ntype PopoverOpenChangeDetails = Parameters<\n  NonNullable<ComponentProps<typeof PopoverPrimitive>['onOpenChange']>\n>[1]\n\n/* Tells the popover where its trigger is, to read the motion preference there. */\nconst TriggerContext = createContext<((element: HTMLElement | null) => void) | null>(null)\n\n/**\n * With `openOnHover`, it waits 200ms before it opens. With\n * `presentation='auto'`, a small touch screen opens it as a sheet from the\n * bottom edge, unless motion is reduced around its trigger: ui-sdk slides the\n * sheet in on a spring of its own, which reduced motion can't stop, so it\n * opens as a popover then (`popupPresentation`).\n */\nfunction Popover({\n  delay = HOVER_DELAY,\n  presentation = 'popover',\n  ...props\n}: ComponentProps<typeof PopoverPrimitive>) {\n  const [shown, setTrigger] = usePopupPresentation(presentation)\n  return (\n    <TriggerContext value={setTrigger}>\n      <PopoverPrimitive delay={delay} presentation={shown} {...props} />\n    </TriggerContext>\n  )\n}\n\nfunction PopoverTrigger({\n  ref,\n  ...props\n}: ComponentProps<typeof PopoverTriggerPrimitive>) {\n  const setTrigger = use(TriggerContext)\n  const own = useMemo(() => mergeRefs(ref, setTrigger), [ref, setTrigger])\n  return <PopoverTriggerPrimitive ref={own} {...props} />\n}\n\nfunction PopoverClose(props: ComponentProps<typeof PopoverClosePrimitive>) {\n  return <PopoverClosePrimitive {...props} />\n}\n\n/* A footer's tint and padding, set on each popup so one opened inside a sheet keeps its own. */\nconst popoverFooterClassName = cn(\n  panelFooterTint,\n  '[--popover-footer-safe:0px] [--popover-footer-y:--spacing(2)] [--popover-footer:transparent] data-[presentation=sheet]:[--popover-footer-safe:env(safe-area-inset-bottom)] data-[presentation=sheet]:[--popover-footer-y:var(--surface-padding)] data-[presentation=sheet]:[--popover-footer:var(--panel-footer)]',\n)\n\n/** What every popup on Popover's look puts on ui-sdk's content: placed, and as a sheet, as wide as the screen up to 40rem. */\nconst popoverContentClassName = cn(\n  popupPlacedClassName,\n  panelSheetBackdropClassName,\n  'border-0 p-0',\n  'flex max-h-(--available-height) max-w-(--available-width) flex-col text-sm',\n  popupSheetClassName,\n  popoverFooterClassName,\n)\n\n/**\n * The box inside ui-sdk's content, and what's in it: it grows out from under\n * its trigger and folds back into it, or as a sheet, it has a handle. For a\n * popup of ui-sdk's on the Popover's look, such as the Date picker's, as a\n * function of its content's state.\n */\nfunction PopoverBox({\n  presentation,\n  className,\n  children,\n}: {\n  presentation: 'popover' | 'sheet'\n  className?: string\n  children?: ReactNode\n}) {\n  return (\n    <div\n      className={cn(\n        'flex min-h-0 flex-1 flex-col',\n        presentation === 'sheet'\n          ? popupSheetPanelClassName\n          : cn(\n              'relative rounded-(--surface-radius)',\n              popupSurfaceClassName,\n              popupGrowBoxClassName,\n            ),\n      )}\n    >\n      {presentation === 'sheet' ? <PanelHandle /> : null}\n      <PopoverScroller sheet={presentation === 'sheet'} className={className}>\n        {children}\n      </PopoverScroller>\n    </div>\n  )\n}\n\n/**\n * The box and what's in it. It grows out from under its trigger and folds\n * back into it; as a sheet, it is as wide as the screen up to 40rem.\n * `className` goes to the content inside the box, which is\n * `--popover-width` wide (18rem); every other prop goes to ui-sdk's\n * content. Content taller than the space left on screen scrolls.\n */\nfunction PopoverContent({\n  className,\n  children,\n  side = 'bottom',\n  align = 'center',\n  sideOffset = 6,\n  inline,\n  ref,\n  ...props\n}: Omit<ComponentProps<typeof PopoverContentPrimitive>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n}) {\n  const content = usePopoverContent(ref)\n  return (\n    <PopoverContentPrimitive\n      {...content.props}\n      side={side}\n      align={align}\n      sideOffset={sideOffset}\n      inline={inline}\n      {...props}\n    >\n      {({ presentation }) => (\n        <PopoverBox presentation={presentation} className={className}>\n          {children}\n        </PopoverBox>\n      )}\n    </PopoverContentPrimitive>\n  )\n}\n\n/**\n * What scrolls inside the box, so its fading edges leave the box's shadow,\n * ring and outline whole. While it scrolls it takes focus, so the keyboard\n * can scroll it, as a region named by the title. It mounts with the open\n * popup, so it measures what it holds then.\n */\nfunction PopoverScroller({\n  sheet,\n  className,\n  children,\n}: {\n  sheet: boolean\n  className?: string\n  children: ReactNode\n}) {\n  const scrollerRef = useRef<HTMLDivElement>(null)\n  const contentRef = useRef<HTMLDivElement>(null)\n  const region = useScrollRegion(scrollerRef, contentRef)\n  return (\n    <div className={cn(panelBodyFrameClassName, 'rounded-[inherit]')}>\n      <div\n        ref={scrollerRef}\n        {...region}\n        className={cn(\n          'scrollbar-thin flex min-h-0 flex-1 flex-col overflow-y-auto overscroll-contain rounded-[inherit] focus-visible:outline-hidden',\n          edgeFadeClassName,\n        )}\n      >\n        <div\n          ref={contentRef}\n          className={cn(\n            'flex max-w-full flex-col gap-(--surface-gap) p-(--popover-edge)',\n            sheet\n              ? 'w-full [--popover-edge:var(--surface-padding-lg)]'\n              : cn(\n                  'w-(--popover-width,--spacing(72)) [--popover-edge:var(--surface-padding)]',\n                  popupGrowContentClassName,\n                ),\n            className,\n          )}\n        >\n          {children}\n        </div>\n      </div>\n    </div>\n  )\n}\n\nfunction PopoverHeader({\n  className,\n  render,\n  ...props\n}: Omit<PartProps<'div'>, 'className'> & { className?: string }) {\n  return renderElement(\n    'div',\n    {\n      'data-slot': 'popover-header',\n      className: cn('flex flex-col gap-1', className),\n      ...props,\n    },\n    render,\n  )\n}\n\nfunction PopoverTitle({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof PopoverTitlePrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <PopoverTitlePrimitive\n      className={cn('text-sm leading-snug font-medium', className)}\n      {...props}\n    />\n  )\n}\n\nfunction PopoverDescription({\n  className,\n  ...props\n}: Omit<ComponentProps<typeof PopoverDescriptionPrimitive>, 'className'> & {\n  className?: string\n}) {\n  return (\n    <PopoverDescriptionPrimitive\n      className={cn('text-muted-foreground text-sm text-pretty', className)}\n      {...props}\n    />\n  )\n}\n\n/**\n * What scrolls between a header and a footer, for a popover laid out as a\n * panel: give `PopoverContent` `min-h-0 gap-0 p-0`, and a height if it\n * should keep one. `className` goes to its content. While it scrolls it\n * takes focus, so the keyboard can scroll it, as a region named by the\n * title.\n */\nfunction PopoverBody({ className, children, ref, ...props }: ComponentProps<'div'>) {\n  const scrollerRef = useRef<HTMLDivElement>(null)\n  const contentRef = useRef<HTMLDivElement>(null)\n  const region = useScrollRegion(scrollerRef, contentRef)\n  const own = useMemo(() => mergeRefs(scrollerRef, ref), [ref])\n  return (\n    <div className={panelBodyFrameClassName}>\n      <div\n        ref={own}\n        data-slot='popover-body'\n        {...region}\n        className={cn(\n          'scrollbar-thin min-h-0 flex-1 overflow-y-auto overscroll-contain focus-visible:outline-hidden',\n          edgeFadeClassName,\n        )}\n        {...props}\n      >\n        <div ref={contentRef} className={cn('flex flex-col', className)}>\n          {children}\n        </div>\n      </div>\n    </div>\n  )\n}\n\n/**\n * Under a panel's body, such as a link to the settings. As a sheet, it takes\n * a panel footer's tint and padding, down past the screen's rounded corners.\n */\nfunction PopoverFooter({\n  className,\n  render,\n  ...props\n}: Omit<PartProps<'div'>, 'className'> & { className?: string }) {\n  return renderElement(\n    'div',\n    {\n      'data-slot': 'popover-footer',\n      className: cn(\n        'relative flex shrink-0 items-center gap-2 border-t bg-(--popover-footer) px-(--popover-edge) py-(--popover-footer-y) after:absolute after:inset-x-0 after:top-full after:h-(--popover-footer-safe) after:bg-inherit',\n        className,\n      ),\n      ...props,\n    },\n    render,\n  )\n}\n\n/**\n * What a popup on the Popover's look puts on ui-sdk's content part: its ref,\n * its offset and padding from the screen's edges, and its class.\n */\nfunction usePopoverContent(ref: Ref<HTMLDivElement> | undefined) {\n  return {\n    props: {\n      ref,\n      sideOffset: 6,\n      collisionPadding: POPUP_COLLISION_PADDING,\n      arrowPadding: 0,\n      className: popoverContentClassName,\n    },\n  }\n}\n\nexport {\n  Popover,\n  PopoverBody,\n  PopoverBox,\n  PopoverClose,\n  PopoverContent,\n  PopoverDescription,\n  PopoverFooter,\n  PopoverHeader,\n  PopoverTitle,\n  PopoverTrigger,\n  usePopoverContent,\n}\nexport type { PopoverOpenChangeDetails }\n",
      "type": "registry:component",
      "target": "@components/kino/popover.tsx"
    }
  ],
  "type": "registry:component"
}