{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"motion-swap","type":"registry:component","title":"Swap (Motion)","description":"Swap with motion: the old content is lifted out and fades fast while the new one rises or pops in on a spring, and whatever is around glides to the new size.","dependencies":["motion"],"registryDependencies":["https://dashral.com/r/motion-reduced.json","https://dashral.com/r/motion-tokens.json","https://dashral.com/r/swap.json"],"files":[{"path":"registry/dashral/motion/swap.tsx","type":"registry:file","target":"components/dashral/motion/swap.tsx","content":"\"use client\"\n\nimport { AnimatePresence, motion } from \"motion/react\"\nimport type { SwapEffect, SwapProps } from \"../swap\"\n\nimport { useReducedMotion } from \"../lib/motion-reduced\"\nimport { duration, ease, spring } from \"../lib/motion-tokens\"\n\nexport type { SwapEffect, SwapProps } from \"../swap\"\n\nconst from: Record<SwapEffect, { opacity: number; y?: number; scale?: number }> = {\n  fade: { opacity: 0 },\n  rise: { opacity: 0, y: 6 },\n  pop: { opacity: 0, scale: 0.3 },\n}\n\n/**\n * The kit's Swap with motion: the same props. The old content is lifted out of the layout and fades fast while the new\n * one arrives in its place (rising, or popping in on a spring), so whatever is around glides to the new size rather\n * than waiting. With reduced motion they only cross-fade.\n */\nexport function Swap({ value, children, effect = \"fade\", wait = false, appear = false, as = \"span\", className }: SwapProps) {\n  const reduced = useReducedMotion()\n  const Item = as === \"span\" ? motion.span : motion.div\n  const start = reduced ? { opacity: 0 } : from[effect]\n\n  return (\n    <AnimatePresence mode={wait ? \"wait\" : \"popLayout\"} initial={appear}>\n      <Item\n        key={String(value)}\n        data-slot=\"swap\"\n        className={className ?? (as === \"span\" ? \"inline-flex\" : undefined)}\n        initial={start}\n        animate={{ opacity: 1, y: 0, scale: 1 }}\n        exit={{ opacity: 0, transition: { duration: duration.fast, ease: ease.exit } }}\n        transition={\n          reduced\n            ? { duration: duration.fast }\n            : effect === \"pop\"\n              ? { ...spring.pop, opacity: { duration: duration.fast, ease: ease.enter } }\n              : { duration: duration.standard, ease: ease.enter }\n        }\n      >\n        {children}\n      </Item>\n    </AnimatePresence>\n  )\n}\n"}]}