{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"presence","type":"registry:ui","title":"Presence","description":"Mounts and unmounts content with a real entrance and exit through one direction-aware transition, tracking opening/open/closing state, marking the panel inert while it closes, and firing lifecycle callbacks","author":"fancy-ui <https://fancy-ui.rama.app>","categories":["effects"],"registryDependencies":["https://fancy-ui.rama.app/r/internals.json","https://fancy-ui.rama.app/r/internals-dom.json","https://fancy-ui.rama.app/r/internals-motion.json","https://fancy-ui.rama.app/r/utils.json"],"files":[{"path":"react/src/components/presence/Presence.tsx","content":"\"use client\";\n\nimport { forwardRef } from \"react\";\nimport type { HTMLAttributes, ReactNode } from \"react\";\n\nimport { cn } from \"../../utils\";\nimport { useComposedRefs } from \"../../internals/dom/use-composed-refs\";\nimport { useReducedMotion } from \"../../internals/motion/media-query\";\nimport { usePresence } from \"../../internals/motion/presence\";\nimport { preset as makePreset } from \"../../internals/motion/transitions\";\nimport type { PresetName } from \"../../internals/motion/types\";\n\n/**\n * Presence — mounts and unmounts content with a real entrance and exit rather\n * than an instant swap, driving `data-state` through `opening → open →\n * closing` and firing lifecycle callbacks a caller can hook into. Shares\n * Reveal's preset vocabulary, plus `blur`/`zoom` — the one place besides\n * Reveal a preset may carry `filter`, and here it is opt-in per instance\n * rather than per child — with an asymmetric, faster-leaving exit by default.\n *\n * There is deliberately no stylesheet: the source has no `<style>` block and\n * no custom properties, because the motion is entirely JS-timed through\n * `duration`/`exitDuration`/`delay`/`distance` feeding `preset()`'s sampled\n * keyframes. There is nothing for a stylesheet to override; use the props.\n */\nexport interface PresenceProps\n\textends Omit<HTMLAttributes<HTMLDivElement>, \"className\" | \"children\"> {\n\t/** Whether the content is mounted and, once the entrance settles, visible. */\n\topen: boolean;\n\t/** Shares Reveal's preset vocabulary, plus `blur`/`zoom` — the one place besides Reveal a preset may carry `filter`, and here it's opt-in per instance, not per child. */\n\tpreset?: PresetName;\n\t/** Entrance duration in ms. */\n\tduration?: number;\n\t/** Exit duration in ms — shorter than the entrance by default; leaving reads faster than arriving. */\n\texitDuration?: number;\n\t/** Delay in ms before the entrance starts. Applied to the exit too. */\n\tdelay?: number;\n\t/** Entrance travel distance in px for the four directional presets. The exit travels half as far. */\n\tdistance?: number;\n\t/** Whether the panel is `inert` while closing. `true`, the default, reproduces the native behaviour the source framework applies to any transitioning element; `false` is an explicit opt-out, and it means the attribute is never touched at all. */\n\tinert?: boolean;\n\t/** Fires once the entrance transition settles. */\n\tonEnterEnd?: () => void;\n\t/** Fires once the exit transition settles — NOT guaranteed if the component is unmounted mid-exit. */\n\tonExitEnd?: () => void;\n\t/** Additional CSS classes, merged onto the root. */\n\tclassName?: string;\n\t/** Panel content. */\n\tchildren: ReactNode;\n}\n\nexport const Presence = forwardRef<HTMLDivElement, PresenceProps>(function Presence(\n\t{\n\t\topen,\n\t\tpreset = \"fade\",\n\t\tduration = 300, // DURATIONS.base\n\t\texitDuration = 200, // DURATIONS.exit\n\t\tdelay = 0,\n\t\tdistance = 16,\n\t\tinert = true,\n\t\tonEnterEnd,\n\t\tonExitEnd,\n\t\tclassName,\n\t\tchildren,\n\t\t...restProps\n\t},\n\tforwardedRef\n) {\n\tconst reduced = useReducedMotion();\n\n\t// `mounted` stays true for the WHOLE exit, so the subtree leaves at the\n\t// instant the exit settles rather than the instant `open` flips — the mount\n\t// clock the source's own conditional block owned, made explicit.\n\tconst presence = usePresence(open, { inert, onEnterEnd, onExitEnd });\n\n\t// C-2: composed ABOVE the early return. Building this inside the JSX below\n\t// would be a conditional hook and would throw the first time `mounted`\n\t// flips.\n\t//\n\t// ONE bidirectional leg, never a split enter/exit pair: reversal smoothing\n\t// — a rapid `open` toggle resuming from the position the close actually\n\t// reached instead of snapping back to the far end — only exists for a\n\t// unified leg. The params factory supplies the direction the leg itself\n\t// cannot know (a single two-way transition reports an ambiguous \"both\" on\n\t// both of its invocations, while `open` is the real signal), and it is\n\t// called at the instant a leg starts, so it always reads the latest\n\t// render's props and reduced-motion answer rather than the ones registered\n\t// at mount.\n\tconst rootRef = useComposedRefs(\n\t\tforwardedRef,\n\t\tpresence.register(makePreset(preset), (entering) => ({\n\t\t\tduration: reduced ? 0 : entering ? duration : exitDuration,\n\t\t\tdelay: reduced ? 0 : delay,\n\t\t\tdistance: entering ? distance : distance / 2,\n\t\t}))\n\t);\n\n\tif (!presence.mounted) return null;\n\n\treturn (\n\t\t<div\n\t\t\t{...restProps}\n\t\t\tref={rootRef}\n\t\t\tclassName={cn(\"ft-presence\", className)}\n\t\t\t// Three values, not the two an anchored surface renders (C-5): the\n\t\t\t// source renders three here.\n\t\t\tdata-state={presence.state}\n\t\t>\n\t\t\t{children}\n\t\t</div>\n\t);\n});\n","type":"registry:ui","target":"@ui/fancy/components/presence/Presence.tsx"},{"path":"react/src/components/presence/index.ts","content":"\"use client\";\n\nexport { Presence } from \"./Presence\";\nexport type { PresenceProps } from \"./Presence\";\n","type":"registry:ui","target":"@ui/fancy/components/presence/index.ts"}],"meta":{"license":"MIT","package":"fancy-ui-react","version":"0.7.0","source":"https://fancy-ui.rama.app/docs/components/presence?framework=react"}}