{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "swatch",
  "title": "Swatch palette",
  "description": "Color grid with a plus to add your own.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/dgit/ui/swatch.tsx",
      "content": "import { useRef, useState, type KeyboardEvent } from \"react\";\nimport { Plus } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\n/**\n * Color picker: a 4-column grid; the chosen color gets a dark ring. Arrow keys move (one tab stop).\n * Pass `onAdd` to show a trailing \"+\": it returns the new color (a CSS color string) or nothing to cancel.\n */\nexport function SwatchPalette({ colors, onAdd, onChange }: { colors: string[]; onAdd?: () => string | undefined; onChange?: (c: string) => void }) {\n  const [list, setList] = useState(colors);\n  const [sel, setSel] = useState(colors[0]);\n  const refs = useRef<(HTMLButtonElement | null)[]>([]);\n  const pick = (c: string) => { setSel(c); onChange?.(c); };\n  const onKey = (e: KeyboardEvent) => {\n    const i = list.indexOf(sel);\n    const step = e.key === \"ArrowRight\" ? 1 : e.key === \"ArrowLeft\" ? -1 : e.key === \"ArrowDown\" ? 4 : e.key === \"ArrowUp\" ? -4 : 0;\n    const n = i + step;\n    if (step && list[n]) { e.preventDefault(); pick(list[n]); refs.current[n]?.focus(); }\n  };\n  return (\n    <div className=\"w-fit rounded-3xl bg-background-100 p-3 shadow-menu\">\n      <div role=\"radiogroup\" aria-label=\"Colors\" onKeyDown={onKey} className=\"grid grid-cols-4 gap-2.5\">\n        {list.map((c, i) => (\n          <button key={`${c}-${i}`} ref={(el) => { refs.current[i] = el; }} type=\"button\" role=\"radio\" aria-checked={sel === c} aria-label={c} tabIndex={sel === c ? 0 : -1} onClick={() => pick(c)}\n            className={cn(\"flex size-12 cursor-pointer items-center justify-center rounded-xl transition-shadow active:scale-[0.97]\", sel === c && \"ring-2 ring-foreground ring-offset-2 ring-offset-background-100\")} style={{ background: c }} />\n        ))}\n        {onAdd && (\n          <button type=\"button\" aria-label=\"Add a color\" onClick={() => { const c = onAdd(); if (c) { setList([...list, c]); pick(c); } }}\n            className=\"flex size-12 cursor-pointer items-center justify-center rounded-xl border-2 border-foreground active:scale-[0.97]\"><Plus className=\"size-5\" /></button>\n        )}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}