{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"popover","type":"registry:ui","title":"Popover","description":"A small anchored surface for contextual information.","categories":["disclosure"],"dependencies":["@radix-ui/react-popover"],"registryDependencies":[],"files":[{"path":"registry/components/popover/popover.tsx","type":"registry:component","target":"@components/silicon-ui/popover/popover.tsx","content":"\"use client\";\n\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { forwardRef } from \"react\";\nimport type { ComponentPropsWithoutRef } from \"react\";\nimport { ESCAPE_LAYER_ATTRIBUTE, layerEscape } from \"../lib/escape\";\nimport styles from \"./popover.module.css\";\n\nexport const Popover = PopoverPrimitive.Root;\nexport const PopoverClose = PopoverPrimitive.Close;\n\n/** The trigger anchors the panel, so it opts out of press-scale: a scaled rect measured on open would shift the panel as the trigger springs back. */\nexport const PopoverTrigger = forwardRef<\n  HTMLButtonElement,\n  ComponentPropsWithoutRef<typeof PopoverPrimitive.Trigger>\n>(function PopoverTrigger({ className, ...props }, ref) {\n  return <PopoverPrimitive.Trigger {...props} ref={ref} className={[styles.anchor, className].filter(Boolean).join(\" \")}/>;\n});\n\nPopoverTrigger.displayName = \"PopoverTrigger\";\n\nexport const PopoverContent = forwardRef<\n  HTMLDivElement,\n  ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>\n>(function PopoverContent({ className, align = \"start\", sideOffset = 6, collisionPadding = 10, onEscapeKeyDown, ...props }, ref) {\n  return <PopoverPrimitive.Portal>\n    <PopoverPrimitive.Content\n      {...props}\n      {...{ [ESCAPE_LAYER_ATTRIBUTE]: \"\" }}\n      // Escape inside belongs to an open list, calendar or question first (lib/escape.ts).\n      onEscapeKeyDown={layerEscape(onEscapeKeyDown)}\n      ref={ref}\n      align={align}\n      sideOffset={sideOffset}\n      collisionPadding={collisionPadding}\n      className={[styles.content, className].filter(Boolean).join(\" \")}\n    />\n  </PopoverPrimitive.Portal>;\n});\n\nPopoverContent.displayName = \"PopoverContent\";\n"},{"path":"registry/components/popover/popover.module.css","type":"registry:component","target":"@components/silicon-ui/popover/popover.module.css","content":"/* Press feedback on the anchor stays in color. Radix measures the trigger when the panel opens, so a scaled trigger would move the panel. */\n.anchor:active:not(:disabled) { transform: none; }\n.content {\n  --popover-x: 0px;\n  --popover-y: -5px;\n  z-index: var(--layer-popover);\n  min-width: 12rem;\n  max-width: min(22rem, calc(100vw - 20px));\n  padding: var(--space-inset);\n  border: 1px solid var(--border);\n  border-radius: var(--radius-container);\n  background: var(--surface-raised);\n  color: var(--foreground);\n  box-shadow: var(--shadow-floating);\n  transform-origin: var(--radix-popover-content-transform-origin);\n  transition: opacity var(--duration-fast) var(--ease-enter), transform var(--duration-spring) var(--ease-spring);\n}\n/* The panel starts a few pixels toward its trigger and settles on a spring; it leaves faster than it arrives.\n   Transitions instead of keyframes, so a close that interrupts the open, or a reopen during the close, reverses from where the panel is. */\n.content[data-side=\"top\"] { --popover-y: 5px; }\n.content[data-side=\"left\"] { --popover-x: 5px; --popover-y: 0px; }\n.content[data-side=\"right\"] { --popover-x: -5px; --popover-y: 0px; }\n@starting-style {\n  .content[data-state=\"open\"] { opacity: 0; transform: translate(var(--popover-x), var(--popover-y)) scale(.97); }\n}\n/* Radix unmounts when the exit animation ends, so a no-op keyframe times the exit while the transition does the visual work. */\n.content[data-state=\"closed\"] { opacity: 0; transform: translate(calc(var(--popover-x) * .5), calc(var(--popover-y) * .5)) scale(.98); transition: opacity var(--duration-fast) var(--ease-standard), transform var(--duration-fast) var(--ease-standard); animation: popover-exit var(--duration-fast) linear both; pointer-events: none; }\n.content:focus { outline: none; }\n@keyframes popover-exit { to { --popover-exit: 1; } }\n@media (prefers-reduced-motion: reduce) {\n  .content, .content[data-state=\"closed\"] { transform: none; transition: opacity var(--duration-instant) var(--ease-standard); }\n}\n"},{"path":"lib/escape.ts","type":"registry:lib","target":"@components/silicon-ui/lib/escape.ts","content":"/**\n * Escape inside a layer (Dialog, Drawer, BottomSheet, Popover) belongs to the control that has focus when that control\n * has something of its own to close: an open Combobox list, an open DatePicker calendar, an InlineEdit being edited, a\n * ConfirmMorph asking its question. Only the next Escape closes the layer.\n *\n * Radix closes its layers from a capture listener on the document, before the control's own key handler runs, so every\n * Silicon UI layer passes its `onEscapeKeyDown` through `layerEscape` (and marks its own panel with `data-escape-layer`, where\n * the search for an inner popup stops). Pages need nothing for this; their own `onEscapeKeyDown` still runs first and\n * can keep the layer open for reasons of its own with `event.preventDefault()`.\n */\n\n/** Marks a layer's own panel (so it is never mistaken for a popup of a control inside it). */\nexport const ESCAPE_LAYER_ATTRIBUTE = \"data-escape-layer\";\n\n/** Controls that close something of their own on Escape while focus is in them. */\nconst OWN_ESCAPE = [\n  // Combobox with its list open (focus stays in its input).\n  '[role=\"combobox\"][aria-expanded=\"true\"]',\n  // DatePicker's trigger (or any popup button) while its panel is open.\n  '[aria-haspopup=\"dialog\"][aria-expanded=\"true\"]',\n  '[aria-haspopup=\"listbox\"][aria-expanded=\"true\"]',\n  // InlineEdit while editing: Escape puts the saved text back.\n  \"[data-editing]\",\n].join(\", \");\n\n/** ConfirmMorph asking its question or showing a result (Escape returns it to rest). */\nconst MORPH_STATES = '[data-state=\"confirming\"], [data-state=\"done\"], [data-state=\"error\"]';\n\n/** True when Escape at `target` is handled by a control inside the layer, which closes its own part first. */\nexport function escapeBelongsInside(target: EventTarget | null): boolean {\n  if (!(target instanceof Element)) return false;\n  if (target.closest(OWN_ESCAPE)) return true;\n  // A ConfirmMorph's root (focused while it works or shows a result) or one of its faces. A HoldToConfirm button also\n  // says data-state=\"done\", but it has no faces and no Escape of its own.\n  const morph = target.closest(MORPH_STATES);\n  if (morph?.querySelector(\"[data-face]\")) return true;\n  // A popup of a control (DatePicker's calendar is a dialog inside the layer); the layer's own panel is not one.\n  const dialog = target.closest('[role=\"dialog\"]');\n  return !!dialog && !dialog.hasAttribute(ESCAPE_LAYER_ATTRIBUTE);\n}\n\n/**\n * The `onEscapeKeyDown` a Silicon UI layer gives Radix: the page's own handler first, then the layer stays open when the\n * Escape belongs to a control inside it.\n */\nexport function layerEscape<E extends KeyboardEvent>(own?: (event: E) => void): (event: E) => void {\n  return event => {\n    own?.(event);\n    if (!event.defaultPrevented && escapeBelongsInside(event.target)) event.preventDefault();\n  };\n}\n"}],"docs":"Docs and live preview: https://ui.teamofsilicons.com/popover","meta":{"tier":"free","kind":"component","docs":"https://ui.teamofsilicons.com/popover","markdown":"https://ui.teamofsilicons.com/popover.md","tags":["overlay","menu"],"status":"stable"}}