# Board column

One column of a board: its name and count over its rows, the rows scrolling under the head, and the strip it folds to.

Live variants: https://design.arcadia.is/components/board-column

```tsx
import {
  BoardColumn, BoardDrag, BoardDragItem, BoardDragHandle, useBoardDropTarget,
} from "@arcadia/ui";
```

## When to use

- A board column holding the cards that move between columns
- Any column that folds to a strip when it needs no room, such as a done stage

## When not to use

- A single card that stands on its own: use `Card`
- Rows that never fold and hold no cards of their own: use `ListRow`

## In context

Add a card or fold the stage. Its count stays beside the name, and its cards scroll below the header.

Add a card or collapse the column. The title and count stay visible.

```tsx
import { useState } from "react";
import { BoardColumn, Chip, IconButton } from "@arcadia/ui";

function Column() {
  const [collapsed, setCollapsed] = useState(false);
  const [added, setAdded] = useState(0);
  return (
    <div {...stylex.props(styles.row, styles.board)}>
      <BoardColumn
        title="In progress"
        count={8 + added}
        collapsed={collapsed}
        onCollapsedChange={setCollapsed}
        collapseLabel="Collapse In progress"
        actions={<IconButton icon="plus" label="New card" size="sm" onClick={() => setAdded((n) => n + 1)} />}
        rootStyle={styles.column}
      >
        {Array.from({ length: added }, (_, at) => <TaskCard key={at} title="Untitled card" meta="You" />)}
        <TaskCard title="Move the upload test" meta="Maya"><Chip size="md" tone="warning">High</Chip></TaskCard>
        <TaskCard title="Write the release notes" meta="Sam"><Chip size="md">Feature</Chip></TaskCard>
        <TaskCard title="Pin the fixture server port" meta="Nora"><Chip size="md">Design</Chip></TaskCard>
        <TaskCard title="Retry the flaky upload" meta="Maya" />
        <TaskCard title="Move the icons page to the new grid" meta="Sam" />
        <TaskCard title="Check the board at 390 wide" meta="Nora" />
        <TaskCard title="Name the done stage in the guide" meta="Maya" />
        <TaskCard title="Time the cold check" meta="Sam" />
      </BoardColumn>
      <BoardColumn title="Done" count={12} collapsed />
    </div>
  );
}
```

## Usage

```tsx
import {
  BoardColumn, Card, CardHeader, CardTitle, IconButton,
} from "@arcadia/ui";

<BoardColumn title="In progress" count={3} actions={<IconButton icon="plus" label="New card" />}>
  <Card>
    <CardHeader><CardTitle>Move the upload test to the staging runner</CardTitle></CardHeader>
  </Card>
</BoardColumn>
```

Give it a `title`, the `count` it holds, and the controls that act on it in `actions`. Its rows are `Card`s, one per card, in the order they sit, and a column never frames or restyles them. Set `collapsed` to draw it as a strip with its title turned upright and its count under it; `onCollapsedChange` gives the head a control that folds it and makes the strip the control that opens it again. The column fills the height its board gives it, so the rows scroll inside it.

## Examples

### Collapsed

The strip is the whole control: a press anywhere on it asks for the column back, and the head's control folds it again. `collapseLabel` names that control with the column's name in it (Collapse Done).

```tsx
import { useState } from "react";
import { BoardColumn } from "@arcadia/ui";

function Strip() {
  const [collapsed, setCollapsed] = useState(true);
  return (
    <div {...stylex.props(styles.row)}>
      <BoardColumn title="Done" count={12} fit collapsed={collapsed} onCollapsedChange={setCollapsed} collapseLabel="Collapse Done">
        <TaskCard title="Ship the board column" meta="Today" />
      </BoardColumn>
    </div>
  );
}
```

### Fit to its cards

`fit` sizes the column to its cards instead of the board: as wide as its widest card, at most `--board-column-w`, and as tall as its cards, at most the height the board gives it, scrolling past that. Default false: `--board-column-w` wide and the board's height.

```tsx
import { BoardColumn } from "@arcadia/ui";

<div {...stylex.props(styles.row)}>
  <BoardColumn title="Review" count={2} fit>
    <TaskCard title="Write the release notes" meta="Sam" />
    <TaskCard title="Pin the fixture server port" meta="Nora" />
  </BoardColumn>
</div>
```

### A long title

A title that wraps keeps the count and the actions on its first line, so the head grows downward and the controls stay where a one-line head puts them.

```tsx
import { useState } from "react";
import { BoardColumn } from "@arcadia/ui";

function Wrapped() {
  const [collapsed, setCollapsed] = useState(false);
  return (
    <div {...stylex.props(styles.row)}>
      <BoardColumn fit title="Waiting on the security review of the new sign-in flow" count={1}
        collapsed={collapsed} onCollapsedChange={setCollapsed} collapseLabel="Collapse security review">
        <TaskCard title="Write the release notes" meta="Sam" />
      </BoardColumn>
    </div>
  );
}
```

### Carried cards

Hover a card or Tab to its grip to reveal it. On touch, the grip stays visible. Drag it to move the card, or press Space or Enter to pick it up, use the arrows to move and press Space or Enter to drop. While you drag, a raised preview follows the pointer. The dashed slot shows where the card will land.

```tsx
import { useState } from "react";
import {
  BoardColumn, BoardDrag, BoardDragHandle, BoardDragItem, Card, CardHeader,
  CardTitle,
} from "@arcadia/ui";

function Carried() {
  const [columns, setColumns] = useState<readonly BoardDragColumn[]>([
    { id: "now", label: "Now", cards: [
      { id: "notes", label: "Notes" },
      { id: "icons", label: "Icons" },
      { id: "upload", label: "Uploads" },
    ] },
    { id: "done", label: "Done", cards: [] },
  ]);

  return (
    <BoardDrag columns={columns} onMove={({ id, from, to }) => {
      const card = columns.find((column) => column.id === from.column)?.cards[from.index];
      if (!card) return;
      setColumns(columns.map((column) => {
        const cards = column.cards.filter((entry) => entry.id !== id);
        if (column.id === to.column) cards.splice(to.index, 0, card);
        return { ...column, cards };
      }));
    }}>
      <div {...stylex.props(styles.row, styles.carried)}>
        {columns.map((column) => (
          <BoardColumn key={column.id} dropId={column.id} title={column.label} count={column.cards.length} rootStyle={styles.dragColumn}>
            {column.cards.map((card) => (
              <BoardDragItem key={card.id} id={card.id}>
                <Card>
                  <CardHeader><CardTitle rootStyle={styles.dragTitle}>{card.label}</CardTitle></CardHeader>
                </Card>
                <div {...stylex.props(styles.grip)}><BoardDragHandle /></div>
              </BoardDragItem>
            ))}
          </BoardColumn>
        ))}
      </div>
    </BoardDrag>
  );
}
```

Give `BoardDrag` the columns in keyboard order and each column’s cards in display order, with card IDs unique across the board. Match `dropId` to the column ID. For a custom column, spread `dropProps` from `useBoardDropTarget(id)` on its drop region and render `dropSlot` inside its card list for empty drops. For an ordered or unordered list, pass `"li"` as the second argument. Apply `onMove` in one update. The destination index excludes the moved card.

## Customising

`rootStyle` takes where the column sits and these knobs; the head and the rows read the inset and the gap, so a board styles its columns together.

- `--board-column-w` (`Ref<Space> | `calc(${Ref<Space>} * ${number})``, default `calc(var(--space-16) * 4.25)`): The open column's width.
- `--board-column-strip-w` (`Ref<Space>`, default `var(--space-12)`): The collapsed strip's width.
- `--board-column-px` (`Ref<Space>`, default `var(--space-2)`): The inline inset of its head and its rows.
- `--board-column-gap` (`Ref<Space>`, default `var(--space-2)`): The gap between its rows.

## Accessibility

The column is a `section` named by its title, and the title is an `h2`. Collapsed, the strip is one button whose words are the title and the count, with `aria-expanded` false, and the section keeps that name. Its rows keep their own focus stops, and the strip draws the ring inside its edge. A person who folds the column from the head keeps their place on the strip, and a press on the strip returns them to the head's control.

The grip keeps focus while carrying a card. It regains focus after a keyboard drop, and the board announces the destination and position.

- Tab: Moves through the controls in the head and the cards
- Space or Enter: On a grip, picks up or drops its card. On a column control, folds or expands the column
- Up or Down: Changes the insertion position while carrying a card
- Left or Right: Moves to the next column in that direction
- Escape: Cancels the move and leaves the card where it started

## API reference

### BoardColumn

- `title` (`ReactNode`, required): The column's name, in its head: words, or a name edited where it stands. Collapsed, it is the strip's own text.
- `count` (`ReactNode`): How many it holds, after the name: a count, a "12+" where more are held.
- `actions` (`ReactNode`): Controls at the head's end: add a card, its menu. The control that collapses the column stands before them.
- `collapsed` (`boolean`, default `false`): Drawn as a narrow strip, its title and count turned upright, in place of the column.
- `onCollapsedChange` (`(collapsed: boolean) => void`): Called with the new state from the head's control, or by a press on the strip. Without it the column cannot be collapsed and the strip is still text.
- `collapseLabel` (`string`, default `"Collapse column"`): The head's control's name, with the column's name in it ("Collapse In progress").
- `fit` (`boolean`, default `false`): The column takes the size of its cards instead of the board's: as wide as its widest card, at most `--board-column-w`, and as tall as its cards, at most the height its board gives it, scrolling past that. Default false: the column is `--board-column-w` wide and fills its board's height.
- `dropId` (`string`): The column ID registered with BoardDrag. A collapsed column does not accept drops.
- `rootStyle` (`BoardColumnStyle`): Typed StyleX override: where it sits and its `--board-column-*` knobs.
- `children` (`ReactNode`): Its rows: a `Card` each, in the order they sit.

Rest props go to `<section>` props.

### BoardDrag

- `columns` (`readonly BoardDragColumn[]`, required)
- `onMove` (`(move: BoardDragMove) => void`, required): Apply the move in one update. The destination index counts cards after the source card is taken out.

### BoardDragItem

- `id` (`string`, required)
- `as` (`"div" | "li"`)
