{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "kanban-board",
  "type": "registry:component",
  "title": "Kanban Board",
  "description": "Columns of cards you can drag between lists and reorder, with a placeholder slot and add buttons.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "app-ui",
    "kanban",
    "drag and drop",
    "board",
    "pointer events"
  ],
  "docs": "https://hyperblur.dev/effects/kanban-board",
  "files": [
    {
      "path": "registry/hyperblur/kanban-board.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/kanban-board.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface KanbanCard {\n  id: string;\n  title: string;\n  tag?: string;\n  tone?: string;\n}\n\nexport interface KanbanColumn {\n  id: string;\n  title: string;\n  cards: KanbanCard[];\n}\n\nexport interface KanbanBoardProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"children\"> {\n  columns: KanbanColumn[];\n  onChange?: (columns: KanbanColumn[]) => void;\n  newCardLabel?: string;\n  color?: string;\n}\n\nconst css = `\n.hb-kb {\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  padding: 2px;\n  overflow-x: auto;\n  color: #ededed;\n  font-family: var(--font-sans, ui-sans-serif, system-ui, sans-serif);\n  font-size: 12px;\n  line-height: 16px;\n  scrollbar-width: thin;\n  scrollbar-color: #2a2a2a transparent;\n  --hb-kb-accent: #2f7bff;\n}\n.hb-kb[data-dragging=\"true\"], .hb-kb[data-dragging=\"true\"] * { cursor: grabbing !important; }\n.hb-kb-cols { display: flex; align-items: flex-start; gap: 12px; }\n.hb-kb-col {\n  display: flex;\n  flex: 1 1 0;\n  flex-direction: column;\n  gap: 6px;\n  box-sizing: border-box;\n  min-width: var(--hb-kb-minw, 140px);\n  padding: 6px;\n  border: 1px solid #262626;\n  border-radius: 12px;\n  background: #111111;\n}\n.hb-kb-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 2px; }\n.hb-kb-title { overflow: hidden; font-size: 12px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }\n.hb-kb-count {\n  flex: none;\n  min-width: 18px;\n  padding: 0 6px;\n  border-radius: 999px;\n  background: #1f1f1f;\n  color: #8f8f8f;\n  font-size: 11px;\n  line-height: 18px;\n  text-align: center;\n}\n.hb-kb-cards { display: flex; flex-direction: column; gap: 6px; min-height: 8px; margin: 0; padding: 0; list-style: none; }\n.hb-kb-card {\n  position: relative;\n  box-sizing: border-box;\n  padding: 5px 8px;\n  border: 1px solid #262626;\n  border-radius: 8px;\n  background: #171717;\n  cursor: grab;\n  touch-action: none;\n  user-select: none;\n  -webkit-user-select: none;\n  transition: border-color .15s ease, background-color .15s ease;\n}\n.hb-kb-card:hover { border-color: #333333; background: #1a1a1a; }\n.hb-kb-card:focus-visible { outline: 2px solid var(--hb-kb-accent); outline-offset: 1px; }\n.hb-kb-card[data-fresh=\"true\"] { animation: hb-kb-in .35s cubic-bezier(.2, .9, .2, 1) both; }\n.hb-kb-text {\n  display: -webkit-box;\n  overflow: hidden;\n  overflow-wrap: anywhere;\n  -webkit-box-orient: vertical;\n  -webkit-line-clamp: 2;\n}\n.hb-kb-tag {\n  display: inline-flex;\n  align-items: center;\n  gap: 5px;\n  margin-top: 6px;\n  color: #8f8f8f;\n  font-size: 11px;\n  line-height: 14px;\n}\n.hb-kb-tag::before {\n  content: \"\";\n  width: 6px;\n  height: 6px;\n  border-radius: 999px;\n  background: var(--hb-kb-tone, #8f8f8f);\n}\n.hb-kb-ph {\n  box-sizing: border-box;\n  border: 1px dashed var(--hb-kb-accent);\n  border-radius: 8px;\n  background: rgba(47, 123, 255, .08);\n  background: color-mix(in srgb, var(--hb-kb-accent) 10%, transparent);\n}\n.hb-kb-add {\n  display: flex;\n  align-items: center;\n  gap: 6px;\n  box-sizing: border-box;\n  width: 100%;\n  height: 24px;\n  margin: 0;\n  padding: 0 6px;\n  border: 0;\n  border-radius: 6px;\n  background: transparent;\n  color: #8f8f8f;\n  font: inherit;\n  font-size: 12px;\n  cursor: pointer;\n  transition: background-color .15s ease, color .15s ease;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-kb-add:hover { background: #1f1f1f; color: #ededed; }\n.hb-kb-add:focus-visible { outline: 2px solid var(--hb-kb-accent); outline-offset: 1px; }\n.hb-kb-add svg { flex: none; width: 12px; height: 12px; }\n.hb-kb-ghost { position: fixed; top: 0; left: 0; z-index: 1000; pointer-events: none; will-change: transform; }\n.hb-kb-ghost-in {\n  box-sizing: border-box;\n  width: 100%;\n  height: 100%;\n  border-color: var(--hb-kb-accent);\n  background: #1f1f1f;\n  box-shadow: 0 14px 36px rgba(0, 0, 0, .55);\n  transform: rotate(2.5deg) scale(1.03);\n  transition: transform .18s cubic-bezier(.2, .9, .2, 1), box-shadow .18s ease;\n  animation: hb-kb-lift .18s cubic-bezier(.2, .9, .2, 1) both;\n}\n.hb-kb-ghost[data-drop=\"true\"] .hb-kb-ghost-in { transform: none; box-shadow: 0 2px 8px rgba(0, 0, 0, .3); animation: none; }\n.hb-kb-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n}\n@keyframes hb-kb-in {\n  from { opacity: 0; transform: translate3d(0, 6px, 0) scale(.96); }\n  to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }\n}\n@keyframes hb-kb-lift {\n  from { transform: rotate(0) scale(1); box-shadow: 0 2px 8px rgba(0, 0, 0, .3); }\n  to { transform: rotate(2.5deg) scale(1.03); box-shadow: 0 14px 36px rgba(0, 0, 0, .55); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-kb-card, .hb-kb-add, .hb-kb-ghost-in { transition: none; }\n  .hb-kb-card[data-fresh=\"true\"], .hb-kb-ghost-in { animation: none; }\n  .hb-kb-ghost-in { transform: none; }\n}\n`;\n\ninterface DragState {\n  id: string;\n  card: KanbanCard;\n  w: number;\n  h: number;\n  col: string;\n  index: number;\n}\n\ninterface DragRef {\n  id: string;\n  pointerId: number;\n  sx: number;\n  sy: number;\n  ox: number;\n  oy: number;\n  w: number;\n  h: number;\n  x: number;\n  y: number;\n  active: boolean;\n  col: string;\n  index: number;\n}\n\ntype Entry = { kind: \"card\"; card: KanbanCard } | { kind: \"ph\" };\n\nfunction relocate(cols: KanbanColumn[], id: string, toCol: string, toIndex: number): KanbanColumn[] {\n  const source = cols.find((c) => c.cards.some((x) => x.id === id));\n  const card = source?.cards.find((x) => x.id === id);\n  if (!card) return cols;\n  return cols.map((c) => {\n    const list = c.cards.filter((x) => x.id !== id);\n    if (c.id !== toCol) return list.length === c.cards.length ? c : { ...c, cards: list };\n    list.splice(Math.max(0, Math.min(toIndex, list.length)), 0, card);\n    return { ...c, cards: list };\n  });\n}\n\nfunction signature(cols: KanbanColumn[]) {\n  return JSON.stringify(cols);\n}\n\nfunction CardBody({ card }: { card: KanbanCard }) {\n  return (\n    <>\n      <span className=\"hb-kb-text\">{card.title}</span>\n      {card.tag ? (\n        <span className=\"hb-kb-tag\" style={card.tone ? ({ \"--hb-kb-tone\": card.tone } as React.CSSProperties) : undefined}>\n          {card.tag}\n        </span>\n      ) : null}\n    </>\n  );\n}\n\nexport function KanbanBoard({\n  columns,\n  onChange,\n  newCardLabel = \"New card\",\n  color = \"#2f7bff\",\n  className = \"\",\n  style,\n  onKeyDown,\n  ...rest\n}: KanbanBoardProps) {\n  const uid = React.useId();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const ghostRef = React.useRef<HTMLDivElement>(null);\n  const dragRef = React.useRef<DragRef | null>(null);\n  const colsRef = React.useRef(columns);\n  const positions = React.useRef<Map<string, { x: number; y: number }>>(new Map());\n  const timer = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n  const dropping = React.useRef(false);\n  const counter = React.useRef(0);\n  const focusId = React.useRef<string | null>(null);\n  const [cols, setCols] = React.useState(columns);\n  const [prevProp, setPrevProp] = React.useState(columns);\n  const [drag, setDrag] = React.useState<DragState | null>(null);\n  const [fresh, setFresh] = React.useState(\"\");\n  const [announce, setAnnounce] = React.useState(\"\");\n\n  if (prevProp !== columns) {\n    setPrevProp(columns);\n    if (signature(columns) !== signature(cols)) setCols(columns);\n  }\n\n  const dragId = drag ? drag.id : null;\n\n  const commit = React.useCallback(\n    (next: KanbanColumn[]) => {\n      colsRef.current = next;\n      setCols(next);\n      onChange?.(next);\n    },\n    [onChange],\n  );\n\n  React.useLayoutEffect(() => {\n    colsRef.current = cols;\n  }, [cols]);\n\n  React.useLayoutEffect(() => {\n    const root = rootRef.current;\n    if (!root) return;\n    const reduce = typeof window.matchMedia === \"function\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const base = root.getBoundingClientRect();\n    const next = new Map<string, { x: number; y: number }>();\n    root.querySelectorAll<HTMLElement>(\"[data-flip]\").forEach((el) => {\n      const id = el.dataset.flip as string;\n      const r = el.getBoundingClientRect();\n      const x = r.left - base.left + root.scrollLeft;\n      const y = r.top - base.top + root.scrollTop;\n      next.set(id, { x, y });\n      const prev = positions.current.get(id);\n      if (!prev || reduce) return;\n      const dx = prev.x - x;\n      const dy = prev.y - y;\n      if (Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5) return;\n      el.style.transition = \"none\";\n      el.style.transform = `translate3d(${dx}px, ${dy}px, 0)`;\n      void el.offsetWidth;\n      el.style.transition = \"transform .24s cubic-bezier(.2, .9, .2, 1), border-color .15s ease, background-color .15s ease\";\n      el.style.transform = \"\";\n    });\n    positions.current = next;\n  });\n\n  React.useLayoutEffect(() => {\n    const id = focusId.current;\n    if (!id) return;\n    focusId.current = null;\n    const el = Array.from(rootRef.current?.querySelectorAll<HTMLElement>(\"[data-card]\") ?? []).find((n) => n.dataset.card === id);\n    el?.focus();\n  }, [cols]);\n\n  const moveGhost = React.useCallback(() => {\n    const d = dragRef.current;\n    const g = ghostRef.current;\n    if (!d || !g || dropping.current) return;\n    g.style.transform = `translate3d(${d.x - d.ox}px, ${d.y - d.oy}px, 0)`;\n  }, []);\n\n  React.useLayoutEffect(() => {\n    if (dragId) moveGhost();\n  }, [dragId, moveGhost]);\n\n  const cancel = React.useCallback(() => {\n    if (timer.current) clearTimeout(timer.current);\n    timer.current = null;\n    dropping.current = false;\n    dragRef.current = null;\n    setDrag(null);\n  }, []);\n\n  React.useEffect(() => {\n    return () => {\n      if (timer.current) clearTimeout(timer.current);\n    };\n  }, []);\n\n  React.useEffect(() => {\n    if (!dragId) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") cancel();\n    };\n    window.addEventListener(\"keydown\", onKey);\n    return () => window.removeEventListener(\"keydown\", onKey);\n  }, [dragId, cancel]);\n\n  function retarget(x: number, y: number) {\n    const root = rootRef.current;\n    const d = dragRef.current;\n    if (!root || !d) return;\n    let best: HTMLElement | null = null;\n    let bestDist = Infinity;\n    root.querySelectorAll<HTMLElement>(\"[data-col]\").forEach((c) => {\n      const r = c.getBoundingClientRect();\n      const dx = x < r.left ? r.left - x : x > r.right ? x - r.right : 0;\n      if (dx < bestDist) {\n        bestDist = dx;\n        best = c;\n      }\n    });\n    const target = best as HTMLElement | null;\n    if (!target) return;\n    const colId = target.dataset.col as string;\n    let index = 0;\n    target.querySelectorAll<HTMLElement>(\"[data-card]\").forEach((c) => {\n      const r = c.getBoundingClientRect();\n      if (y > r.top + r.height / 2) index += 1;\n    });\n    if (d.col === colId && d.index === index) return;\n    d.col = colId;\n    d.index = index;\n    setDrag((prev) => (prev ? { ...prev, col: colId, index } : prev));\n  }\n\n  function handlePointerDown(e: React.PointerEvent<HTMLDivElement>) {\n    if (dropping.current || dragRef.current) return;\n    if (e.pointerType === \"mouse\" && e.button !== 0) return;\n    const el = (e.target as HTMLElement).closest<HTMLElement>(\"[data-card]\");\n    if (!el || !rootRef.current?.contains(el)) return;\n    const id = el.dataset.card as string;\n    const colEl = el.closest<HTMLElement>(\"[data-col]\");\n    const colId = colEl?.dataset.col ?? \"\";\n    const col = colsRef.current.find((c) => c.id === colId);\n    if (!col) return;\n    const rect = el.getBoundingClientRect();\n    dragRef.current = {\n      id,\n      pointerId: e.pointerId,\n      sx: e.clientX,\n      sy: e.clientY,\n      ox: e.clientX - rect.left,\n      oy: e.clientY - rect.top,\n      w: rect.width,\n      h: rect.height,\n      x: e.clientX,\n      y: e.clientY,\n      active: false,\n      col: colId,\n      index: col.cards.findIndex((c) => c.id === id),\n    };\n  }\n\n  function handlePointerMove(e: React.PointerEvent<HTMLDivElement>) {\n    const d = dragRef.current;\n    if (!d || e.pointerId !== d.pointerId || dropping.current) return;\n    d.x = e.clientX;\n    d.y = e.clientY;\n    if (!d.active) {\n      if (Math.hypot(e.clientX - d.sx, e.clientY - d.sy) < 4) return;\n      const card = colsRef.current.flatMap((c) => c.cards).find((c) => c.id === d.id);\n      if (!card) {\n        dragRef.current = null;\n        return;\n      }\n      d.active = true;\n      rootRef.current?.setPointerCapture(e.pointerId);\n      setDrag({ id: d.id, card, w: d.w, h: d.h, col: d.col, index: d.index });\n      return;\n    }\n    moveGhost();\n    retarget(e.clientX, e.clientY);\n  }\n\n  function handlePointerUp(e: React.PointerEvent<HTMLDivElement>) {\n    const d = dragRef.current;\n    if (!d || e.pointerId !== d.pointerId || dropping.current) return;\n    if (!d.active) {\n      dragRef.current = null;\n      return;\n    }\n    const { id, col, index } = d;\n    const finalize = () => {\n      timer.current = null;\n      dropping.current = false;\n      dragRef.current = null;\n      commit(relocate(colsRef.current, id, col, index));\n      setDrag(null);\n    };\n    const reduce = typeof window.matchMedia === \"function\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const ph = rootRef.current?.querySelector<HTMLElement>(\"[data-ph]\");\n    const ghost = ghostRef.current;\n    if (ph && ghost && !reduce) {\n      const r = ph.getBoundingClientRect();\n      dropping.current = true;\n      ghost.dataset.drop = \"true\";\n      ghost.style.transition = \"transform .18s cubic-bezier(.2, .9, .2, 1)\";\n      ghost.style.transform = `translate3d(${r.left}px, ${r.top}px, 0)`;\n      timer.current = setTimeout(finalize, 190);\n    } else {\n      finalize();\n    }\n  }\n\n  function addCard(colId: string) {\n    if (dragRef.current) return;\n    let id = \"\";\n    do {\n      counter.current += 1;\n      id = `${uid}-new-${counter.current}`;\n    } while (colsRef.current.some((c) => c.cards.some((x) => x.id === id)));\n    const card: KanbanCard = { id, title: newCardLabel };\n    setFresh(id);\n    commit(colsRef.current.map((c) => (c.id === colId ? { ...c, cards: [...c.cards, card] } : c)));\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {\n    onKeyDown?.(e);\n    if (e.defaultPrevented || !e.altKey) return;\n    const el = e.target as HTMLElement;\n    if (!el.dataset || !el.dataset.card) return;\n    const dc = e.key === \"ArrowRight\" ? 1 : e.key === \"ArrowLeft\" ? -1 : 0;\n    const di = e.key === \"ArrowDown\" ? 1 : e.key === \"ArrowUp\" ? -1 : 0;\n    if (!dc && !di) return;\n    e.preventDefault();\n    const id = el.dataset.card;\n    const all = colsRef.current;\n    const ci = all.findIndex((c) => c.cards.some((x) => x.id === id));\n    if (ci < 0) return;\n    const ii = all[ci].cards.findIndex((x) => x.id === id);\n    const nci = Math.max(0, Math.min(all.length - 1, ci + dc));\n    const len = all[nci].cards.length - (nci === ci ? 1 : 0);\n    const nii = Math.max(0, Math.min(len, nci === ci ? ii + di : ii));\n    if (nci === ci && nii === ii) return;\n    focusId.current = id;\n    commit(relocate(all, id, all[nci].id, nii));\n    setAnnounce(`${all[ci].cards[ii].title} moved to ${all[nci].title}, position ${nii + 1}`);\n  }\n\n  const view = cols.map((col) => {\n    const list: Entry[] = col.cards\n      .filter((c) => !drag || c.id !== drag.id)\n      .map((card): Entry => ({ kind: \"card\", card }));\n    if (drag && drag.col === col.id) list.splice(Math.min(drag.index, list.length), 0, { kind: \"ph\" });\n    return { col, list };\n  });\n\n  const vars = { \"--hb-kb-accent\": color, ...style } as React.CSSProperties;\n  const hintId = `${uid}-hint`;\n\n  return (\n    <div\n      ref={rootRef}\n      className={`hb-kb ${className}`}\n      data-dragging={drag !== null}\n      style={vars}\n      onPointerDown={handlePointerDown}\n      onPointerMove={handlePointerMove}\n      onPointerUp={handlePointerUp}\n      onPointerCancel={cancel}\n      onKeyDown={handleKeyDown}\n      {...rest}\n    >\n      <style href=\"hb-kanban-board\" precedence=\"default\">{css}</style>\n      <span id={hintId} className=\"hb-kb-sr\">\n        Drag with the pointer, or hold Alt and press the arrow keys to move this card.\n      </span>\n      <div className=\"hb-kb-sr\" role=\"status\" aria-live=\"polite\">\n        {announce}\n      </div>\n      <div className=\"hb-kb-cols\">\n        {view.map(({ col, list }) => (\n          <section key={col.id} className=\"hb-kb-col\" role=\"group\" aria-label={col.title} data-col={col.id}>\n            <div className=\"hb-kb-head\">\n              <span className=\"hb-kb-title\">{col.title}</span>\n              <span className=\"hb-kb-count\" aria-label={`${list.length} cards`}>\n                {list.length}\n              </span>\n            </div>\n            <ul className=\"hb-kb-cards\">\n              {list.map((entry) =>\n                entry.kind === \"ph\" ? (\n                  <li key=\"hb-ph\" className=\"hb-kb-ph\" data-ph=\"true\" style={{ height: drag?.h }} aria-hidden=\"true\" />\n                ) : (\n                  <li\n                    key={entry.card.id}\n                    className=\"hb-kb-card\"\n                    data-card={entry.card.id}\n                    data-flip={entry.card.id}\n                    data-fresh={fresh === entry.card.id}\n                    tabIndex={0}\n                    aria-describedby={hintId}\n                    onAnimationEnd={() => {\n                      if (fresh === entry.card.id) setFresh(\"\");\n                    }}\n                  >\n                    <CardBody card={entry.card} />\n                  </li>\n                ),\n              )}\n            </ul>\n            <button type=\"button\" className=\"hb-kb-add\" onClick={() => addCard(col.id)}>\n              <svg viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                <path d=\"M6 2v8M2 6h8\" />\n              </svg>\n              Add card\n            </button>\n          </section>\n        ))}\n      </div>\n      {drag ? (\n        <div ref={ghostRef} className=\"hb-kb-ghost\" style={{ width: drag.w, height: drag.h }} aria-hidden=\"true\">\n          <div className=\"hb-kb-card hb-kb-ghost-in\">\n            <CardBody card={drag.card} />\n          </div>\n        </div>\n      ) : null}\n    </div>\n  );\n}\n"
    }
  ]
}