{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "popover",
  "title": "Popover",
  "description": "Anchored popover with an arrow in default, soft, glass, neo and inverted surfaces, tones, sizes, radii and shadows; side and align that flip and shift to stay on screen, match-trigger-width, scale, fade, slide or spring entrances, header, close button and footer slots, and modal (focus trapped) or non-modal (Tab flows back to the page) behavior, shown as a date filter, share menu, switcher and inline note form.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json"
  ],
  "files": [
    {
      "path": "registry/components/core/popover.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { createPortal } from \"react-dom\"\nimport { AnimatePresence, motion, useReducedMotion, type TargetAndTransition, type Transition } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { GooduiTokens, spring, ease as easing } from \"@/lib/goodui-motion\"\n\n/*\n * One popover, independent layers: every axis combines with every other.\n *   variant    default, soft, glass, neo, inverted        tone       accent (soft tint, neo fill, focus ring)\n *   size       sm, md, lg, auto (width + padding)          radius     none → xl\n *   shadow     none → xl                                   animation  none, fade, scale, slide, spring\n *   placement  side × align, flips and shifts to stay on screen, optional arrow, can match the trigger width\n *   behaviour  modal (focus trapped, page blocked) or non-modal (Tab past the end returns to the page)\n *   slots      title + description header, close button, body, footer; body and footer may be (api) => node\n * Esc and outside click close it (both configurable); focus returns to the trigger.\n */\n\nexport type PopoverVariant = \"default\" | \"soft\" | \"glass\" | \"neo\" | \"inverted\"\nexport type PopoverTone = \"primary\" | \"neutral\" | \"success\" | \"warning\" | \"danger\" | \"info\"\nexport type PopoverSize = \"sm\" | \"md\" | \"lg\" | \"auto\"\nexport type PopoverRadius = \"none\" | \"sm\" | \"md\" | \"lg\" | \"xl\"\nexport type PopoverShadow = \"none\" | \"sm\" | \"md\" | \"lg\" | \"xl\"\nexport type PopoverAnimation = \"none\" | \"fade\" | \"scale\" | \"slide\" | \"spring\"\n/** start and end follow the reading direction (left/right in LTR, right/left in RTL). */\nexport type PopoverSide = \"top\" | \"bottom\" | \"left\" | \"right\" | \"start\" | \"end\"\nexport type PopoverAlign = \"start\" | \"center\" | \"end\"\nexport type PopoverApi = { close: () => void }\n\nexport type PopoverLabels = { close: string }\nconst DEFAULT_LABELS: PopoverLabels = { close: \"Close\" }\n\ntype TriggerProps = React.HTMLAttributes<HTMLElement> & { ref?: React.Ref<HTMLElement> }\ntype MotionSafe = \"onAnimationStart\" | \"onAnimationEnd\" | \"onAnimationIteration\" | \"onDrag\" | \"onDragStart\" | \"onDragEnd\" | \"onDragEnter\" | \"onDragLeave\" | \"onDragOver\" | \"onDrop\" | \"onDragExit\"\n\nexport type PopoverProps = Omit<React.ComponentProps<\"div\">, \"title\" | \"children\" | MotionSafe> & {\n  /** The element that toggles the popover (a button). It gets aria-expanded, aria-controls and aria-haspopup. */\n  trigger: React.ReactElement<TriggerProps>\n  /** Body. A function receives { close } for buttons that should close the popover. */\n  children?: React.ReactNode | ((api: PopoverApi) => React.ReactNode)\n  /** Header title; also names the popover for screen readers. Without it, pass aria-label. */\n  title?: React.ReactNode\n  /** Muted line under the title. */\n  description?: React.ReactNode\n  /** Footer row (actions). A function receives { close }. */\n  footer?: React.ReactNode | ((api: PopoverApi) => React.ReactNode)\n  /** × button in the header. Defaults to true when there is a title. */\n  showClose?: boolean\n  /** Surface: default (your popover color), soft (tone tint), glass, neo or inverted (dark on light). */\n  variant?: PopoverVariant\n  tone?: PopoverTone\n  /** Width and padding: sm 16rem, md 20rem, lg 26rem, auto fits the content. */\n  size?: PopoverSize\n  radius?: PopoverRadius\n  /** Drop shadow. Ignored by neo, which has its own offset shadow. */\n  shadow?: PopoverShadow\n  /** How it opens: scale (default), fade, slide, spring or none. Reduced motion uses a short fade. */\n  animation?: PopoverAnimation\n  /** Preferred side; flips to the opposite side when there is no room. */\n  side?: PopoverSide\n  /** Alignment along the side. start/end follow the reading direction. */\n  align?: PopoverAlign\n  /** Gap between trigger and popover, in px. */\n  offset?: number\n  arrow?: boolean\n  /** false keeps the requested side and alignment even when the popover leaves the screen. */\n  avoidCollisions?: boolean\n  /** Same width as the trigger (account switchers, comboboxes). Overrides size width. */\n  matchTriggerWidth?: boolean\n  /** true traps focus inside and blocks the page behind with a transparent layer. */\n  modal?: boolean\n  closeOnOutsideClick?: boolean\n  closeOnEsc?: boolean\n  /** Open state (controlled). */\n  open?: boolean\n  /** Initial open state when uncontrolled. */\n  defaultOpen?: boolean\n  onOpenChange?: (open: boolean) => void\n  /** Element to focus on open. Default: the first focusable element in the body, else the panel. */\n  initialFocus?: React.RefObject<HTMLElement | null>\n  /** Return focus to the trigger after closing with Esc, the close button or close(). */\n  returnFocus?: boolean\n  /** Render into document.body so overflow and z-index of parents can't clip it. */\n  portal?: boolean\n  /** Text for built-in controls; pass translations here. */\n  labels?: Partial<PopoverLabels>\n}\n\n/* ---------- positioning: flip + shift, written for this component ---------- */\n\ntype Side = \"top\" | \"bottom\" | \"left\" | \"right\"\ntype Box = { x: number; y: number; width: number; height: number }\ntype Placed = { x: number; y: number; side: Side; arrow: number; rtl: boolean; maxHeight: number }\nconst OPPOSITE: Record<Side, Side> = { top: \"bottom\", bottom: \"top\", left: \"right\", right: \"left\" }\nconst clamp = (v: number, lo: number, hi: number) => Math.min(Math.max(v, lo), Math.max(lo, hi))\n\nfunction place(a: Box, w: number, h: number, want: Side, align: PopoverAlign, offset: number, rtl: boolean, arrowPad: number, avoid: boolean): Placed {\n  const pad = 8\n  const vw = document.documentElement.clientWidth\n  const vh = window.innerHeight\n  const at = (s: Side) => {\n    if (s === \"top\" || s === \"bottom\") {\n      const y = s === \"top\" ? a.y - h - offset : a.y + a.height + offset\n      const start = rtl ? a.x + a.width - w : a.x\n      const end = rtl ? a.x : a.x + a.width - w\n      return { x: align === \"center\" ? a.x + a.width / 2 - w / 2 : align === \"start\" ? start : end, y }\n    }\n    const x = s === \"left\" ? a.x - w - offset : a.x + a.width + offset\n    return { x, y: align === \"center\" ? a.y + a.height / 2 - h / 2 : align === \"start\" ? a.y : a.y + a.height - h }\n  }\n  const over = (s: Side, p: { x: number; y: number }) =>\n    s === \"top\" ? pad - p.y : s === \"bottom\" ? p.y + h - (vh - pad) : s === \"left\" ? pad - p.x : p.x + w - (vw - pad)\n  let side = want\n  let p = at(want)\n  if (avoid && over(want, p) > 0) {\n    const q = at(OPPOSITE[want])\n    if (over(OPPOSITE[want], q) < over(want, p)) {\n      side = OPPOSITE[want]\n      p = q\n    }\n  }\n  const vertical = side === \"top\" || side === \"bottom\"\n  if (avoid) {\n    if (vertical) p.x = clamp(p.x, pad, vw - pad - w)\n    else p.y = clamp(p.y, pad, vh - pad - h)\n  }\n  // Room on the chosen side, so a tall body scrolls instead of leaving the screen.\n  const room = side === \"bottom\" ? vh - pad - (a.y + a.height + offset) : side === \"top\" ? a.y - offset - pad : vh - pad * 2\n  if (side === \"top\") p.y = Math.max(p.y, a.y - offset - Math.min(h, room))\n  const arrow = vertical ? clamp(a.x + a.width / 2 - p.x, arrowPad, w - arrowPad) : clamp(a.y + a.height / 2 - p.y, arrowPad, h - arrowPad)\n  return { x: p.x, y: p.y, side, arrow, rtl, maxHeight: Math.max(120, room) }\n}\n\nconst TABBABLE =\n  'a[href],button:not([disabled]),input:not([disabled]):not([type=\"hidden\"]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"]),[contenteditable=\"true\"],summary,audio[controls],video[controls]'\nfunction tabbables(root: ParentNode) {\n  return Array.from(root.querySelectorAll<HTMLElement>(TABBABLE)).filter((el) => el.tabIndex >= 0 && !el.closest(\"[inert]\") && el.getClientRects().length > 0)\n}\n\nfunction mergeRefs<T>(...refs: (React.Ref<T> | undefined)[]) {\n  return (el: T | null) => {\n    for (const r of refs) {\n      if (typeof r === \"function\") r(el)\n      else if (r) (r as React.RefObject<T | null>).current = el\n    }\n  }\n}\n\n/* ---------- look ---------- */\n\nconst CSS = `\n.pc-popover{--pc-c:var(--primary);--pc-fg:var(--primary-foreground)}\n.pc-popover[data-tone=neutral]{--pc-c:var(--foreground);--pc-fg:var(--background)}\n.pc-popover[data-tone=success]{--pc-c:oklch(0.53 0.13 155);--pc-fg:#fff}\n.pc-popover[data-tone=warning]{--pc-c:oklch(0.75 0.16 70);--pc-fg:oklch(0.25 0.05 70)}\n.pc-popover[data-tone=danger]{--pc-c:oklch(0.56 0.21 27);--pc-fg:#fff}\n.pc-popover[data-tone=info]{--pc-c:oklch(0.55 0.17 250);--pc-fg:#fff}\n.dark .pc-popover[data-tone=success]{--pc-c:oklch(0.7 0.16 155);--pc-fg:oklch(0.2 0.05 155)}\n.dark .pc-popover[data-tone=danger]{--pc-c:oklch(0.68 0.2 25);--pc-fg:oklch(0.2 0.05 25)}\n.dark .pc-popover[data-tone=info]{--pc-c:oklch(0.7 0.15 245);--pc-fg:oklch(0.2 0.05 245)}\n.pc-popover{--pc-tint:color-mix(in oklab,var(--pc-c) 14%,transparent);--pc-ink:color-mix(in oklab,var(--pc-c) 82%,var(--foreground))}\n.pc-popover[data-tone=warning]{--pc-ink:color-mix(in oklab,var(--pc-c) 62%,var(--foreground))}\n\n.pc-popover{--pc-bg:var(--popover);--pc-tx:var(--popover-foreground);--pc-bd:var(--border);--pc-bw:1px;--pc-as:12px;--pc-muted:var(--muted-foreground);position:relative;background:var(--pc-bg);color:var(--pc-tx);border:var(--pc-bw) solid var(--pc-bd);outline:none}\n.pc-popover[data-variant=soft]{--pc-bg:color-mix(in oklab,var(--pc-c) 6%,var(--popover));--pc-bd:color-mix(in oklab,var(--pc-c) 24%,var(--border))}\n.pc-popover[data-variant=glass]{--pc-bg:color-mix(in oklab,var(--popover) 62%,transparent);--pc-bd:color-mix(in oklab,var(--foreground) 14%,transparent);-webkit-backdrop-filter:blur(18px) saturate(1.7);backdrop-filter:blur(18px) saturate(1.7)}\n.pc-popover[data-variant=neo]{--pc-bg:var(--background);--pc-tx:var(--foreground);--pc-bd:var(--foreground);--pc-bw:2px}\n.pc-popover[data-variant=inverted]{--pc-bg:var(--foreground);--pc-tx:var(--background);--pc-bd:var(--foreground);--pc-muted:color-mix(in oklab,var(--background) 68%,var(--foreground))}\n.pc-popover-motion[data-variant=neo]{filter:drop-shadow(5px 5px 0 var(--foreground))}\n.pc-popover[data-shadow=sm]{box-shadow:0 2px 6px -1px rgb(0 0 0/.12)}\n.pc-popover[data-shadow=md]{box-shadow:0 8px 24px -8px rgb(0 0 0/.22),0 2px 6px -2px rgb(0 0 0/.08)}\n.pc-popover[data-shadow=lg]{box-shadow:0 18px 44px -14px rgb(0 0 0/.3),0 4px 10px -4px rgb(0 0 0/.1)}\n.pc-popover[data-shadow=xl]{box-shadow:0 30px 70px -20px rgb(0 0 0/.42),0 8px 18px -8px rgb(0 0 0/.14)}\n.dark .pc-popover:not([data-variant=neo]):is([data-shadow=md],[data-shadow=lg],[data-shadow=xl]){box-shadow:0 18px 44px -12px rgb(0 0 0/.65),0 0 0 1px rgb(255 255 255/.03)}\n.pc-popover[data-variant=neo][data-shadow]{box-shadow:none}\n.pc-popover-muted{color:var(--pc-muted)}\n.pc-popover-x{color:var(--pc-muted)}\n.pc-popover-x:hover{background:color-mix(in oklab,currentColor 12%,transparent);color:var(--pc-tx)}\n.pc-popover-x:focus-visible{box-shadow:0 0 0 3px color-mix(in oklab,var(--pc-c) 40%,transparent)}\n.pc-popover-foot{border-top:1px solid color-mix(in oklab,var(--pc-bd) 70%,transparent)}\n.pc-popover[data-variant=neo] .pc-popover-foot{border-top:2px solid var(--foreground)}\n\n.pc-popover-arrow{position:absolute;width:var(--pc-as);height:var(--pc-as);background:var(--pc-bg);border:var(--pc-bw) solid var(--pc-bd);transform:rotate(45deg);pointer-events:none}\n.pc-popover[data-variant=glass] .pc-popover-arrow{background:color-mix(in oklab,var(--popover) 88%,transparent)}\n.pc-popover-arrow[data-side=top]{top:calc(100% - var(--pc-as) / 2);clip-path:polygon(100% 0,100% 100%,0 100%)}\n.pc-popover-arrow[data-side=bottom]{top:calc(var(--pc-as) / -2);clip-path:polygon(0 0,100% 0,0 100%)}\n.pc-popover-arrow[data-side=left]{left:calc(100% - var(--pc-as) / 2);clip-path:polygon(0 0,100% 0,100% 100%)}\n.pc-popover-arrow[data-side=right]{left:calc(var(--pc-as) / -2);clip-path:polygon(0 0,100% 100%,0 100%)}\n`\n\nconst SIZES: Record<PopoverSize, { w: string; pad: string; px: string }> = {\n  sm: { w: \"w-64\", pad: \"p-3\", px: \"px-3\" },\n  md: { w: \"w-80\", pad: \"p-4\", px: \"px-4\" },\n  lg: { w: \"w-[26rem]\", pad: \"p-5\", px: \"px-5\" },\n  auto: { w: \"w-max\", pad: \"p-3\", px: \"px-3\" },\n}\nconst RADIUS: Record<PopoverRadius, string> = { none: \"rounded-none\", sm: \"rounded-md\", md: \"rounded-lg\", lg: \"rounded-xl\", xl: \"rounded-2xl\" }\n\nexport function Popover({\n  trigger: triggerNode,\n  children,\n  title,\n  description,\n  footer,\n  showClose,\n  variant = \"default\",\n  tone = \"primary\",\n  size = \"md\",\n  radius = \"lg\",\n  shadow = \"lg\",\n  animation = \"scale\",\n  side = \"bottom\",\n  align = \"center\",\n  offset = 8,\n  arrow = true,\n  avoidCollisions = true,\n  matchTriggerWidth = false,\n  modal = false,\n  closeOnOutsideClick = true,\n  closeOnEsc = true,\n  open: openProp,\n  defaultOpen = false,\n  onOpenChange,\n  initialFocus,\n  returnFocus = true,\n  portal = true,\n  labels,\n  className,\n  style,\n  onKeyDown,\n  ...props\n}: PopoverProps) {\n  const l = useLabels(\"popover\", DEFAULT_LABELS, labels)\n  const prefersReduced = useReducedMotion()\n  const [mounted, setMounted] = React.useState(false)\n  React.useEffect(() => setMounted(true), [])\n  const reduce = mounted && !!prefersReduced\n\n  const id = React.useId()\n  const panelId = id + \"-panel\"\n  const titleId = id + \"-title\"\n  const descId = id + \"-desc\"\n\n  const [inner, setInner] = React.useState(defaultOpen)\n  const open = openProp ?? inner\n  const trigger = React.useRef<HTMLElement | null>(null)\n  const floating = React.useRef<HTMLDivElement>(null)\n  const panel = React.useRef<HTMLDivElement>(null)\n  const insideTree = React.useRef(false)\n\n  const live = React.useRef({ open, openProp, onOpenChange, returnFocus })\n  React.useLayoutEffect(() => {\n    live.current = { open, openProp, onOpenChange, returnFocus }\n  })\n  const setOpen = React.useCallback((o: boolean) => {\n    const c = live.current\n    if (c.open === o) return\n    if (c.openProp === undefined) setInner(o)\n    c.onOpenChange?.(o)\n  }, [])\n  /** Closes; focus goes back to the trigger unless the user clicked somewhere else. */\n  const close = React.useCallback(\n    (refocus = true) => {\n      setOpen(false)\n      if (refocus && live.current.returnFocus) trigger.current?.focus({ preventScroll: true })\n    },\n    [setOpen],\n  )\n  const api = React.useMemo<PopoverApi>(() => ({ close: () => close() }), [close])\n\n  /* positioning */\n  const [pos, setPos] = React.useState<Placed | null>(null)\n  const arrowPad = radius === \"xl\" ? 22 : radius === \"lg\" ? 18 : 14\n  const update = React.useCallback(() => {\n    const el = floating.current\n    const t = trigger.current\n    if (!el || !t) return\n    const r = t.getBoundingClientRect()\n    if (matchTriggerWidth) el.style.width = `${r.width}px`\n    const rtl = getComputedStyle(t).direction === \"rtl\"\n    const s: Side = side === \"start\" ? (rtl ? \"right\" : \"left\") : side === \"end\" ? (rtl ? \"left\" : \"right\") : side\n    const next = place({ x: r.left, y: r.top, width: r.width, height: r.height }, el.offsetWidth, el.offsetHeight, s, align, offset, rtl, arrowPad, avoidCollisions)\n    setPos((p) =>\n      p &&\n      Math.abs(p.x - next.x) < 0.5 &&\n      Math.abs(p.y - next.y) < 0.5 &&\n      p.side === next.side &&\n      Math.abs(p.arrow - next.arrow) < 0.5 &&\n      p.rtl === next.rtl &&\n      Math.abs(p.maxHeight - next.maxHeight) < 0.5\n        ? p\n        : next,\n    )\n  }, [side, align, offset, arrowPad, avoidCollisions, matchTriggerWidth])\n\n  React.useLayoutEffect(() => {\n    if (!open || !mounted) return\n    update()\n    const on = () => update()\n    window.addEventListener(\"scroll\", on, { capture: true, passive: true })\n    window.addEventListener(\"resize\", on)\n    const ro = new ResizeObserver(on)\n    if (panel.current) ro.observe(panel.current)\n    if (trigger.current) ro.observe(trigger.current)\n    return () => {\n      window.removeEventListener(\"scroll\", on, { capture: true })\n      window.removeEventListener(\"resize\", on)\n      ro.disconnect()\n    }\n  }, [open, mounted, update])\n\n  /* focus in on open, once positioned (a hidden panel can't take focus) */\n  const placed = pos !== null\n  React.useEffect(() => {\n    if (!open || !mounted || !placed) return\n    const p = panel.current\n    if (!p) return\n    if (p.contains(document.activeElement)) return\n    const body = p.querySelector<HTMLElement>(\"[data-slot=popover-body]\")\n    const target = initialFocus?.current ?? (body ? tabbables(body)[0] : undefined) ?? tabbables(p).find((el) => !el.hasAttribute(\"data-close\")) ?? p\n    target.focus({ preventScroll: true })\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [open, mounted, placed])\n\n  /* outside click: the React tree counts as inside, so nested popovers and menus in portals don't close it */\n  React.useEffect(() => {\n    if (!open || modal || !closeOnOutsideClick) return\n    const onDown = (e: PointerEvent) => {\n      const inside = insideTree.current\n      insideTree.current = false\n      if (inside || trigger.current?.contains(e.target as Node)) return\n      close(false)\n    }\n    document.addEventListener(\"pointerdown\", onDown)\n    return () => document.removeEventListener(\"pointerdown\", onDown)\n  }, [open, modal, closeOnOutsideClick, close])\n\n  const onPanelKey = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    onKeyDown?.(e)\n    if (e.defaultPrevented) return\n    if (e.key === \"Escape\") {\n      if (!closeOnEsc) return\n      e.stopPropagation()\n      close()\n      return\n    }\n    const p = panel.current\n    if (e.key !== \"Tab\" || !p || !p.contains(e.target as Node)) return\n    const items = tabbables(p)\n    const first = items[0]\n    const last = items[items.length - 1]\n    const active = document.activeElement\n    if (modal) {\n      if (!first || !last) {\n        e.preventDefault()\n        return\n      }\n      if (e.shiftKey && (active === first || active === p)) {\n        e.preventDefault()\n        last.focus()\n      } else if (!e.shiftKey && active === last) {\n        e.preventDefault()\n        first.focus()\n      }\n      return\n    }\n    // Non-modal: the panel behaves as if it sat right after the trigger in the tab order.\n    if (e.shiftKey && (active === first || active === p || !first)) {\n      e.preventDefault()\n      close()\n    } else if (!e.shiftKey && (active === last || !last)) {\n      e.preventDefault()\n      const t = trigger.current\n      const scope = t?.closest<HTMLElement>(\"[aria-modal=true]\") ?? document.body\n      const list = tabbables(scope).filter((el) => !floating.current?.contains(el))\n      const next = t ? list[list.indexOf(t) + 1] : undefined\n      setOpen(false)\n      ;(next ?? t)?.focus({ preventScroll: true })\n    }\n  }\n\n  /* trigger wiring */\n  const tp = triggerNode.props\n  const triggerEl = React.cloneElement(triggerNode, {\n    ref: mergeRefs(tp.ref, (el: HTMLElement | null) => {\n      trigger.current = el\n    }),\n    \"aria-haspopup\": \"dialog\",\n    \"aria-expanded\": open,\n    \"aria-controls\": open ? panelId : undefined,\n    \"data-state\": open ? \"open\" : \"closed\",\n    onClick: (e: React.MouseEvent<HTMLElement>) => {\n      tp.onClick?.(e)\n      if (!e.defaultPrevented) setOpen(!live.current.open)\n    },\n  } as Partial<TriggerProps>)\n\n  /* motion */\n  const s: Side = pos?.side ?? (side === \"start\" ? \"left\" : side === \"end\" ? \"right\" : side)\n  const away = { top: { y: 6 }, bottom: { y: -6 }, left: { x: 6 }, right: { x: -6 } }[s]\n  const still = reduce || animation === \"none\"\n  let from: TargetAndTransition = {}\n  let enter: TargetAndTransition = {}\n  let leave: TargetAndTransition = {}\n  let move: Transition = { duration: 0 }\n  if (!still) {\n    if (animation === \"scale\") {\n      from = { scale: 0.94 }\n      enter = { scale: 1 }\n      leave = { scale: 0.96 }\n      move = { duration: 0.18, ease: easing.out }\n    } else if (animation === \"slide\") {\n      from = { ...away }\n      enter = { x: 0, y: 0 }\n      leave = { x: (away.x ?? 0) / 2, y: (away.y ?? 0) / 2 }\n      move = { duration: 0.22, ease: easing.out }\n    } else if (animation === \"spring\") {\n      from = { scale: 0.8, x: (away.x ?? 0) * 1.5, y: (away.y ?? 0) * 1.5 }\n      enter = { scale: 1, x: 0, y: 0 }\n      leave = { scale: 0.94 }\n      move = spring.ui\n    }\n  }\n  const fade: Transition = animation === \"none\" && !reduce ? { duration: 0 } : { duration: reduce ? 0.1 : 0.15 }\n  const origin = pos ? (s === \"top\" ? `${pos.arrow}px 100%` : s === \"bottom\" ? `${pos.arrow}px 0` : s === \"left\" ? `100% ${pos.arrow}px` : `0 ${pos.arrow}px`) : \"50% 50%\"\n\n  const sz = SIZES[size]\n  const hasHeader = (title !== undefined && title !== null) || (description !== undefined && description !== null)\n  const withClose = showClose ?? (title !== undefined && title !== null)\n  const content = typeof children === \"function\" ? children(api) : children\n  const foot = typeof footer === \"function\" ? footer(api) : footer\n\n  const layer = (\n    <AnimatePresence>\n      {open && mounted && (\n        <React.Fragment key=\"popover\">\n          {modal && (\n            <div\n              aria-hidden=\"true\"\n              data-slot=\"popover-overlay\"\n              className=\"fixed inset-0 z-50\"\n              onPointerDown={(e) => {\n                e.preventDefault()\n                if (closeOnOutsideClick) close(false)\n              }}\n            />\n          )}\n          <div\n            ref={floating}\n            data-slot=\"popover-positioner\"\n            dir={pos ? (pos.rtl ? \"rtl\" : \"ltr\") : undefined}\n            className={cn(\"fixed top-0 left-0 z-50\", !matchTriggerWidth && \"w-max\")}\n            style={{ transform: pos ? `translate3d(${Math.round(pos.x)}px,${Math.round(pos.y)}px,0)` : undefined, visibility: pos ? undefined : \"hidden\" }}\n            onPointerDownCapture={() => {\n              insideTree.current = true\n            }}\n          >\n            <motion.div\n              className=\"pc-popover-motion\"\n              data-variant={variant}\n              initial={from}\n              animate={enter}\n              exit={{ ...leave, transition: still ? { duration: 0 } : { duration: 0.12 } }}\n              transition={move}\n              style={{ transformOrigin: origin }}\n            >\n              <motion.div\n                {...props}\n                ref={panel}\n                id={panelId}\n                role=\"dialog\"\n                aria-modal={modal || undefined}\n                aria-labelledby={title !== undefined && title !== null ? titleId : props[\"aria-labelledby\"]}\n                aria-describedby={description !== undefined && description !== null ? descId : props[\"aria-describedby\"]}\n                tabIndex={-1}\n                data-slot=\"popover\"\n                data-variant={variant}\n                data-tone={tone}\n                data-shadow={shadow}\n                data-side={s}\n                data-modal={modal ? \"\" : undefined}\n                initial={{ opacity: 0 }}\n                animate={{ opacity: 1 }}\n                exit={{ opacity: 0, transition: animation === \"none\" && !reduce ? { duration: 0 } : { duration: 0.12 } }}\n                transition={fade}\n                onKeyDown={onPanelKey}\n                style={{ ...style, maxHeight: pos ? Math.min(pos.maxHeight, 640) : undefined }}\n                className={cn(\n                  \"pc-popover flex max-w-[calc(100vw-1rem)] flex-col text-sm\",\n                  matchTriggerWidth ? \"w-full\" : sz.w,\n                  RADIUS[radius],\n                  variant === \"neo\" && radius !== \"none\" && \"rounded-md\",\n                  className,\n                )}\n              >\n                {hasHeader && (\n                  <div data-slot=\"popover-header\" className={cn(\"flex shrink-0 items-start gap-3\", sz.px, size === \"lg\" ? \"pt-5\" : size === \"md\" ? \"pt-4\" : \"pt-3\", !content && !foot && \"pb-3\")}>\n                    <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n                      {title !== undefined && title !== null && (\n                        <h2 id={titleId} className=\"text-sm leading-tight font-semibold\">\n                          {title}\n                        </h2>\n                      )}\n                      {description !== undefined && description !== null && (\n                        <p id={descId} className=\"pc-popover-muted text-[13px] leading-snug\">\n                          {description}\n                        </p>\n                      )}\n                    </div>\n                    {withClose && (\n                      <button\n                        type=\"button\"\n                        data-close=\"\"\n                        aria-label={l.close}\n                        onClick={() => close()}\n                        className=\"pc-press pc-popover-x -me-1.5 -mt-1 grid size-7 shrink-0 cursor-pointer place-items-center rounded-md outline-none transition-colors\"\n                      >\n                        <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\" className=\"size-4\">\n                          <path d=\"M4.5 4.5 11.5 11.5M11.5 4.5 4.5 11.5\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n                        </svg>\n                      </button>\n                    )}\n                  </div>\n                )}\n                {!hasHeader && withClose && (\n                  <button\n                    type=\"button\"\n                    data-close=\"\"\n                    aria-label={l.close}\n                    onClick={() => close()}\n                    className=\"pc-press pc-popover-x absolute end-1.5 top-1.5 z-10 grid size-7 cursor-pointer place-items-center rounded-md outline-none transition-colors\"\n                  >\n                    <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\" className=\"size-4\">\n                      <path d=\"M4.5 4.5 11.5 11.5M11.5 4.5 4.5 11.5\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n                    </svg>\n                  </button>\n                )}\n                {content !== undefined && content !== null && content !== false && (\n                  <div data-slot=\"popover-body\" className={cn(\"min-h-0 flex-1 overflow-y-auto overscroll-contain\", sz.pad, hasHeader && \"pt-3\")}>\n                    {content}\n                  </div>\n                )}\n                {foot !== undefined && foot !== null && foot !== false && (\n                  <div data-slot=\"popover-footer\" className={cn(\"pc-popover-foot flex shrink-0 items-center justify-end gap-2\", sz.px, size === \"lg\" ? \"py-3.5\" : \"py-2.5\")}>\n                    {foot}\n                  </div>\n                )}\n                {arrow && pos && (\n                  <span\n                    aria-hidden=\"true\"\n                    data-slot=\"popover-arrow\"\n                    data-side={s}\n                    className=\"pc-popover-arrow\"\n                    style={\n                      s === \"top\" || s === \"bottom\"\n                        ? { left: `calc(${pos.arrow}px - var(--pc-bw) - var(--pc-as) / 2)` }\n                        : { top: `calc(${pos.arrow}px - var(--pc-bw) - var(--pc-as) / 2)` }\n                    }\n                  />\n                )}\n              </motion.div>\n            </motion.div>\n          </div>\n        </React.Fragment>\n      )}\n    </AnimatePresence>\n  )\n\n  return (\n    <>\n      <GooduiTokens />\n      <style href=\"pc-popover\" precedence=\"default\">\n        {CSS}\n      </style>\n      {triggerEl}\n      {mounted && portal ? createPortal(layer, document.body) : layer}\n    </>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/popover.tsx"
    }
  ],
  "categories": [
    "components",
    "core"
  ],
  "type": "registry:component"
}