# Kanban board

> A pipeline you rearrange by hand: the card becomes the stage it's over while still in the air, and every column's total rolls as it passes.

Most boards drag a floating copy of the card, snap a gap open somewhere and only update the counts after you drop. Here you carry the card itself. Pick it up and it follows you exactly, tilting a little with how fast you carry it and settling upright when you stop; the column under it eases open a gap at the exact slot while the one it left closes up. While it is still in the air its status chip turns into the stage it is over: the label morphs, the colour crossfades, and a finishing column draws a check. Each column's count and total roll as the card leaves one and enters the next, so a pipeline's money moves while you hold it. A column at its limit, or with a rule the card breaks, turns amber, says why and opens no gap; let go and the card springs home. Drops land with a slight overshoot, a failed save flies the card back with a shake, "+ Add deal" grows into a card you type into, columns fold to a strip, and Space, the arrows and Space carry a card by keyboard.

## Install

```bash
npx shadcn@latest add @hairline/kanban-board
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/kanban-board
- Registry item (source): https://hairlineui.com/r/kanban-board.json

## Usage

```tsx
import { KanbanBoard } from "@/components/kanban-board";

<KanbanBoard
  columns={[{ id: "todo", title: "Todo" }, { id: "doing", title: "In progress" }, { id: "done", title: "Done", done: true }]}
  cards={issues}
  onCardsChange={setIssues}
  renderCard={(issue) => <p className="text-[13px]">{issue.title}</p>}
/>
```

## A sales pipeline that saves to your CRM

Cards are { id, column, … } in the order they stand; the board hands back the new order on every move and calls onMove to save it. value totals each column, refuse keeps a rule (here: no amount, no win), and limit caps a column.

```tsx
"use client";
import { useState } from "react";
import { KanbanBoard, type KanbanColumn } from "@/components/kanban-board";

type Deal = { id: string; column: string; company: string; amount: number | null };

const stages: KanbanColumn[] = [
  { id: "lead", title: "Lead", tone: 4 },
  { id: "qualified", title: "Qualified", tone: 1 },
  { id: "proposal", title: "Proposal", tone: 5, limit: 6 },
  { id: "won", title: "Won", tone: 3, done: true },
];

export function Pipeline({ initial }: { initial: Deal[] }) {
  const [deals, setDeals] = useState(initial);
  return (
    <KanbanBoard
      columns={stages}
      cards={deals}
      onCardsChange={setDeals}
      cardLabel={(d) => d.company}
      value={(d) => d.amount}
      valueFormat={{ style: "currency", currency: "USD", maximumFractionDigits: 0 }}
      refuse={(d, stage) => (stage.id === "won" && d.amount == null ? "Add an amount before it can be won" : null)}
      onMove={async (deal, stage, index) => {
        const res = await fetch(`/api/deals/${deal.id}`, { method: "PATCH", body: JSON.stringify({ stage: stage.id, index }) });
        if (!res.ok) throw new Error("Not saved");
      }}
      addLabel="deal"
      onAdd={async (stage, company) => {
        const res = await fetch("/api/deals", { method: "POST", body: JSON.stringify({ stage: stage.id, company }) });
        return res.json();
      }}
      renderCard={(d) => <p className="truncate text-[13.5px] font-medium">{d.company}</p>}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `columns` | `KanbanColumn[]` | – | { id, title, tone?, limit?, done? }. tone picks one of the five chart colours for its chip; limit caps it; done draws a check on its chip. |
| `cards / defaultCards` | `T extends { id, column }[]` | – | The cards, in the order they stand in their columns. |
| `onCardsChange` | `(cards: T[]) => void` | – | The new order after every move, add and failed-save revert. |
| `renderCard` | `(card, { column, lifted }) => ReactNode` | – | The card's own content. The board adds the status chip (the column it's over while carried) and the value under it. |
| `cardLabel` | `(card: T) => string` | – | How a card is named in its accessible name and announcements. |
| `refuse` | `(card, column) => string \| null` | – | A reason a column won't take a card; the column says it while the card is over it. Limits are checked for you. |
| `onMove` | `(card, to, index) => Promise<void>` | – | Saves a move (the card already has its new column). Throw to fly it back. |
| `value` | `(card: T) => number \| null` | – | An amount per card, shown on it and totalled (rolling) in each column head. |
| `valueFormat / locales` | `Intl.NumberFormatOptions / string` | – | How amounts are written, e.g. { style: "currency", currency: "USD" }. |
| `onAdd` | `(column, title) => T \| Promise<T>` | – | Shows "+ Add …" at the foot of each column; return the new card. |
| `addLabel` | `string` | `"card"` | The noun in "+ Add …" and the new card's field. |
| `label` | `string` | `"Board"` | Accessible name of the board. |

## States

- **pick up**: After 4px (or a 300ms hold on touch, with a short vibration where supported) the card lifts: 1.03 scale, a darker hairline, above everything. It follows the pointer one to one and tilts up to 5° with its sideways speed, eased by one frame loop that runs only while it's carried.
- **gaps**: The column under the card opens a gap at the slot its centre is over (240ms, transforms only) and grows by a card; the column it left closes up behind it. Same column: the cards between the old and new slot make way.
- **becomes**: Over another column the card's chip takes that column's name (TextMorph) and colour (300ms), and a done column draws a check; the column's border and ground take its tint. Counts and totals roll in both columns as if it had already moved.
- **refuse**: A column at its limit, or whose refuse() returns a reason, turns amber, gives a short shake, says why under its title and opens no gap. Let go there and the card springs home (460ms, slight overshoot); the reason stays 3.2s.
- **drop**: Everything on the board glides from where it is on screen to its new place; the carried card unwinds its tilt and lands with a slight overshoot. If onMove throws, it flies back the same way, shakes, and its column says it couldn't move.
- **add**: "+ Add deal" fades as a ring and ground grow into a card-sized field by grid rows (380ms). Enter adds what onAdd returns; Escape or an empty field folds it back.
- **collapse**: A column folds to a 48px strip with its count and a vertical title (width 420ms). It still takes a carried card, at its end.

## What it handles

Most boards drag a floating copy of the card and only update the counts after you drop. Here you carry the card itself, and the columns react while it is still in the air.

- **Carry the real card**: It follows you exactly and tilts a little with how fast you move it, then settles upright.
- **Columns make room**: The column under the card opens a gap at the exact slot, and the counts and totals roll as the card passes.
- **The card shows its next stage**: While still in the air, the card’s status chip turns into the stage it is over. A finishing column draws a check.
- **Rules and limits**: A column at its limit, or one whose rule the card breaks, turns amber and says why. Let go and the card springs home.
- **It saves, or flies back**: onMove saves each drop. If it fails, the card flies back with a shake and its column says it couldn’t move.
- **Add cards, move by keyboard**: “+ Add deal” grows into a field. Space and the arrow keys carry a card, announced step by step, and touch uses a short hold.

## Replaces

a drag and drop library, column totals, column limits and rules, optimistic updates with rollback, keyboard dragging, an add-card form

## Where it fits

- **Sales pipelines**: Deals moving through stages, with the value of each column totalled.
- **Issue and task boards**: Move work between To do, In progress and Done.
- **Hiring pipelines**: Candidates moving from applied to offer.
- **Content and support queues**: Drafts, requests or tickets that pass through stages.

## Notes

- Each column is a labelled section with an ordered list; each card says its name, column, place and amount. Space or Enter picks a card up, arrows carry it (up and down in its column, left and right across columns, skipping none: a column that refuses says why), Space drops it and Escape puts it back. Every step is announced, and onMove runs once, on the drop.
- While a card is carried the board writes transforms only: the card's own (with its tilt) and the shift of the cards making way. React re-renders only when the column or slot under it changes, for the chip and the totals. On the drop every card is snapshotted where it is on screen, the new order is laid out, and each glides from its snapshot.
- On touch, the board scrolls as usual; a 300ms hold picks a card up and only then does the page stop scrolling under the finger. Near the board's sides it scrolls sideways, near the window's edges the page scrolls. Narrow, columns snap one at a time.
- Reduced motion moves cards in place, without tilt, glides or shakes; chips, totals, amber refusals and the announcements still say what happened.

License: MIT (https://hairlineui.com/license#components)
