{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"motion-table","type":"registry:component","title":"Table (Motion)","description":"Table with motion: when its rows change, they move instead of jumping. A sort glides each row to its new place, a row that goes fades out while the rest close up, and a new one fades in, tinted for a moment.","dependencies":["motion"],"registryDependencies":["https://dashral.com/r/utils.json","https://dashral.com/r/motion-reduced.json","https://dashral.com/r/table.json"],"files":[{"path":"registry/dashral/motion/table.tsx","type":"registry:file","target":"components/dashral/motion/table.tsx","content":"\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, type HTMLMotionProps } from \"motion/react\"\nimport { TableBody as KitTableBody } from \"../table\"\nimport { cn } from \"../lib/utils\"\n\nimport { useReducedMotion } from \"../lib/motion-reduced\"\n\n// The parts that don't move are the kit's, re-exported, so a table imports every part from here.\nexport { Table, TableCaption, TableCell, TableFooter, TableHead, TableHeader } from \"../table\"\n\n/** The smooth curve every move uses: no spring, no overshoot. */\nconst smooth = [0.4, 0, 0.2, 1] as const\n\ntype BodyContextValue = {\n  /** Rows move (they're in a TableBody of this edition). */\n  animated: boolean\n  /** Tint rows that arrive after the body first drew. */\n  highlight: boolean\n  /** Whether the body has drawn once: rows there from the start never animate in. */\n  ready: React.RefObject<boolean>\n}\n\nconst BodyContext = React.createContext<BodyContextValue | null>(null)\n\ntype TableBodyProps = React.ComponentProps<typeof KitTableBody> & {\n  /** Rows that arrive after the table first drew are tinted in the primary color for a moment, so the eye finds them. On by default. */\n  highlightNew?: boolean\n}\n\n/**\n * The body whose rows move: give each TableRow a stable key (the record's id) and rows that change place glide to it,\n * rows that go fade out while the rest close up, and new ones fade in, tinted for a moment. The first draw stays still.\n */\nfunction TableBody({ highlightNew = true, children, ...props }: TableBodyProps) {\n  const ready = React.useRef(false)\n  React.useEffect(() => {\n    ready.current = true\n  }, [])\n  const value = React.useMemo(() => ({ animated: true, highlight: highlightNew, ready }), [highlightNew])\n  return (\n    <KitTableBody {...props}>\n      <BodyContext value={value}>\n        <AnimatePresence initial={false}>{children}</AnimatePresence>\n      </BodyContext>\n    </KitTableBody>\n  )\n}\n\ntype TableRowProps = Omit<HTMLMotionProps<\"tr\">, \"ref\"> & { ref?: React.Ref<HTMLTableRowElement> }\n\nconst rowClass = \"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted\"\n\n// The tint of a row that just arrived: a layer of the primary color over the row's own background (hover and\n// selected still show under it), fading from 12% to nothing.\nconst tint = \"color-mix(in oklab, var(--color-primary) var(--row-tint), transparent)\"\n\n/**\n * A row. In this edition's TableBody it moves: to a new place on a smooth glide (a sort), out with a quick fade (the\n * rest close up after it), in from a few pixels above. In a header or footer it's the kit's still row.\n */\nfunction TableRow({ className, style, ...props }: TableRowProps) {\n  const body = React.useContext(BodyContext)\n  const reduced = useReducedMotion()\n  // Decided once, as the row first draws: was the body already there (so this row is new)?\n  const [fresh] = React.useState(() => Boolean(body?.ready.current))\n  if (!body?.animated) return <motion.tr data-slot=\"table-row\" className={cn(rowClass, className)} style={style} {...props} />\n\n  const tinted = fresh && body.highlight && !reduced\n  return (\n    <motion.tr\n      data-slot=\"table-row\"\n      layout={reduced ? false : \"position\"}\n      initial={reduced ? { opacity: 0 } : { opacity: 0, y: -6, ...(tinted && { \"--row-tint\": \"12%\" }) }}\n      animate={{ opacity: 1, y: 0, ...(tinted && { \"--row-tint\": \"0%\" }) }}\n      exit={{ opacity: 0, transition: { duration: 0.18, ease: smooth } }}\n      transition={{\n        layout: { duration: 0.35, ease: smooth },\n        opacity: { duration: 0.28, ease: smooth },\n        y: { duration: 0.32, ease: smooth },\n        \"--row-tint\": { duration: 1.4, ease: smooth, delay: 0.25 },\n      }}\n      style={tinted ? { backgroundImage: `linear-gradient(${tint}, ${tint})`, ...style } : style}\n      className={cn(rowClass, className)}\n      {...props}\n    />\n  )\n}\n\nexport { TableBody, TableRow, type TableBodyProps, type TableRowProps }\n"}]}