{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"motion-reveal","type":"registry:component","title":"Reveal (Motion)","description":"Reveal with motion: its height glides open with no overshoot while what's inside rises as it fades in; closing, the content fades first and the height folds away, so no line is cut through.","dependencies":["motion"],"registryDependencies":["https://dashral.com/r/motion-reduced.json","https://dashral.com/r/motion-tokens.json","https://dashral.com/r/reveal.json"],"files":[{"path":"registry/dashral/motion/reveal.tsx","type":"registry:file","target":"components/dashral/motion/reveal.tsx","content":"\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, PresenceContext, motion, useIsPresent } from \"motion/react\"\nimport { RevealListContext, glideRevealGap, revealGap, type RevealGap, type RevealListProps, type RevealProps } from \"../reveal\"\n\nimport { useReducedMotion } from \"../lib/motion-reduced\"\nimport { duration, ease, spring } from \"../lib/motion-tokens\"\n\nexport type { RevealListProps, RevealProps } from \"../reveal\"\n\nconst bezier = (points: readonly number[]) => `cubic-bezier(${points.join(\", \")})`\n\n/**\n * The kit's Reveal with motion: the same props. Its height glides open with no overshoot while what's inside rises a\n * little as it fades in, as an Accordion section opens; in a grid or a flex column, the gap it brings glides in with\n * it. Closing, the content fades out fast, then the height folds away gathering speed, so no line is cut through.\n * With reduced motion it only fades.\n */\nexport function Reveal({ open = true, as = \"div\", children, id, className }: RevealProps) {\n  const reduced = useReducedMotion()\n  // A row of a RevealList: the list's presence brings it in and takes it away.\n  if (React.useContext(RevealListContext)) {\n    return (\n      <RevealPanel as={as} id={id} className={className} reduced={reduced} row>\n        {children}\n      </RevealPanel>\n    )\n  }\n  return (\n    <AnimatePresence initial={false}>\n      {open && (\n        <RevealPanel key=\"reveal\" as={as} id={id} className={className} reduced={reduced}>\n          {children}\n        </RevealPanel>\n      )}\n    </AnimatePresence>\n  )\n}\n\n/**\n * The kit's RevealList with motion: added rows grow in, removed ones fold away, and the others glide to their new\n * places (a row moving up as one above it leaves, or the list put in a new order).\n */\nexport function RevealList({ as: Tag = \"ul\", children, ...props }: RevealListProps) {\n  return (\n    <RevealListContext.Provider value={true}>\n      <Tag data-slot=\"reveal-list\" {...props}>\n        <AnimatePresence initial={false}>{children}</AnimatePresence>\n      </Tag>\n    </RevealListContext.Provider>\n  )\n}\n\n/** How the height folds away; the gap follows it on the same timing. */\nconst closing = { duration: duration.standard, ease: ease.exit, delay: duration.fast / 2 }\n\nconst panels = { div: motion.div, li: motion.li, span: motion.span }\n\nfunction RevealPanel({\n  as = \"div\",\n  id,\n  className,\n  reduced,\n  row = false,\n  children,\n}: Omit<RevealProps, \"open\"> & { reduced: boolean; row?: boolean }) {\n  const Panel = panels[as]\n  const Inner = as === \"span\" ? motion.span : motion.div\n  const panel = React.useRef<HTMLElement>(null)\n  const gap = React.useRef<RevealGap | null>(null)\n  const present = useIsPresent()\n  // There from the first render (open from the start, or a row already in its list): no gap to glide in.\n  const atStart = React.useRef(React.useContext(PresenceContext)?.initial === false)\n\n  // The parent's gap glides in with the height as it arrives, and out as it leaves (held until it's gone). A list's\n  // rows have none to glide: their gap comes and goes as the rows around them glide.\n  React.useLayoutEffect(() => {\n    if (!panel.current || reduced || row) return\n    if (present) gap.current = revealGap(panel.current)\n    if (present && atStart.current) return\n    const glide = glideRevealGap(\n      gap.current,\n      present,\n      present\n        ? { duration: duration.considered * 1000, easing: bezier(ease.standard) }\n        : { duration: (closing.duration + closing.delay) * 1000, easing: bezier(ease.exit) }\n    )\n    return () => glide?.cancel()\n  }, [present, reduced, row])\n\n  return (\n    <Panel\n      ref={panel as React.Ref<never>}\n      data-slot=\"reveal\"\n      id={id}\n      className=\"overflow-hidden\"\n      layout={row ? \"position\" : undefined}\n      initial={reduced ? { opacity: 0 } : { height: 0 }}\n      animate={reduced ? { opacity: 1 } : { height: \"auto\" }}\n      exit={reduced ? { opacity: 0, transition: { duration: duration.fast } } : { height: 0, transition: closing }}\n      transition={reduced ? { duration: duration.fast } : { ...spring.glide, layout: spring.glide }}\n    >\n      <Inner\n        className={className}\n        initial={reduced ? false : { opacity: 0, y: -4 }}\n        animate={{ opacity: 1, y: 0 }}\n        exit={{ opacity: 0, transition: { duration: duration.fast, ease: ease.exit } }}\n        transition={{ duration: duration.standard, ease: ease.enter }}\n      >\n        {children}\n      </Inner>\n    </Panel>\n  )\n}\n"}]}