# Data table

> Rows people sort, select and scan: the shot list, the one-liner. Drawn checkboxes, sort arrows in the header, numbers right-aligned in tabular figures, stripboard colours on the one-liner.

Source: https://kwark.space/designSystem/components/data-table

## Usage

### What it is
A table for comparing many items across the same attributes. Kwark's tables are production paperwork: the **shot list**, the **one-liner** (the day's scenes in one line each), day out of days, cast and crew lists. They look like the sheets an AD would print, because they are printed.

### When to use
- The shot list, the one-liner schedule, day out of days, cast and crew lists, research databases.
- When people sort, select several rows and act on them together.

### When not to
- Fewer than four rows or two columns. Use a [Description list](https://kwark.space/designSystem/components/description-list.md).
- On a phone with more than three columns: turn rows into cards with the two key values and a ⋯ sheet.
- For one item's facts. That is a description list.

### Variants
| Variant | Use |
|---|---|
| Default | 44px rows, 13px text: the shot list |
| Dense (`--dense`) | 32px rows, the one-liner and day out of days |
| Selectable | A first column of drawn checkboxes and a tools bar that names the count |
| Sortable | Header buttons with an arrow; one sort at a time |

### Film conventions it keeps
- **Scene and shot numbers** in the accent, 600: *12A*.
- **Page counts in eighths**, right-aligned: *1 3/8*, *5/8*.
- **One-liner strips**: a 4px edge in the stripboard's paper colour (white INT DAY, yellow EXT DAY, blue INT NIGHT, green EXT NIGHT), and the words in their own column so colour is never alone.
- A **total row** in the foot: *Day 4 total · 4 6/8*.

### Writing
Header labels are short nouns in sentence case, or the AD's abbreviations where the crew uses them (*Sc*, *I/E · D/N*). The tools bar says what is selected: *2 shots selected*. Empty cells say *Not yet* or *Not set*.

**Do:** *Shot · Size · Subject · Lens · Seconds · Filmed*, numbers right-aligned, 12A in the accent, *Not yet* where nothing is filmed.

**Don't:** ALL-CAPS headers with letter spacing, centred numbers, and empty cells.

## Style

### Anatomy

1. **Wrap**: 1px `--k-line`, 10px corners, `--k-surface`; scrolls both ways inside; the head is sticky.
2. **Tools bar**: 44px, `--k-raise`, count in 13px with the number in 600, then actions as small buttons.
3. **Head**: 12px 500 `--k-text-2`, 1px rule under it; sort buttons inherit the type and show a 12px arrow, rotated for descending, faint until sorted.
4. **Rows**: 44px (dense 32px), 1px rules, 13px text; hover 3% ink; selected 8% accent with a 2px accent edge on the first cell.
5. **Checkbox** (`.kw-tick`): 18px drawn box, 1.5px border, 4px corners; checked fills `--k-text` with a surface check; `data-mixed` draws a bar.
6. **Numbers**: right-aligned, tabular.
7. **Filmed**: a 14px check in `--k-ok` with the take.
8. **Strip edge**: 4px, full row height, the stripboard paper colour with a 1px line around white.

### Tokens

| Token | Light | Dark |
|---|---|---|
| `--k-surface` | #ffffff | #1a1a1a |
| `--k-raise` | #f1f5f9 | #252525 |
| `--k-line` | #e2e8f0 | rgba(255, 255, 255, .1) |
| `--k-text` | #0f172a | #e3e3e3 |
| `--k-text-2` | #5b6779 | #9ca3af |
| `--k-accent` | #98633f | #98633f |
| `--k-ok` | #2c6e49 | #6cc08a |
| `--k-focus` | #0f172a | #f4f4f5 |
| `--k-strip-int-day` | #f5f4ee |  |
| `--k-strip-ext-day` | #f1d563 |  |
| `--k-strip-int-night` | #8fb4d6 |  |
| `--k-strip-ext-night` | #93c197 |  |
| `--k-radius-card` | 10px |  |
| `--k-fs-meta` | 12px |  |
| `--k-fs-detail` | 13px |  |

### States
| State | Look |
|---|---|
| Row hover | 3% ink |
| Row selected | 8% accent ground, 2px accent edge |
| Checkbox focus | 2px `--k-focus` outline, 2px offset |
| Some selected | Header checkbox shows a bar (`data-mixed`, and `indeterminate` set in script) |
| Sorted column | Arrow at full strength; others faint |
| Empty table | One row spanning all columns: *No shots in Scene 12 yet.* |

## Code

### React

In the Kwark app: `// pages/PreProduction/ShotListModule/ShotTable.tsx and .po-table (shared)`.

```tsx
<ShotTable rows={rows} custom={columns} canEdit={canEdit} selected={selected} onSelect={setSelected} />
```

| Prop | Type | Notes |
|---|---|---|
| `selected` | `Set<string>` |  |
| `lean` | `boolean` | dense rows |

### HTML and CSS

Works anywhere with `kwark.css`.

```html
<div class="kw-dtable">
  <div class="kw-dtable__tools" role="status"><span><b>2 shots</b> selected</span><button class="kw-button kw-button--sm" type="button">Move to setup</button><button class="kw-button kw-button--sm kw-button--quiet" type="button">Clear</button></div>
  <div class="kw-dtable__scroll" tabindex="0" role="region" aria-label="Shots in Scene 12">
  <table>
    <caption class="kw-visually-hidden">Shots in Scene 12, sorted by shot</caption>
    <thead><tr><th scope="col" class="kw-dtable__pick"><input class="kw-tick" type="checkbox" aria-label="Select all shots" data-mixed></th><th scope="col" aria-sort="ascending"><button type="button">Shot <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 19V5M6 11l6-6 6 6"/></svg></button></th><th scope="col">Size</th><th scope="col">Subject</th><th scope="col" class="num"><button type="button">Lens <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 19V5M6 11l6-6 6 6"/></svg></button></th><th scope="col" class="num">Seconds</th><th scope="col">Filmed</th></tr></thead>
    <tbody>
      <tr aria-selected="true"><td class="kw-dtable__pick"><input class="kw-tick" type="checkbox" checked aria-label="Select 12A"></td><td class="kw-dtable__key">12A</td><td>MS</td><td>Mira, from the doorway</td><td class="num">40 mm</td><td class="num">3</td><td><span class="kw-dtable__done"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>Take 3</span></td></tr>
      <tr aria-selected="true"><td class="kw-dtable__pick"><input class="kw-tick" type="checkbox" checked aria-label="Select 12B"></td><td class="kw-dtable__key">12B</td><td>CU</td><td>Insert: the monitor</td><td class="num">75 mm</td><td class="num">2</td><td class="kw-dtable__quiet">Not yet</td></tr>
      <tr><td class="kw-dtable__pick"><input class="kw-tick" type="checkbox" aria-label="Select 12C"></td><td class="kw-dtable__key">12C</td><td>OTS</td><td>Over Mira to the frame</td><td class="num">50 mm</td><td class="num">4</td><td class="kw-dtable__quiet">Not yet</td></tr>
    </tbody>
  </table>
  </div>
</div>
<div class="kw-dtable kw-dtable--dense">
  <div class="kw-dtable__scroll" tabindex="0" role="region" aria-label="One-liner, Day 4">
  <table>
    <caption>One-liner · Day 4 · Thu 21 Nov</caption>
    <thead><tr><th scope="col">Sc</th><th scope="col">Set</th><th scope="col">I/E · D/N</th><th scope="col" class="num">Pages</th><th scope="col">Cast</th></tr></thead>
    <tbody>
      <tr><td class="kw-dtable__key"><i class="kw-dtable__strip" style="--kw-strip:var(--k-strip-int-night)" aria-hidden="true"></i>12</td><td>EDIT SUITE<small>Mira finds the frame</small></td><td>INT · NIGHT</td><td class="num">1 3/8</td><td>1</td></tr>
      <tr><td class="kw-dtable__key"><i class="kw-dtable__strip" style="--kw-strip:var(--k-strip-int-day)" aria-hidden="true"></i>3</td><td>LAB CORRIDOR<small>The courier arrives</small></td><td>INT · DAY</td><td class="num">5/8</td><td>1, 2</td></tr>
      <tr><td class="kw-dtable__key"><i class="kw-dtable__strip" style="--kw-strip:var(--k-strip-ext-day)" aria-hidden="true"></i>9</td><td>STREET<small>Rain, the scooter leaves</small></td><td>EXT · DAY</td><td class="num">2 6/8</td><td>2</td></tr>
    </tbody>
    <tfoot><tr><th scope="row" colspan="3">Day 4 total</th><td class="num">4 6/8</td><td></td></tr></tfoot>
  </table>
  </div>
</div>
```

### Markup
- `<table>` with `<caption>`, `<th scope="col">` and, in the foot, `<th scope="row">`.
- Checkboxes are real inputs with `class="kw-tick"` (`appearance: none`, drawn in CSS) so keyboard and forms work.
- Set `aria-sort` on the sorted `<th>`; the arrow rotates from it.

## Accessibility

### Keyboard
| Key | Does |
|---|---|
| Tab | Header checkbox, sort buttons, then each row's checkbox and links |
| Space | Toggles the focused checkbox |
| Enter on a sort button | Sorts; announces *Sorted by lens, ascending* |
| Arrows | Scroll the table region when it has focus |

### Screen readers
- Each row checkbox is named with the row's key (*Select 12A*).
- The tools bar is a polite status: *2 shots selected*.
- Never make a whole row clickable without a real link or button inside it.

## For agents

### Rules

- **Must** use a real `<table>` with scoped headers and a caption.
- **Must** right-align numbers in tabular figures and write pages in eighths.
- **Never** use all-caps header labels or a native checkbox look; use `.kw-tick`.
- **Always** name each selection checkbox with its row.
- **Never** show stripboard colour without the I/E and D/N words beside it.

### AI readiness test

**Task:** Show the one-liner schedule for Day 4.

**Give the agent:** Data table, Stripboard strip, Call sheet.

**Constraint:** Must fit a laptop without horizontal scroll at 1280px.

**A reliable answer:**
- Dense variant
- Columns Sc, Set, I/E · D/N, Pages, Cast
- Strip edge in paper colours with the words
- Pages in eighths right-aligned
- Total row
- Caption names the day
