{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ripple-heatmap",
  "title": "Ripple Heatmap",
  "description": "A weekday by hour grid. Press a cell and the grid ripples out from it.",
  "dependencies": [
    "animejs"
  ],
  "registryDependencies": [
    "https://spotcheckui.com/r/spotcheck-base.json",
    "https://spotcheckui.com/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/spotcheck/components/spotcheck/ripple-heatmap.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { animate, stagger } from \"animejs\"\n\nimport { cn } from \"@/lib/utils\"\nimport { useReducedMotion } from \"@/registry/spotcheck/hooks/use-reduced-motion\"\n\nconst STAGGER_MS = 26\nconst SHRINK_MS = 180\nconst RETURN_MS = 700\nconst SHRUNK_SCALE = 0.25\n\n/** The next cell for an arrow key, Home or End, staying inside the grid. */\nexport function moveCell(index: number, key: string, cols: number, rows: number) {\n  const column = index % cols\n  const row = Math.floor(index / cols)\n  const moves: Record<string, number> = {\n    ArrowLeft: row * cols + Math.max(0, column - 1),\n    ArrowRight: row * cols + Math.min(cols - 1, column + 1),\n    ArrowUp: Math.max(0, row - 1) * cols + column,\n    ArrowDown: Math.min(rows - 1, row + 1) * cols + column,\n    Home: row * cols,\n    End: row * cols + cols - 1,\n  }\n  return moves[key]\n}\n\nexport type HeatCell = { index: number; column: number; row: number; value: number }\n\ntype RippleHeatmapProps = {\n  /** One value from 0 to 1 per cell, row by row. */\n  values: number[]\n  /** Describes the grid for screen readers. */\n  label: string\n  cols?: number\n  /** One label per row, printed at the left. */\n  rowLabels: string[]\n  /** Names a cell for screen readers. */\n  cellLabel?: (cell: HeatCell) => string\n  /** Runs when a cell is pressed. */\n  onPick?: (cell: HeatCell) => void\n  className?: string\n}\n\nexport function RippleHeatmap({\n  values,\n  label,\n  cols = 24,\n  rowLabels,\n  cellLabel,\n  onPick,\n  className,\n}: RippleHeatmapProps) {\n  const reduced = useReducedMotion()\n  const grid = React.useRef<HTMLDivElement>(null)\n  const [focusIndex, setFocusIndex] = React.useState(0)\n  const [picked, setPicked] = React.useState<number | null>(null)\n  const rows = rowLabels.length\n\n  const cellAt = (index: number): HeatCell => ({\n    index,\n    column: index % cols,\n    row: Math.floor(index / cols),\n    value: values[index] ?? 0,\n  })\n\n  const pick = (index: number) => {\n    setPicked(index)\n    setFocusIndex(index)\n    onPick?.(cellAt(index))\n    const cells = grid.current?.querySelectorAll(\"[data-cell]\")\n    if (!cells || reduced) return\n    animate(cells, {\n      scale: [\n        { to: SHRUNK_SCALE, duration: SHRINK_MS, ease: \"outSine\" },\n        { to: 1, duration: RETURN_MS, ease: \"outElastic(1, .55)\" },\n      ],\n      delay: stagger(STAGGER_MS, { grid: [cols, rows], from: index }),\n    })\n  }\n\n  const onKeyDown = (event: React.KeyboardEvent) => {\n    const next = moveCell(focusIndex, event.key, cols, rows)\n    if (next === undefined) return\n    event.preventDefault()\n    setFocusIndex(next)\n    grid.current?.querySelector<HTMLElement>(`[data-cell=\"${next}\"]`)?.focus()\n  }\n\n  return (\n    <div\n      ref={grid}\n      role=\"grid\"\n      aria-label={label}\n      onKeyDown={onKeyDown}\n      className={cn(\"grid items-center gap-[3px] overflow-x-auto font-(family-name:--f-body)\", className)}\n      style={{ gridTemplateColumns: `auto repeat(${cols}, minmax(12px, 1fr))` }}\n    >\n      {rowLabels.map((rowLabel, row) => (\n        <div key={rowLabel} role=\"row\" className=\"contents\">\n          <span role=\"rowheader\" className=\"spotcheck-label pr-1.5 text-[10px]\">\n            {rowLabel}\n          </span>\n          {Array.from({ length: cols }, (_, column) => {\n            const index = row * cols + column\n            const cell = cellAt(index)\n            return (\n              <button\n                key={index}\n                type=\"button\"\n                role=\"gridcell\"\n                data-cell={index}\n                aria-label={cellLabel?.(cell) ?? `${rowLabel}, column ${column + 1}`}\n                aria-selected={picked === index}\n                tabIndex={focusIndex === index ? 0 : -1}\n                onClick={() => pick(index)}\n                className={cn(\n                  \"spotcheck-focus aspect-square min-w-3 cursor-pointer\",\n                  picked === index && \"outline-ink outline-2 outline-offset-1\",\n                )}\n                style={{ background: `color-mix(in srgb, var(--accent-ink) ${Math.round(cell.value * 100)}%, var(--wash))` }}\n              />\n            )\n          })}\n        </div>\n      ))}\n    </div>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "timelines"
  ],
  "type": "registry:component"
}