Board
A Kanban board. Columns go across. Lanes go down. Each card sits in the cell where its column and lane meet. Drag cards to any cell, drag columns by their grip, and click a card to open it.
Installation
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/board.jsonCopies Board and the components it uses (Alert Dialog, Badge, Button, Dropdown Menu, Input, Search Field, Select, and Skeleton) into your app, installs the packages, and adds the styles. Then import it from @/components/ui/board. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-merge @dnd-kit/core @dnd-kit/sortable @dnd-kit/utilities @hugeicons/core-free-icons @hugeicons/react @tanstack/react-virtualAdd Sprout base once per app: the
cn()helper and the design tokens.lib/sprout/classes.ts- Design tokens, for your global CSS
Add the components it uses: Alert Dialog, Badge, Button, Dropdown Menu, Input, Search Field, Select, and Skeleton.
Copy and paste the following code into your project.
'use client'; import { memo, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, type KeyboardEvent, type MouseEvent, type ReactNode, } from 'react'; import { DndContext, DragOverlay, KeyboardSensor, PointerSensor, TouchSensor, closestCenter, pointerWithin, rectIntersection, useDroppable, useSensor, useSensors, type Announcements, type CollisionDetection, type DragEndEvent, type DragOverEvent, type DragStartEvent, type DropAnimation, } from '@dnd-kit/core'; import { SortableContext, arrayMove, defaultAnimateLayoutChanges, horizontalListSortingStrategy, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy, type AnimateLayoutChanges, } from '@dnd-kit/sortable'; import { CSS } from '@dnd-kit/utilities'; import { defaultRangeExtractor, useVirtualizer, type Range } from '@tanstack/react-virtual'; import { AddIcon } from '@/lib/sprout/icons/add-icon'; import { ChevronDownIcon } from '@/lib/sprout/icons/chevron-down-icon'; import { ChevronRightIcon } from '@/lib/sprout/icons/chevron-right-icon'; import { DragHandleIcon } from '@/lib/sprout/icons/drag-handle-icon'; import { MoreIcon } from '@/lib/sprout/icons/more-icon'; import { cn } from '@/lib/sprout/classes'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog'; import { Badge, type BadgeVariant } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { Input } from '@/components/ui/input'; import { SearchField } from '@/components/ui/search-field'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Skeleton } from '@/components/ui/skeleton'; export type BoardColumnStatus = 'loading' | 'error' | 'unavailable'; export interface BoardColumn { id: string; title: string; limit?: number | undefined; total?: number | undefined; status?: BoardColumnStatus | undefined; error?: ReactNode; tone?: BadgeVariant | undefined; icon?: ReactNode; } export interface BoardLane { id: string; title: string; } export interface BoardItem { id: string; columnId: string; laneId?: string | undefined; title: string; } export interface BoardLaneBy { label?: string | undefined; value: string; options: { value: string; label: string }[]; onChange: (value: string) => void; } export interface BoardNewItem { title: string; columnId: string; laneId: string | undefined; } export interface BoardDropTarget { columnId: string; laneId: string | undefined; } export interface BoardColumnText { empty?: ReactNode; showAll?: ((total: number, column: BoardColumn) => ReactNode) | undefined; } export interface BoardCardParts { title: ReactNode; menu: ReactNode; } export interface BoardProps<T extends BoardItem> { columns: BoardColumn[]; items: T[]; lanes?: BoardLane[] | undefined; onItemsChange?: ((items: T[]) => void) | undefined; onColumnsChange?: ((columns: BoardColumn[]) => void) | undefined; onItemAdd?: ((item: BoardNewItem) => void) | undefined; onColumnAdd?: ((title: string) => void) | undefined; onColumnRetry?: ((column: BoardColumn) => void) | undefined; onColumnShowAll?: ((column: BoardColumn) => void) | undefined; columnText?: BoardColumnText | undefined; canDrag?: ((item: T) => boolean) | undefined; canDrop?: ((item: T, to: BoardDropTarget) => boolean) | undefined; dropText?: ((item: T, to: BoardDropTarget) => ReactNode) | undefined; renamable?: boolean | undefined; onItemOpen?: ((item: T) => void) | undefined; renderBody?: ((item: T) => ReactNode) | undefined; renderTitle?: ((item: T) => ReactNode) | undefined; renderCard?: ((item: T, parts: BoardCardParts) => ReactNode) | undefined; itemActions?: ((item: T) => ReactNode) | undefined; searchable?: boolean | undefined; searchText?: ((item: T) => string) | undefined; laneBy?: BoardLaneBy | undefined; label?: string | undefined; className?: string | undefined; } type Cell = { laneId: string; columnId: string }; type DragData = { type: 'card'; id: string } | { type: 'column'; id: string } | { type: 'cell'; cell: Cell }; const CARD = 'card:'; const COLUMN = 'column:'; const cellKey = (laneId: string, columnId: string) => `${laneId}\u0000${columnId}`; const dataOf = (value: unknown) => value as DragData | undefined; const dndAccessibility = { container: typeof document === 'undefined' ? undefined : document.body, }; const keyboardCodes = { start: ['Space'], cancel: ['Escape'], end: ['Space'], }; const animateLayoutChanges: AnimateLayoutChanges = args => defaultAnimateLayoutChanges({ ...args, wasDragging: true }); const dropAnimation: DropAnimation = { duration: 160, easing: 'cubic-bezier(0.2, 0, 0, 1)', }; const reducedMotion = () => typeof window !== 'undefined' && window.matchMedia('(prefers-reduced-motion: reduce)').matches; class NoTouchPointerSensor extends PointerSensor { static override activators = [ { eventName: 'onPointerDown' as const, handler: ({ nativeEvent }: { nativeEvent: PointerEvent }) => nativeEvent.pointerType !== 'touch' && nativeEvent.isPrimary && nativeEvent.button === 0, }, ]; } const sameList = <T,>(a: T[] | undefined, b: T[]) => a !== undefined && a.length === b.length && a.every((x, i) => x === b[i]); const collide: CollisionDetection = args => { const type = dataOf(args.active.data.current)?.type; const droppableContainers = args.droppableContainers.filter(container => type === 'column' ? dataOf(container.data.current)?.type === 'column' : dataOf(container.data.current)?.type !== 'column', ); const scoped = { ...args, droppableContainers }; if (type === 'column') return closestCenter(scoped); const pointer = pointerWithin(scoped); const hits = pointer.length ? pointer : rectIntersection(scoped); const card = hits.find(hit => dataOf(droppableContainers.find(c => c.id === hit.id)?.data.current)?.type === 'card'); return card ? [card] : hits.slice(0, 1); }; function place<T extends BoardItem>( list: T[], ids: string[], to: Cell, beforeId: string | null, laneOf: (item: T) => string, withLanes: boolean, ): T[] { const moving = new Set(ids); const moved = ids.flatMap(id => { const item = list.find(i => i.id === id); if (!item) return []; return [ { ...item, columnId: to.columnId, ...(withLanes ? { laneId: to.laneId } : {}), }, ]; }); const rest = list.filter(item => !moving.has(item.id)); let at = beforeId === null ? -1 : rest.findIndex(i => i.id === beforeId); if (at === -1) { at = rest.length; for (let i = rest.length - 1; i >= 0; i--) { const item = rest[i]!; if (item.columnId === to.columnId && laneOf(item) === to.laneId) { at = i + 1; break; } } } rest.splice(at, 0, ...moved); return rest; } export function Board<T extends BoardItem>({ columns, items, lanes, onItemsChange, onColumnsChange, onItemAdd, onColumnAdd, onColumnRetry, onColumnShowAll, columnText, onItemOpen, canDrag, canDrop, dropText, renamable = true, renderBody, renderTitle, renderCard, itemActions, searchable, searchText, laneBy, label = 'Board', className, }: BoardProps<T>) { const dndId = useId(); const withLanes = lanes !== undefined; const laneList = useMemo<BoardLane[]>(() => lanes ?? [{ id: '', title: label }], [lanes, label]); const laneOf = (item: T) => (withLanes ? (item.laneId ?? '') : ''); const [draft, setDraft] = useState<T[] | null>(null); const draftRef = useRef<T[] | null>(null); const setDraftBoth = (next: T[] | null) => { draftRef.current = next; setDraft(next); }; const shown = draft ?? items; const [query, setQuery] = useState(''); const [selected, setSelected] = useState<Set<string>>(() => new Set()); const [anchor, setAnchor] = useState<string | null>(null); const [collapsedColumns, setCollapsedColumns] = useState<Set<string>>(() => new Set()); const [collapsedLanes, setCollapsedLanes] = useState<Set<string>>(() => new Set()); const [active, setActive] = useState<DragData | null>(null); const [extras, setExtras] = useState<string[]>([]); const [laneLock, setLaneLock] = useState<Map<string, number> | null>(null); const movedRef = useRef(false); const needle = query.trim().toLowerCase(); const matches = (item: T) => !needle || item.title.toLowerCase().includes(needle) || (searchText?.(item).toLowerCase().includes(needle) ?? false); const cellsRef = useRef(new Map<string, T[]>()); const cells = useMemo(() => { const map = new Map<string, T[]>(); for (const item of shown) { if (!matches(item)) continue; const key = cellKey(laneOf(item), item.columnId); const list = map.get(key); if (list) list.push(item); else map.set(key, [item]); } for (const [key, list] of map) { const before = cellsRef.current.get(key); if (sameList(before, list)) map.set(key, before!); } cellsRef.current = map; return map; // eslint-disable-next-line react-hooks/exhaustive-deps }, [shown, needle, searchText, withLanes]); const columnTotals = useMemo(() => { const totals = new Map<string, number>(); for (const item of shown) totals.set(item.columnId, (totals.get(item.columnId) ?? 0) + 1); return totals; }, [shown]); const laneTotals = (laneId: string) => columns.reduce((sum, column) => sum + (cells.get(cellKey(laneId, column.id))?.length ?? 0), 0); const visibleCount = [...cells.values()].reduce((s, l) => s + l.length, 0); const findItem = (id: string) => (draftRef.current ?? items).find(item => item.id === id); const cellOf = (item: T): Cell => ({ laneId: laneOf(item), columnId: item.columnId, }); const cellName = (cell: Cell) => { const column = columns.find(c => c.id === cell.columnId)?.title ?? ''; const lane = laneList.find(l => l.id === cell.laneId)?.title; return withLanes && lane ? `${column}, ${lane}` : column; }; const targetOf = (cell: Cell): BoardDropTarget => ({ columnId: cell.columnId, laneId: withLanes ? cell.laneId : undefined, }); const allowed = (item: T, cell: Cell) => canDrop?.(item, targetOf(cell)) ?? true; const draggable = (item: T) => canDrag?.(item) ?? true; const sameCell = (a: Cell, b: Cell) => a.laneId === b.laneId && a.columnId === b.columnId; const originOf = (id: string) => items.find(item => item.id === id); const overCell = (target: DragData | undefined): Cell | undefined => { if (target?.type === 'cell') return target.cell; if (target?.type !== 'card') return undefined; const overItem = findItem(target.id); return overItem ? cellOf(overItem) : undefined; }; const sensors = useSensors( useSensor(NoTouchPointerSensor, { activationConstraint: { distance: 4 } }), useSensor(TouchSensor, { activationConstraint: { delay: 200, tolerance: 6 }, }), useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates, keyboardCodes, }), ); const onDragStart = ({ active: a }: DragStartEvent) => { const data = dataOf(a.data.current); if (!data) return; setActive(data); if (data.type !== 'card') return; setLaneLock(new Map(laneVirtualizer.getVirtualItems().map(row => [laneList[row.index]?.id ?? '', row.size]))); const others = selected.has(data.id) ? shown.filter(item => selected.has(item.id) && item.id !== data.id && draggable(item)).map(item => item.id) : []; if (!selected.has(data.id)) setSelected(new Set()); setExtras(others); const hidden = new Set(others); setDraftBoth(items.filter(item => !hidden.has(item.id))); }; const onDragOver = ({ active: a, over }: DragOverEvent) => { const data = dataOf(a.data.current); const target = dataOf(over?.data.current); if (data?.type !== 'card' || !over || !target || movedRef.current) return; const list = draftRef.current; const item = findItem(data.id); if (!list || !item) return; let to: Cell; let beforeId: string | null = null; if (target.type === 'card') { if (target.id === data.id) return; const overItem = findItem(target.id); if (!overItem) return; to = cellOf(overItem); const siblings = cells.get(cellKey(to.laneId, to.columnId)) ?? []; const translated = a.rect.current.translated; const below = translated !== null && translated.top > over.rect.top + over.rect.height / 2; const index = siblings.findIndex(s => s.id === target.id); beforeId = below ? (siblings[index + 1]?.id ?? null) : target.id; } else if (target.type === 'cell') { to = target.cell; } else return; const from = cellOf(item); if (sameCell(from, to)) return; const origin = originOf(data.id); if (origin && !sameCell(cellOf(origin), to) && !allowed(origin, to)) { if (!sameCell(from, cellOf(origin))) setDraftBoth(items.filter(i => !extras.includes(i.id))); return; } movedRef.current = true; requestAnimationFrame(() => { movedRef.current = false; }); setDraftBoth(place(list, [data.id], to, beforeId, laneOf, withLanes)); }; const finish = () => { setDraftBoth(null); setLaneLock(null); setActive(null); setExtras([]); }; const onDragEnd = ({ active: a, over }: DragEndEvent) => { const data = dataOf(a.data.current); const target = dataOf(over?.data.current); if (data?.type === 'column') { if (target?.type === 'column' && target.id !== data.id && onColumnsChange) { const ids = columns.map(c => c.id); onColumnsChange(arrayMove(columns, ids.indexOf(data.id), ids.indexOf(target.id))); } return finish(); } let list = draftRef.current; const item = data?.type === 'card' ? findItem(data.id) : undefined; const origin = data?.type === 'card' ? originOf(data.id) : undefined; if (!list || !item || !origin || data?.type !== 'card') return finish(); const cell = cellOf(item); if (!allowed(origin, cell)) return finish(); const siblings = cells.get(cellKey(cell.laneId, cell.columnId)) ?? []; if (target?.type === 'card' && target.id !== data.id) { const ids = siblings.map(s => s.id); const from = ids.indexOf(data.id); const to = ids.indexOf(target.id); if (from !== -1 && to !== -1) { const order = arrayMove(ids, from, to); list = place(list, [data.id], cell, order[to + 1] ?? null, laneOf, withLanes); } } const kept = extras.filter(id => { const extra = originOf(id); return extra && (sameCell(cellOf(extra), cell) || allowed(extra, cell)); }); for (const id of extras.filter(i => !kept.includes(i))) { const index = items.findIndex(i => i.id === id); const extra = items[index]!; const home = cellOf(extra); const next = items .slice(index + 1) .find(i => !extras.includes(i.id) && i.id !== data.id && sameCell(cellOf(i), home)); list = place([...list, extra], [id], home, next?.id ?? null, laneOf, withLanes); } if (kept.length) { list = [...list, ...items.filter(i => kept.includes(i.id))]; const after = list.indexOf(list.find(i => i.id === data.id)!) + 1; list = place(list, kept, cell, list[after]?.id ?? null, laneOf, withLanes); const next = list[list.findIndex(i => i.id === kept.at(-1)) + 1]; if (next && cellKey(laneOf(next), next.columnId) !== cellKey(cell.laneId, cell.columnId)) list = place(list, kept, cell, null, laneOf, withLanes); } const changed = list.some((i, index) => i !== items[index]) || list.length !== items.length; finish(); if (changed) onItemsChange?.(list); }; const announcements: Announcements = { onDragStart: ({ active: a }) => { const data = dataOf(a.data.current); if (data?.type === 'column') return `Picked up column ${columns.find(c => c.id === data.id)?.title}.`; const item = data?.type === 'card' ? findItem(data.id) : undefined; return item ? `Picked up card ${item.title}.` : undefined; }, onDragOver: ({ active: a, over }) => { const data = dataOf(a.data.current); if (!over) return undefined; if (data?.type === 'column') { const target = dataOf(over.data.current); return target?.type === 'column' ? `Over column ${columns.find(c => c.id === target.id)?.title}.` : undefined; } const item = data?.type === 'card' ? findItem(data.id) : undefined; if (!item) return undefined; const origin = originOf(item.id); const to = overCell(dataOf(over.data.current)); if (origin && to && !sameCell(cellOf(origin), to) && !allowed(origin, to)) return `Card ${item.title} can’t move to ${cellName(to)}.`; return `Card ${item.title} is in ${cellName(cellOf(item))}.`; }, onDragEnd: ({ active: a }) => { const data = dataOf(a.data.current); if (data?.type === 'column') return 'Column dropped.'; const item = data?.type === 'card' ? findItem(data.id) : undefined; return item ? `Card ${item.title} dropped in ${cellName(cellOf(item))}.` : undefined; }, onDragCancel: () => 'Move cancelled. The card went back.', }; const select = (item: T, event: MouseEvent) => { const next = new Set(selected); if (event.shiftKey && anchor) { const flat = laneList.flatMap(lane => columns.flatMap(c => cells.get(cellKey(lane.id, c.id)) ?? [])); const from = flat.findIndex(i => i.id === anchor); const to = flat.findIndex(i => i.id === item.id); if (from !== -1 && to !== -1) for (const i of flat.slice(Math.min(from, to), Math.max(from, to) + 1)) next.add(i.id); } else if (next.has(item.id)) next.delete(item.id); else next.add(item.id); setSelected(next); setAnchor(item.id); }; const canRename = !!onItemsChange && renamable; const rename = (item: T, title: string) => onItemsChange?.(items.map(i => (i.id === item.id ? { ...i, title } : i))); const renameColumn = (column: BoardColumn, title: string) => onColumnsChange?.(columns.map(c => (c.id === column.id ? { ...c, title } : c))); const deleteColumn = (column: BoardColumn) => { onColumnsChange?.(columns.filter(c => c.id !== column.id)); if (items.some(i => i.columnId === column.id)) onItemsChange?.(items.filter(i => i.columnId !== column.id)); }; const latest = useRef({ select, rename }); useLayoutEffect(() => { latest.current = { select, rename }; }); const onSelect = useCallback((item: T, event: MouseEvent) => latest.current.select(item, event), []); const onRename = useCallback((item: T, title: string) => latest.current.rename(item, title), []); const toggle = (set: Set<string>, id: string) => { const next = new Set(set); if (next.has(id)) next.delete(id); else next.add(id); return next; }; const viewportRef = useRef<HTMLDivElement>(null); const bodyRef = useRef<HTMLDivElement>(null); const [bodyTop, setBodyTop] = useState(0); useLayoutEffect(() => { setBodyTop(bodyRef.current?.offsetTop ?? 0); }); useEffect(() => { const viewport = viewportRef.current; const frame = viewport?.parentElement; if (!viewport || !frame) return; const update = () => { const { scrollLeft, scrollWidth, clientWidth } = viewport; frame.toggleAttribute('data-more-start', scrollLeft > 1); frame.toggleAttribute('data-more-end', scrollLeft + clientWidth < scrollWidth - 1); }; update(); viewport.addEventListener('scroll', update, { passive: true }); const observer = new ResizeObserver(update); observer.observe(viewport); if (viewport.firstElementChild) observer.observe(viewport.firstElementChild); return () => { viewport.removeEventListener('scroll', update); observer.disconnect(); }; }, []); const activeLane = active?.type === 'card' ? laneList.findIndex(l => { const item = findItem(active.id); return item ? l.id === laneOf(item) : false; }) : -1; const laneVirtualizer = useVirtualizer({ count: withLanes ? laneList.length : 0, getScrollElement: () => viewportRef.current, estimateSize: () => 140, overscan: 2, scrollMargin: bodyTop, initialRect: { width: 0, height: 720 }, getItemKey: index => laneList[index]?.id ?? index, rangeExtractor: (range: Range) => { const indexes = defaultRangeExtractor(range); return activeLane !== -1 && !indexes.includes(activeLane) ? [...indexes, activeLane].sort((a, b) => a - b) : indexes; }, }); const laneRows = laneVirtualizer.getVirtualItems().map((row, i, rows) => ({ ...row, pinned: rows.length > 1 && row.index === activeLane && rows[i - 1]?.index !== row.index - 1 && rows[i + 1]?.index !== row.index + 1, })); const firstFlow = laneRows.find(row => !row.pinned); const onBoardKeyDown = (event: KeyboardEvent) => { if (event.key === 'Escape' && selected.size && !active) setSelected(new Set()); }; const activeItem = active?.type === 'card' ? findItem(active.id) : undefined; const activeColumn = active?.type === 'column' ? columns.find(c => c.id === active.id) : undefined; const columnTemplate = columns .map(c => (collapsedColumns.has(c.id) ? 'var(--sprout-board-collapsed-width)' : 'var(--sprout-board-column-width)')) .join(' '); const gridStyle = { gridTemplateColumns: `${columnTemplate}${onColumnAdd ? ' var(--sprout-board-column-width)' : ''}`, }; const loadedIn = (column: BoardColumn) => columnTotals.get(column.id) ?? 0; const showAllCount = (column: BoardColumn) => onColumnShowAll && !column.status && !collapsedColumns.has(column.id) && column.total !== undefined && column.total > loadedIn(column) ? column.total : undefined; const laneNotices = withLanes && columns.some(c => c.status === 'error' || c.status === 'unavailable'); const laneFoot = withLanes && columns.some(c => showAllCount(c) !== undefined); const dragOrigin = active?.type === 'card' && (canDrop || dropText) ? originOf(active.id) : undefined; const dropState = (laneId: string, columnId: string): 'allowed' | 'blocked' | undefined => { if (!dragOrigin) return undefined; const cell = { laneId, columnId }; if (sameCell(cellOf(dragOrigin), cell)) return undefined; return allowed(dragOrigin, cell) ? 'allowed' : 'blocked'; }; const dropTextFor = (laneId: string, columnId: string) => dragOrigin && dropText && dropState(laneId, columnId) === 'allowed' ? dropText(dragOrigin, targetOf({ laneId, columnId })) : undefined; const renderRow = (lane: BoardLane) => ( <div className="sprout-board-row" style={gridStyle}> {columns.map(column => ( <BoardCell key={column.id} laneId={lane.id} column={column} name={cellName({ laneId: lane.id, columnId: column.id })} items={cells.get(cellKey(lane.id, column.id)) ?? []} collapsed={collapsedColumns.has(column.id)} fill={!withLanes} empty={ !column.status && !column.total && loadedIn(column) === 0 ? (columnText?.empty ?? 'No cards') : undefined } showAll={withLanes ? undefined : showAllCount(column)} onShowAll={!withLanes && showAllCount(column) !== undefined ? onColumnShowAll : undefined} showAllText={columnText?.showAll} onRetry={!withLanes && column.status === 'error' ? onColumnRetry : undefined} activeId={active?.type === 'card' ? active.id : null} movable={!!onItemsChange && !needle} canDrag={canDrag} drop={dropState(lane.id, column.id)} dropText={dropTextFor(lane.id, column.id)} selected={selected} onSelect={onItemsChange ? onSelect : undefined} onRename={canRename ? onRename : undefined} onItemAdd={onItemAdd} onItemOpen={onItemOpen} look={look} /> ))} </div> ); const look = useMemo<CardLook<T>>( () => ({ renderBody, renderTitle, renderCard, itemActions }), [renderBody, renderTitle, renderCard, itemActions], ); const toolbar = searchable || laneBy || selected.size > 0; return ( <div data-slot="board" className={cn('sprout-board', className)} onKeyDown={onBoardKeyDown}> {toolbar && ( <div className="sprout-board-toolbar" data-slot="board-toolbar"> {searchable && ( <SearchField label="Search cards" value={query} onChange={setQuery} className="sprout-board-search" /> )} {laneBy && ( <span className="sprout-board-lane-by"> <span>{laneBy.label ?? 'Lanes by'}</span> <Select value={laneBy.value} onValueChange={value => { if (typeof value === 'string') laneBy.onChange(value); }} > <SelectTrigger size="sm" aria-label={laneBy.label ?? 'Lanes by'}> <SelectValue>{laneBy.options.find(o => o.value === laneBy.value)?.label}</SelectValue> </SelectTrigger> <SelectContent> {laneBy.options.map(option => ( <SelectItem key={option.value} value={option.value}> {option.label} </SelectItem> ))} </SelectContent> </Select> </span> )} <span className="sprout-board-status" role="status"> {selected.size > 0 ? ( <> {selected.size} selected <Button variant="ghost" size="sm" onClick={() => setSelected(new Set())}> Clear </Button> </> ) : needle ? ( visibleCount ? ( `${visibleCount.toLocaleString('en-US')} of ${items.length.toLocaleString('en-US')} cards` ) : ( `No cards match “${query.trim()}”` ) ) : ( `${items.length.toLocaleString('en-US')} cards` )} </span> </div> )} <DndContext id={dndId} sensors={sensors} accessibility={{ ...dndAccessibility, announcements }} collisionDetection={collide} onDragStart={onDragStart} onDragOver={onDragOver} onDragEnd={onDragEnd} onDragCancel={finish} > <div className="sprout-board-frame"> <div ref={viewportRef} role="region" aria-label={label} className="sprout-board-viewport" data-lanes={withLanes || undefined} > <div className="sprout-board-canvas"> <div className="sprout-board-header" style={gridStyle}> <SortableContext items={columns.map(c => COLUMN + c.id)} strategy={horizontalListSortingStrategy}> {columns.map(column => ( <BoardColumnHeader key={column.id} column={column} loaded={loadedIn(column)} collapsed={collapsedColumns.has(column.id)} onCollapse={() => setCollapsedColumns(s => toggle(s, column.id))} onRename={onColumnsChange ? renameColumn : undefined} onDelete={onColumnsChange ? deleteColumn : undefined} /> ))} </SortableContext> {onColumnAdd && <AddColumn onAdd={onColumnAdd} />} {laneNotices && columns.map(column => ( <div key={`notice:${column.id}`} className="sprout-board-column-notice"> {!collapsedColumns.has(column.id) && <ColumnNotice column={column} onRetry={onColumnRetry} />} </div> ))} </div> {withLanes ? ( <div ref={bodyRef} className="sprout-board-lanes" style={{ height: laneVirtualizer.getTotalSize() }}> {laneRows.map(row => { const lane = laneList[row.index]; if (!lane) return null; const collapsed = collapsedLanes.has(lane.id); const count = laneTotals(lane.id); return ( <section key={row.key} ref={laneVirtualizer.measureElement} data-index={row.index} aria-label={`${lane.title}, ${count} cards`} className="sprout-board-lane" data-collapsed={collapsed || undefined} data-pinned={row.pinned || undefined} style={{ ...(row.pinned ? { top: row.start - bodyTop } : row === firstFlow ? { marginTop: row.start - bodyTop } : {}), minHeight: laneLock?.get(lane.id), }} > <div className="sprout-board-lane-bar"> <button type="button" className="sprout-board-lane-toggle" aria-expanded={!collapsed} onClick={() => setCollapsedLanes(s => toggle(s, lane.id))} > {collapsed ? ( <ChevronRightIcon aria-hidden="true" /> ) : ( <ChevronDownIcon aria-hidden="true" /> )} <span className="sprout-board-lane-title">{lane.title}</span> <span className="sprout-board-count">{count}</span> </button> </div> {!collapsed && renderRow(lane)} </section> ); })} </div> ) : ( <div ref={bodyRef} className="sprout-board-single"> {laneList[0] && renderRow(laneList[0])} </div> )} {laneFoot && onColumnShowAll && ( <div className="sprout-board-foot" style={gridStyle}> {columns.map(column => { const count = showAllCount(column); return ( <div key={column.id}> {count !== undefined && ( <ShowAll column={column} count={count} onShowAll={onColumnShowAll} text={columnText?.showAll} /> )} </div> ); })} </div> )} </div> </div> </div> <DragOverlay dropAnimation={reducedMotion() ? null : dropAnimation}> {activeItem ? ( <div className="sprout-board-overlay"> <CardFace item={activeItem} look={look} /> {extras.length > 0 && ( <Badge variant="default" className="sprout-board-overlay-count"> {extras.length + 1} cards </Badge> )} </div> ) : activeColumn ? ( <div className="sprout-board-column-header sprout-board-overlay"> <span className="sprout-board-column-title" data-tone={activeColumn.tone ? '' : undefined}> <ColumnTitle column={activeColumn} /> </span> </div> ) : null} </DragOverlay> </DndContext> </div> ); } interface CardLook<T extends BoardItem> { renderBody: ((item: T) => ReactNode) | undefined; renderTitle: ((item: T) => ReactNode) | undefined; renderCard: ((item: T, parts: BoardCardParts) => ReactNode) | undefined; itemActions: ((item: T) => ReactNode) | undefined; } const cardTitle = <T extends BoardItem>(item: T, look: CardLook<T>) => ( <span className="sprout-board-card-title">{look.renderTitle ? look.renderTitle(item) : item.title}</span> ); function cardInside<T extends BoardItem>(item: T, look: CardLook<T>, parts: BoardCardParts, bodyId?: string) { if (look.renderCard) return look.renderCard(item, parts); const body = look.renderBody?.(item); return ( <> <div className="sprout-board-card-head"> {parts.title} {parts.menu} </div> {body != null && ( <div id={bodyId} className="sprout-board-card-body"> {body} </div> )} </> ); } function CardFace<T extends BoardItem>({ item, look }: { item: T; look: CardLook<T> }) { return ( <div className="sprout-board-card" data-overlay="" data-custom={look.renderCard ? '' : undefined}> {cardInside(item, look, { title: cardTitle(item, look), menu: null })} </div> ); } interface BoardCellProps<T extends BoardItem> { laneId: string; column: BoardColumn; name: string; items: T[]; collapsed: boolean; fill: boolean; empty: ReactNode; showAll: number | undefined; onShowAll: ((column: BoardColumn) => void) | undefined; showAllText: BoardColumnText['showAll']; onRetry: ((column: BoardColumn) => void) | undefined; activeId: string | null; movable: boolean; canDrag: ((item: T) => boolean) | undefined; drop: 'allowed' | 'blocked' | undefined; dropText: ReactNode; selected: Set<string>; onSelect: ((item: T, event: MouseEvent) => void) | undefined; onRename: ((item: T, title: string) => void) | undefined; onItemAdd: ((item: BoardNewItem) => void) | undefined; onItemOpen: ((item: T) => void) | undefined; look: CardLook<T>; } const BoardCell = memo(function BoardCell<T extends BoardItem>({ laneId, column, name, items, collapsed, fill, empty, showAll, onShowAll, showAllText, onRetry, activeId, movable, canDrag, drop: dropAllowed, dropText, selected, onSelect, onRename, onItemAdd, onItemOpen, look, }: BoardCellProps<T>) { const columnId = column.id; const status = column.status; const cell = useMemo(() => ({ laneId, columnId }), [laneId, columnId]); const drop = useDroppable({ id: `cell:${cellKey(cell.laneId, cell.columnId)}`, data: { type: 'cell', cell } satisfies DragData, disabled: status !== undefined, }); const scrollRef = useRef<HTMLDivElement>(null); const activeIndex = activeId ? items.findIndex(i => i.id === activeId) : -1; const virtualizer = useVirtualizer({ count: collapsed ? 0 : items.length, getScrollElement: () => scrollRef.current, estimateSize: () => 60, gap: 4, overscan: 6, initialRect: { width: 0, height: 480 }, getItemKey: index => items[index]?.id ?? index, rangeExtractor: (range: Range) => { const indexes = defaultRangeExtractor(range); return activeIndex !== -1 && !indexes.includes(activeIndex) ? [...indexes, activeIndex].sort((a, b) => a - b) : indexes; }, }); const [adding, setAdding] = useState(false); if (collapsed) return ( <div ref={drop.setNodeRef} className="sprout-board-cell" data-collapsed="" data-over={drop.isOver || undefined} data-drop={dropAllowed} aria-label={`${name}, ${items.length} cards, collapsed`} role="group" > <span className="sprout-board-count">{items.length || ''}</span> </div> ); return ( <div ref={drop.setNodeRef} className="sprout-board-cell" data-fill={fill || undefined} data-over={drop.isOver || undefined} data-drop={dropAllowed} data-status={status} > {fill && <ColumnNotice column={column} onRetry={onRetry} />} <div ref={scrollRef} className="sprout-board-cell-scroll"> <SortableContext items={items.map(i => CARD + i.id)} strategy={verticalListSortingStrategy}> <div role="list" aria-label={`${name}, ${items.length} cards`} aria-busy={status === 'loading' || undefined} className="sprout-board-cards" style={{ height: virtualizer.getTotalSize() }} > {virtualizer.getVirtualItems().map(row => { const item = items[row.index]; if (!item) return null; return ( <div key={row.key} ref={virtualizer.measureElement} data-index={row.index} role="listitem" className="sprout-board-card-slot" style={{ top: row.start }} > <BoardCard item={item} movable={movable && (canDrag?.(item) ?? true)} selected={selected.has(item.id)} onSelect={onSelect} onRename={onRename} onOpen={onItemOpen} look={look} /> </div> ); })} </div> </SortableContext> {status === 'loading' && items.length === 0 && ( <div className="sprout-board-skeletons" aria-hidden="true"> {Array.from({ length: fill ? 3 : 2 }, (_, index) => ( <div key={index} className="sprout-board-skeleton-card"> <Skeleton /> <Skeleton /> </div> ))} </div> )} {empty !== undefined && items.length === 0 && <p className="sprout-board-empty">{empty}</p>} </div> {dropText != null && <p className="sprout-board-drop-text">{dropText}</p>} {showAll !== undefined && onShowAll && ( <ShowAll column={column} count={showAll} onShowAll={onShowAll} text={showAllText} /> )} {onItemAdd && !status && (adding ? ( <InlineText label={`New card in ${name}`} placeholder="Card title" initial="" keepOpen onCommit={title => onItemAdd({ title, columnId: cell.columnId, laneId: fill ? undefined : cell.laneId, }) } onClose={() => setAdding(false)} /> ) : ( <Button variant="ghost" size="sm" className="sprout-board-add" onClick={() => setAdding(true)} aria-label={`Add card to ${name}`} > <AddIcon aria-hidden="true" data-icon="inline-start" /> Add card </Button> ))} </div> ); }) as <T extends BoardItem>(props: BoardCellProps<T>) => ReactNode; interface BoardCardProps<T extends BoardItem> { item: T; movable: boolean; selected: boolean; onSelect: ((item: T, event: MouseEvent) => void) | undefined; onRename: ((item: T, title: string) => void) | undefined; onOpen: ((item: T) => void) | undefined; look: CardLook<T>; } const BoardCard = memo(function BoardCard<T extends BoardItem>({ item, movable, selected, onSelect, onRename, onOpen, look, }: BoardCardProps<T>) { const [editing, setEditing] = useState(false); const sortable = useSortable({ id: CARD + item.id, data: { type: 'card', id: item.id } satisfies DragData, disabled: !movable || editing, animateLayoutChanges, }); const bodyId = useId(); const actions = look.itemActions?.(item); const describe = !look.renderCard && !!look.renderBody; const onClick = (event: MouseEvent) => { if (onSelect && (event.metaKey || event.ctrlKey || event.shiftKey)) { event.preventDefault(); onSelect(item, event); return; } onOpen?.(item); }; const onKeyDown = (event: KeyboardEvent) => { if (event.target !== event.currentTarget) return; if (event.key === 'Enter' && onOpen) { event.preventDefault(); onOpen(item); } else if (event.key === 'F2' && onRename) { event.preventDefault(); setEditing(true); } }; return ( <div ref={sortable.setNodeRef} {...sortable.attributes} {...sortable.listeners} aria-disabled={undefined} role="group" aria-roledescription={movable ? 'draggable card' : 'card'} aria-label={item.title} aria-describedby={describe ? bodyId : undefined} tabIndex={0} className="sprout-board-card" data-selected={selected || undefined} data-dragging={sortable.isDragging || undefined} data-openable={onOpen ? '' : undefined} data-custom={look.renderCard ? '' : undefined} style={{ transform: CSS.Translate.toString(sortable.transform), transition: sortable.transition, }} onClick={editing ? undefined : onClick} onDoubleClick={onRename && !onOpen && !editing ? () => setEditing(true) : undefined} onKeyDown={event => { onKeyDown(event); if (event.target === event.currentTarget && !event.defaultPrevented) sortable.listeners?.onKeyDown?.(event); }} > {cardInside( item, look, { title: editing && onRename ? ( <InlineText label="Card title" initial={item.title} onCommit={title => onRename(item, title)} onClose={() => setEditing(false)} /> ) : ( cardTitle(item, look) ), menu: (actions != null || onRename) && !editing ? ( <DropdownMenu> <DropdownMenuTrigger render={ <Button variant="ghost" size="icon-xs" className="sprout-board-card-menu" aria-label={`Actions for ${item.title}`} onClick={event => event.stopPropagation()} onPointerDown={event => event.stopPropagation()} /> } > <MoreIcon aria-hidden="true" /> </DropdownMenuTrigger> <DropdownMenuContent align="end"> {onRename && <DropdownMenuItem onClick={() => setEditing(true)}>Rename</DropdownMenuItem>} {onRename && actions != null && <DropdownMenuSeparator />} {actions} </DropdownMenuContent> </DropdownMenu> ) : null, }, bodyId, )} </div> ); }) as <T extends BoardItem>(props: BoardCardProps<T>) => ReactNode; interface BoardColumnHeaderProps { column: BoardColumn; loaded: number; collapsed: boolean; onCollapse: () => void; onRename: ((column: BoardColumn, title: string) => void) | undefined; onDelete: ((column: BoardColumn) => void) | undefined; } const statusWords: Record<BoardColumnStatus, string> = { loading: 'loading', error: 'couldn’t load', unavailable: 'unavailable', }; function BoardColumnHeader({ column, loaded, collapsed, onCollapse, onRename, onDelete }: BoardColumnHeaderProps) { const [editing, setEditing] = useState(false); const [confirming, setConfirming] = useState(false); const sortable = useSortable({ id: COLUMN + column.id, data: { type: 'column', id: column.id } satisfies DragData, disabled: !onRename || editing, }); const total = column.total ?? loaded; const counted = column.total !== undefined || !column.status; const over = counted && column.limit !== undefined && total > column.limit; const count = column.limit !== undefined ? `${formatCount(total)} / ${formatCount(column.limit)}` : formatCount(total); const label = [ column.title, counted && `${formatCount(total)} cards`, counted && total > loaded && !column.status && `${loaded} shown`, column.status && statusWords[column.status], over && 'over limit', ] .filter(Boolean) .join(', '); const toggleButton = ( <button type="button" className="sprout-board-column-toggle" aria-expanded={!collapsed} aria-label={`${collapsed ? 'Expand' : 'Collapse'} ${column.title}`} onClick={onCollapse} > {collapsed ? <ChevronRightIcon aria-hidden="true" /> : <ChevronDownIcon aria-hidden="true" />} </button> ); return ( <div ref={sortable.setNodeRef} {...sortable.listeners} role="group" aria-label={label} aria-busy={column.status === 'loading' || undefined} className="sprout-board-column-header" data-collapsed={collapsed || undefined} data-over-limit={over || undefined} data-dragging={sortable.isDragging || undefined} style={{ transform: CSS.Translate.toString(sortable.transform), transition: sortable.transition, }} > {collapsed && toggleButton} {column.icon != null && !collapsed && !editing && ( <span className="sprout-board-column-icon" aria-hidden="true"> {column.icon} </span> )} {editing && onRename ? ( <InlineText label="Column title" initial={column.title} onCommit={title => onRename(column, title)} onClose={() => setEditing(false)} /> ) : onRename && !collapsed ? ( <button type="button" className="sprout-board-column-title" data-editable="" onClick={() => setEditing(true)} aria-label={`Rename ${column.title}`} data-tone={column.tone ? '' : undefined} > <ColumnTitle column={column} /> </button> ) : ( <span className="sprout-board-column-title" data-tone={column.tone && !collapsed ? '' : undefined}> {collapsed ? column.title : <ColumnTitle column={column} />} </span> )} {!editing && counted && ( <span className="sprout-board-count" aria-hidden="true"> {count} </span> )} <span role="status" className="sprout-board-sr-only"> {column.status === 'loading' ? `Loading cards in ${column.title}…` : ''} </span> {over && !collapsed && !editing && ( <Badge variant="warning" className="sprout-board-limit"> Over limit </Badge> )} {!collapsed && !editing && ( <span className="sprout-board-column-tools"> {toggleButton} {onRename && ( <> <button type="button" ref={sortable.setActivatorNodeRef} {...sortable.attributes} className="sprout-board-grip" aria-label={`Move ${column.title}`} > <DragHandleIcon aria-hidden="true" /> </button> <DropdownMenu> <DropdownMenuTrigger render={ <Button variant="ghost" size="icon-xs" aria-label={`${column.title} column actions`} onPointerDown={event => event.stopPropagation()} /> } > <MoreIcon aria-hidden="true" /> </DropdownMenuTrigger> <DropdownMenuContent align="end"> <DropdownMenuItem onClick={() => setEditing(true)}>Rename</DropdownMenuItem> <DropdownMenuItem onClick={onCollapse}>Collapse</DropdownMenuItem> {onDelete && ( <> <DropdownMenuSeparator /> <DropdownMenuItem variant="destructive" onClick={() => setConfirming(true)}> Delete column… </DropdownMenuItem> </> )} </DropdownMenuContent> </DropdownMenu> </> )} </span> )} {onDelete && ( <AlertDialog open={confirming} onOpenChange={setConfirming}> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Delete “{column.title}”?</AlertDialogTitle> <AlertDialogDescription> {total ? `Its ${total} ${total === 1 ? 'card is' : 'cards are'} deleted too. This can’t be undone.` : 'The column is empty. This can’t be undone.'} </AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel>Keep column</AlertDialogCancel> <AlertDialogAction variant="destructive" onClick={() => { setConfirming(false); onDelete(column); }} > Delete column </AlertDialogAction> </AlertDialogFooter> </AlertDialogContent> </AlertDialog> )} </div> ); } const formatCount = (count: number) => count.toLocaleString('en-US'); function ColumnTitle({ column }: { column: BoardColumn }) { if (!column.tone) return column.title; return ( <Badge variant={column.tone} className="sprout-board-column-badge"> <span>{column.title}</span> </Badge> ); } function ColumnNotice({ column, onRetry, }: { column: BoardColumn; onRetry: ((column: BoardColumn) => void) | undefined; }) { if (column.status === 'error') return ( <div className="sprout-board-notice" data-kind="error"> <p role="alert">{column.error ?? 'Couldn’t load this column.'}</p> {onRetry && ( <Button variant="outline" size="sm" aria-label={`Try again to load ${column.title}`} onClick={() => onRetry(column)} > Try again </Button> )} </div> ); if (column.status === 'unavailable') return ( <p className="sprout-board-notice" data-kind="unavailable"> {column.error ?? 'Cards are unavailable.'} </p> ); return null; } function ShowAll({ column, count, onShowAll, text, }: { column: BoardColumn; count: number; onShowAll: (column: BoardColumn) => void; text: BoardColumnText['showAll']; }) { return ( <Button variant="ghost" size="sm" className="sprout-board-show-all" aria-label={text ? undefined : `Show all ${formatCount(count)} in ${column.title}`} onClick={() => onShowAll(column)} > {text ? ( <> {text(count, column)} <span className="sprout-board-sr-only">, {column.title}</span> </> ) : ( `Show all ${formatCount(count)}` )} </Button> ); } function AddColumn({ onAdd }: { onAdd: (title: string) => void }) { const [adding, setAdding] = useState(false); return ( <div className="sprout-board-add-column"> {adding ? ( <InlineText label="New column" placeholder="Column title" initial="" onCommit={onAdd} onClose={() => setAdding(false)} /> ) : ( <Button variant="ghost" size="sm" onClick={() => setAdding(true)}> <AddIcon aria-hidden="true" data-icon="inline-start" /> Add column </Button> )} </div> ); } function InlineText({ label, placeholder, initial, keepOpen, onCommit, onClose, }: { label: string; placeholder?: string; initial: string; keepOpen?: boolean; onCommit: (value: string) => void; onClose: () => void; }) { const [value, setValue] = useState(initial); const ref = useRef<HTMLInputElement>(null); const done = useRef(false); useEffect(() => { ref.current?.focus(); ref.current?.select(); }, []); const commit = (close: boolean) => { const text = value.trim(); if (text && text !== initial) onCommit(text); if (close || !keepOpen) { done.current = true; onClose(); } else setValue(''); }; return ( <Input ref={ref} aria-label={label} placeholder={placeholder} value={value} className="sprout-board-inline-input" onChange={event => setValue(event.currentTarget.value)} onPointerDown={event => event.stopPropagation()} onClick={event => event.stopPropagation()} onKeyDown={event => { event.stopPropagation(); if (event.key === 'Enter') { event.preventDefault(); commit(false); } else if (event.key === 'Escape') { event.preventDefault(); done.current = true; onClose(); } }} onBlur={() => { if (!done.current) commit(true); }} /> ); }And the files it imports:
lib/sprout/icons/add-icon.tsxlib/sprout/icons/chevron-down-icon.tsxlib/sprout/icons/chevron-right-icon.tsxlib/sprout/icons/create-icon.tsxlib/sprout/icons/drag-handle-icon.tsxlib/sprout/icons/more-icon.tsx
Add the styles to your global CSS, after
@import "tailwindcss".@layer components { .sprout-board { --sprout-board-column-width: min(17rem, 85vw); --sprout-board-collapsed-width: 2.75rem; --sprout-board-height: 36rem; --sprout-board-cell-height: 24rem; --sprout-board-gap: .5rem; --sprout-board-column-bg: color-mix(in oklab, var(--sprout-hover) 40%, var(--sprout-canvas)); --sprout-board-card-border: color-mix(in oklab, var(--sprout-border) 30%, var(--sprout-line)); height: var(--sprout-board-height); box-sizing: border-box; border: 1px solid var(--sprout-line); border-radius: var(--sprout-radius-panel); background: var(--sprout-canvas); min-width: 0; color: var(--sprout-text); font-size: var(--sprout-text-sm); flex-direction: column; display: flex; overflow: hidden; } .sprout-board-toolbar { border-bottom: 1px solid var(--sprout-line); background: var(--sprout-surface); flex-wrap: wrap; align-items: center; gap: .5rem .75rem; padding: .625rem .75rem; display: flex; } .sprout-board-search { width: min(16rem, 100%); } .sprout-board-lane-by { color: var(--sprout-muted); font-size: var(--sprout-text-xs); align-items: center; gap: .5rem; display: inline-flex; } .sprout-board-status { color: var(--sprout-muted); font-size: var(--sprout-text-xs); font-variant-numeric: tabular-nums; align-items: center; gap: .25rem; margin-inline-start: auto; display: inline-flex; } .sprout-board-frame { flex: 1; min-height: 0; display: flex; position: relative; } .sprout-board-frame:before, .sprout-board-frame:after { content: ""; z-index: 3; pointer-events: none; opacity: 0; width: 2.5rem; transition: opacity var(--sprout-motion-fast) var(--sprout-motion-ease); position: absolute; top: 0; bottom: 0; } .sprout-board-frame:before { background: linear-gradient(to right, var(--sprout-canvas), transparent); left: 0; } .sprout-board-frame:after { background: linear-gradient(to left, var(--sprout-canvas), transparent); right: 0; } .sprout-board-frame[data-more-start]:before, .sprout-board-frame[data-more-end]:after { opacity: 1; } .sprout-board-viewport { overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--sprout-border) transparent; flex: 1; min-width: 0; min-height: 0; position: relative; overflow: auto; } .sprout-board-viewport:focus-visible { outline: var(--sprout-focus-width) solid var(--sprout-focus-ring); outline-offset: -1px; } .sprout-board-canvas { width: max-content; min-width: 100%; } .sprout-board-viewport:not([data-lanes]) .sprout-board-canvas { flex-direction: column; height: 100%; display: flex; } .sprout-board-header, .sprout-board-row { gap: var(--sprout-board-gap); padding-inline: .75rem; display: grid; } .sprout-board-header { z-index: 2; background: var(--sprout-canvas); padding-block: .5rem .25rem; position: sticky; top: 0; } .sprout-board-row { padding-block: .125rem .5rem; } .sprout-board-column-header { box-sizing: border-box; border-bottom: 2px solid var(--sprout-line); background: var(--sprout-canvas); align-items: center; gap: .25rem; min-width: 0; height: 2rem; padding-inline: .375rem .125rem; display: flex; } .sprout-board-column-header[data-over-limit] { border-bottom-color: var(--sprout-warning); } .sprout-board-column-header[data-dragging] { opacity: .4; } .sprout-board-column-header[data-collapsed] { flex-direction: column; height: auto; min-height: 2rem; padding-block: .25rem; } .sprout-board-column-header[data-collapsed] .sprout-board-column-title { writing-mode: vertical-rl; max-height: 9rem; } .sprout-board-column-toggle, .sprout-board-grip, .sprout-board-lane-toggle { color: var(--sprout-muted); font: inherit; cursor: pointer; border-radius: var(--sprout-radius-control); transition: background-color var(--sprout-motion-fast) var(--sprout-motion-ease); background: none; border: 0; flex-shrink: 0; align-items: center; display: inline-flex; } .sprout-board-column-toggle, .sprout-board-grip { justify-content: center; width: 1.5rem; height: 1.5rem; padding: 0; } .sprout-board-grip { cursor: grab; } .sprout-board-column-toggle svg, .sprout-board-grip svg, .sprout-board-lane-toggle svg { width: 1rem; height: 1rem; } @media (hover: hover) { .sprout-board-column-toggle:hover, .sprout-board-grip:hover, .sprout-board-lane-toggle:hover { background: var(--sprout-hover); color: var(--sprout-text); } button.sprout-board-column-title:hover { text-decoration: underline; text-decoration-color: var(--sprout-border-strong); text-underline-offset: .2em; } .sprout-board-card:hover { border-color: color-mix(in oklab, var(--sprout-border) 70%, var(--sprout-line)); } .sprout-button.sprout-board-show-all:hover { color: var(--sprout-text); } } .sprout-board-column-icon { color: var(--sprout-muted); flex-shrink: 0; display: inline-flex; } .sprout-board-column-icon svg { width: .875rem; height: .875rem; } .sprout-board-column-title { text-overflow: ellipsis; white-space: nowrap; min-width: 0; font-weight: 600; overflow: hidden; } button.sprout-board-column-title { color: inherit; font: inherit; text-align: start; cursor: text; background: none; border: 0; padding: 0; font-weight: 600; } .sprout-board-count { color: var(--sprout-muted); font-size: var(--sprout-text-xs); font-variant-numeric: tabular-nums; flex-shrink: 0; } .sprout-board-column-header[data-over-limit] .sprout-board-count { color: var(--sprout-text); font-weight: 600; } .sprout-board-limit { flex-shrink: 0; } .sprout-board-column-tools { opacity: 0; transition: opacity var(--sprout-motion-fast) var(--sprout-motion-ease); align-items: center; margin-inline-start: auto; display: inline-flex; } .sprout-board-column-header:hover .sprout-board-column-tools, .sprout-board-column-header:focus-within .sprout-board-column-tools { opacity: 1; } @media (hover: none) { .sprout-board-column-tools { opacity: 1; } .sprout-board-card-menu { opacity: 1; } .sprout-board-add { opacity: 1; } } .sprout-board-add-column { align-items: center; height: 2rem; display: flex; } .sprout-board-lanes { display: flow-root; position: relative; } .sprout-board-lane[data-pinned] { width: 100%; position: absolute; left: 0; } .sprout-board-lane-bar { border-top: 1px solid var(--sprout-line); padding: .375rem .75rem .125rem; } .sprout-board-lane[data-index="0"] .sprout-board-lane-bar { border-top: 0; } .sprout-board-lane-toggle { height: 1.5rem; color: var(--sprout-muted); font-size: var(--sprout-text-xs); gap: .375rem; padding-inline: .125rem .5rem; position: sticky; left: .75rem; } .sprout-board-lane-toggle svg { width: .875rem; height: .875rem; } .sprout-board-lane-title { color: var(--sprout-text); text-transform: uppercase; letter-spacing: .04em; font-weight: 500; } .sprout-board-cell { box-sizing: border-box; border-radius: var(--sprout-radius-control); background: var(--sprout-board-column-bg); min-width: 0; min-height: 2.5rem; transition: box-shadow var(--sprout-motion-fast) var(--sprout-motion-ease), background-color var(--sprout-motion-fast) var(--sprout-motion-ease), opacity var(--sprout-motion-fast) var(--sprout-motion-ease); flex-direction: column; gap: .125rem; padding: .25rem; display: flex; } .sprout-board-cell[data-over] { box-shadow: inset 0 0 0 1px var(--sprout-border-strong); } .sprout-board-cell[data-collapsed] { align-items: center; } .sprout-board-cell[data-drop="allowed"] { background: color-mix(in oklab, var(--sprout-primary) 8%, var(--sprout-board-column-bg)); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--sprout-primary) 40%, transparent); } .sprout-board-cell[data-drop="allowed"][data-over] { box-shadow: inset 0 0 0 2px var(--sprout-primary); } .sprout-board-cell[data-drop="blocked"] { opacity: .5; } .sprout-board-drop-text { color: var(--sprout-muted); font-size: var(--sprout-text-xs); margin: 0; padding: .25rem .5rem; } .sprout-board-single { flex: 1; min-height: 0; } .sprout-board-single > .sprout-board-row { box-sizing: border-box; height: 100%; } .sprout-board-cell[data-fill] { min-height: 0; } .sprout-board-cell-scroll { max-height: var(--sprout-board-cell-height); overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--sprout-border) transparent; overflow-y: auto; } .sprout-board-cell[data-fill] .sprout-board-cell-scroll { flex: 1; min-height: 0; max-height: none; } .sprout-board-cards { position: relative; } .sprout-board-card-slot { position: absolute; left: 0; right: 0; } .sprout-board-card { box-sizing: border-box; border: 1px solid var(--sprout-board-card-border); border-radius: var(--sprout-radius-control); background: var(--sprout-card-raised); box-shadow: var(--sprout-card-raised-shadow); touch-action: manipulation; transition: border-color var(--sprout-motion-fast) var(--sprout-motion-ease), background-color var(--sprout-motion-fast) var(--sprout-motion-ease); flex-direction: column; gap: .25rem; padding: .375rem .5rem; line-height: 1.25rem; display: flex; } .sprout-board-card[aria-roledescription="draggable card"] { cursor: grab; } .sprout-board-card[data-openable] { cursor: pointer; } .sprout-board-card:focus-visible { outline: var(--sprout-focus-width) solid var(--sprout-focus-ring); outline-offset: 1px; } .sprout-board-card[data-selected] { border-color: color-mix(in oklab, var(--sprout-text) 35%, transparent); background: color-mix(in oklab, var(--sprout-hover) 60%, var(--sprout-card-raised)); } .sprout-board-card[data-custom] { box-shadow: none; background: none; border: 0; padding: 0; display: block; } .sprout-board-card[data-custom][data-selected] { outline: 2px solid var(--sprout-primary); outline-offset: 1px; } .sprout-board-card[data-dragging] { opacity: .35; } .sprout-board-card-head { align-items: flex-start; gap: .25rem; display: flex; } .sprout-board-card-title { overflow-wrap: anywhere; flex: 1; min-width: 0; font-weight: 500; } .sprout-board-card-menu { opacity: 0; margin: -.125rem -.25rem 0 0; } .sprout-board-card:hover .sprout-board-card-menu, .sprout-board-card:focus-within .sprout-board-card-menu, .sprout-board-card-menu[data-popup-open] { opacity: 1; } .sprout-board-card-body { min-height: 1.25rem; color: var(--sprout-muted); font-size: var(--sprout-text-xs); font-variant-numeric: tabular-nums; flex-wrap: wrap; align-items: center; gap: .375rem; display: flex; } .sprout-button.sprout-board-add { justify-content: flex-start; } .sprout-board-add { color: var(--sprout-muted); opacity: 0; transition: opacity var(--sprout-motion-fast) var(--sprout-motion-ease); } .sprout-board-cell:hover .sprout-board-add, .sprout-board-add:focus-visible { opacity: 1; } .sprout-board-inline-input { width: 100%; } .sprout-board-sr-only { clip-path: inset(50%); white-space: nowrap; width: 1px; height: 1px; position: absolute; overflow: hidden; } .sprout-board-column-title[data-tone] { font-weight: 500; display: flex; } .sprout-board-column-badge { min-width: 0; max-width: 100%; } .sprout-board-column-badge > span { text-overflow: ellipsis; min-width: 0; overflow: hidden; } .sprout-board-column-notice { min-width: 0; } .sprout-board-notice { color: var(--sprout-muted); font-size: var(--sprout-text-xs); flex-wrap: wrap; align-items: center; gap: .375rem .5rem; margin: 0; padding: .375rem .375rem .5rem; line-height: 1.125rem; display: flex; } .sprout-board-notice > p { margin: 0; } .sprout-board-notice[data-kind="error"] > p { color: var(--sprout-danger); flex-basis: 100%; } .sprout-board-skeletons { flex-direction: column; gap: .25rem; display: flex; } .sprout-board-skeleton-card { border: 1px solid var(--sprout-board-card-border); border-radius: var(--sprout-radius-control); background: var(--sprout-card-raised); flex-direction: column; gap: .5rem; padding: .625rem .5rem; display: flex; } .sprout-board-skeleton-card > .sprout-skeleton { background: color-mix(in oklab, var(--sprout-muted) 22%, transparent); width: 80%; height: .75rem; } .sprout-board-skeleton-card > .sprout-skeleton:last-child { width: 40%; } .sprout-board-empty { color: var(--sprout-muted); font-size: var(--sprout-text-xs); text-align: center; margin: 0; padding: .75rem .375rem; } .sprout-button.sprout-board-show-all { color: var(--sprout-muted); font-variant-numeric: tabular-nums; flex-shrink: 0; justify-content: flex-start; } .sprout-board-foot { z-index: 2; gap: var(--sprout-board-gap); border-top: 1px solid var(--sprout-line); background: var(--sprout-canvas); padding: .25rem .75rem; display: grid; position: sticky; bottom: 0; } @media (prefers-reduced-motion: no-preference) { .sprout-board-notice, .sprout-board-empty, .sprout-board-skeletons, .sprout-board-show-all { animation: sprout-board-appear var(--sprout-motion-normal) var(--sprout-motion-ease); } } .sprout-board-overlay { cursor: grabbing; position: relative; } .sprout-board-overlay > .sprout-board-card, .sprout-board-column-header.sprout-board-overlay { box-shadow: var(--sprout-shadow-overlay); border-color: var(--sprout-border); transform: rotate(1.5deg); } .sprout-board-overlay-count { position: absolute; top: -.5rem; right: -.5rem; } @media (prefers-reduced-motion: reduce) { .sprout-board-overlay > .sprout-board-card, .sprout-board-column-header.sprout-board-overlay { transform: none; } } @keyframes sprout-board-appear { from { opacity: 0; transform: translateY(2px); } } }Import it from
@/components/ui/board. Update the paths if your@/alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/board.
Click a card to open it.
Usage
import { Board, type BoardColumn, type BoardItem } from "@tulipfarm/sprout/board";
const columns: BoardColumn[] = [
{ id: "todo", title: "To do" },
{ id: "doing", title: "In progress", limit: 3 },
{ id: "done", title: "Done" },
];
const [items, setItems] = useState<BoardItem[]>([
{ id: "1", title: "Frost alert texts", columnId: "todo", laneId: "ana" },
{ id: "2", title: "Seed order import", columnId: "doing", laneId: "ben" },
]);
<Board
columns={columns}
lanes={[{ id: "ana", title: "Ana" }, { id: "ben", title: "Ben" }]}
items={items}
onItemsChange={setItems}
onItemAdd={({ title, columnId, laneId }) => addCard(title, columnId, laneId)}
onItemOpen={(item) => openSheet(item)}
renderBody={(item) => <Badge>{item.priority}</Badge>}
searchable
/>columns:{ id, title, limit?, total?, status?, error?, tone?, icon? }[]. Overlimit, the header turns amber and says “Over limit”.iconsits before the title. See “Read-only” for the rest.lanes:{ id, title }[]. Leave it out for a plain board with no lane bars.items:{ id, columnId, laneId?, title }[]plus your own fields. Cards in a cell show in their order initems.onItemsChange: gets the whole new list after a move, a rename, or a column delete. Without it, cards do not move.onColumnsChange: gets the new columns after a reorder, rename, or delete. Without it, columns are fixed.onItemAddandonColumnAdd: show “Add card” in every cell and “Add column” after the last column. Your app makes the id.onColumnRetryandonColumnShowAll: show “Try again” on a column that failed to load, and “Show all N” on a column whosetotalis more than its loaded cards.onItemOpen,renderBody,itemActions: what a click does, the card body under the title, and the items in the card menu.renderTitleandrenderCard: change the title, or draw the whole card. See “Custom cards”.canDrag,canDrop,dropText,renamable: which cards move, where they may land, and whether titles rename. See “Move rules”.searchable,searchText,laneBy: the toolbar. Search filters by title and any text you add. “Lanes by” is a select; your app regroupslanesandlaneId.
Without lanes
With no lanes, the board is one row and the cells fill its height.
Read-only
Leave out onItemsChange and onColumnsChange for a status board. Cards and columns do not drag, rename, or select. Click or Enter still opens a card.
Each column can load on its own. total is the count from your server; the header shows it, and withonColumnShowAll the column foot offers “Show all N” when you loaded fewer cards. statusis 'loading' (skeleton cards), 'error' (a message and “Try again”, which callsonColumnRetry), or 'unavailable' (a message only). error replaces the default message. Other columns are not affected. A ready column with no cards says “No cards”. tone draws the title as a Badge of that variant.
columnText changes the column texts to your product's words:columnText={{ empty: "No rows", showAll: (total) => `Show all ${total} in table` }}. The Show all button's accessible name still ends with the column title.
With lanes, a column's message and its “Show all” appear once, under the column header and at the board foot. Skeleton cards appear in every lane of a loading column.
<Board
label="Release status"
columns={[
{ id: "backlog", title: "Backlog", tone: "secondary", total: 128 },
{ id: "review", title: "Review", tone: "warning", total: 9, status: "loading" },
{ id: "blocked", title: "Blocked", tone: "destructive", status: "error" },
{ id: "done", title: "Done", tone: "success", total: 0 },
]}
items={firstRowsOfEachColumn}
onItemOpen={(item) => openSheet(item)}
onColumnRetry={(column) => reload(column.id)}
onColumnShowAll={(column) => openTable(column.id)}
/>Click a card, Show all, or Try again.
Custom cards
renderTitle changes only the title. The playground above uses it to show a key before each title. Screen readers still readitem.title.
renderCard draws the whole card. The board removes its own frame and gives you parts.title and parts.menu. Put them where you want. They keep rename and the card menu working. The board still owns drag, focus, keys, click, and selection.
<Board
columns={columns}
items={items}
onItemsChange={setItems}
renderCard={(item, parts) => (
<div className="flex gap-3 rounded-lg border p-2">
<EntityAvatar size="sm" name={item.assignee} />
<div className="flex-1">
<div className="flex items-start gap-1">
{parts.title}
{parts.menu}
</div>
<span className="text-xs">{item.points} pt</span>
</div>
</div>
)}
/>Move rules
Use these when a move means something, such as starting work or closing a task. canDrag keeps a card in place. canDrop says where a card may land: while it is dragged, allowed cells light up and blocked cells dim. A blocked cell does not take the card, and dropping there puts it back. The card's own cell is checked too, so return false for it to stop reordering. dropText shows a line in each allowed cell, such as what the drop will do. Selected cards that may not land stay where they were.
renamable={false} keeps rename off while cards still drag, for titles your app edits elsewhere.
<Board
columns={columns}
items={items}
onItemsChange={setItems}
renamable={false}
canDrag={(item) => !item.locked}
canDrop={(item, to) => next(item.columnId) === to.columnId || to.columnId === "todo"}
dropText={(item, to) => (to.columnId === "todo" ? "Send back to start" : `Move to ${to.columnId}`)}
/>Large boards
50 columns, 20 lanes, and 10,000 cards. Only the lanes and cards in view render. The card you drag always stays rendered.
Selecting and moving many cards
When cards can move, Cmd-click or Ctrl-click adds a card to the selection. Shift-click selects a range. Drag one selected card and the rest go with it. Escape clears the selection.
Accessibility
The board is a named region. Each cell is a list named by its column and lane. Tab moves to a card. Space picks it up, arrow keys move it, Space drops it, and Escape puts it back. A screen reader hears each step with the card title and its cell, or that the card can’t move to a blocked cell. On touch, press and hold a card to pick it up; a swipe still scrolls.
Enter opens a card. F2 or Rename in the card menu renames it. With noonItemOpen, a double-click renames too. In a title field, Enter saves and Escape cancels. Columns move with their grip button in the same way. The “Over limit” state is in words, not only color.
A column header's name includes its count and state, such as “Review, 9 cards, loading”. A loading column isaria-busy and announces “Loading cards in Review…”. A load error is an alert, and its “Try again” and “Show all N” buttons name their column.
Theme tokens
Cards use --sprout-card-raised and--sprout-card-raised-shadow. Columns tint--sprout-hover over --sprout-canvas. Over limit uses --sprout-warning-subtle, and selection--sprout-primary. Set --sprout-board-height,--sprout-board-column-width, and--sprout-board-cell-height on the board to size it.