# Filter Table

A table with filter chips above it that narrow its rows in place.

A table with chips above it that filter its rows in place: support tickets by status, issues by priority, deploys by environment. Its columns, rows and chips come from props (without them it is a task table: task, date, status, owner). A status column shows each row's StatusPill, a tag column (labels people assign, such as environments) each row's Tag. The chips are a segmented-control with the chips variant (one Zag radio-group, through Ark UI in React, Vue and Svelte), so they are a single tab stop and the arrow keys move and select. Rows that leave collapse with the reveal recipe while they fade, so the rows below close the gap in the same motion.

Kind: block · Category: Data · Status: beta · Targets: React, Vue, Svelte · Behaviour: Zag `radio-group` machine, through Ark UI

## Add

```bash
npx fndn add filter-table
```

It writes the folder `filter-table/` into the project's ui folder (`index.ts`, `filter-table.tsx`, `FilterTable.vue`, `FilterTable.svelte`, `filter-table.recipe.ts`), and what it is built from: [Segmented Control](/components/segmented-control.md), [Status Pill](/components/status-pill.md), [Tag](/components/tag.md), [Empty State](/components/empty-state.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { FilterTable } from "@/components/ui/filter-table";
```

```vue
import { FilterTable } from "@/components/ui/filter-table";
```

```svelte
import { FilterTable } from "$lib/components/ui/filter-table";
```

## Parts

In the DOM the root carries `data-slot="filter-table"` and each part `data-slot="filter-table-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `filter-table` |  | max-width 420 |
| `filters` | `div` | `filter-table-filters` |  | The real SegmentedControl, variant chips, marked data-filter-table="filters": one radio group, a sliding thumb, each option label holds its filter's dot (its tone) and a count |
| `card` | `div` | `filter-table-card` |  | role=region, focusable; scrolls sideways when the table is wider than the card; edge veils (::before / ::after, sticky) fade the side the table continues past, each shown while there is more on its side (data-overflow-start, data-overflow-end, kept in step with the scroll position by lib/veil.ts) |
| `table` | `div` | `filter-table-table` |  | role=table; at least --fndn-filter-min wide (105px a column, 420px at least); the head and every row lay their cells on --fndn-filter-cols (each column's share of the width) |
| `head` | `div` | `filter-table-head` |  | role=row |
| `th` | `span` | `filter-table-th` | repeats | role=columnheader; a number column's header at the end |
| `row` | `div` | `filter-table-row` | repeats | Reveal wrapper; shown (the row matches the filter) is a recipe variant; kbd-instant (the shared keyboard-instant flag) |
| `cells` | `div` | `filter-table-cells` |  | role=row |
| `cell` | `span` | `filter-table-cell` | repeats | role=cell; its column's type (title\|text\|date\|number\|status\|tag) is a recipe variant. title: 500 ink; title and text are cut at the end with the full value in title; date and number stay whole (tabular; number at the end); a status cell is at least 40px tall, the height a tag row has, so rows do not change height with the column type |
| `status` | `span` | `filter-table-status` | optional | A status column's cell content (to do, failed, live): the real StatusPill size sm, marked data-filter-table="status", with the label of the filter its value matches; that filter's tone is the pill's tone when it is green, orange, red or blue, and a neutral pill's dotTone for purple, cyan, yellow and pink (a neutral pill and the raw value when no filter matches) |
| `tag` | `span` | `filter-table-tag` | optional | A tag column's cell content, for labels people assign (an environment, a category): the real Tag, marked data-filter-table="tag", in the label and tone of the filter its value matches (neutral and the raw value when none does) |
| `empty` | `div` | `filter-table-empty` |  | The real EmptyState, marked data-filter-table="empty": a centred row shown only while no row matches, or a block when there are no rows |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `columns` | `{ key: string; label: string; type: title\|text\|date\|number\|status\|tag (default text; status: a StatusPill, for a state; tag: a Tag, for a label people assign); width: number? (a share of the width, fr; default by type: title 1.3, status and tag 0.95, text 0.9, number 0.8, date 0.6) }[]` |  | The columns in order. Without them: task (title), date, status, owner (text), named by labels.columns. The shares reach the table as --fndn-filter-cols (set through filter-table.logic.ts). |
| `rows` | `{ [column key]: string \| number }[]` |  | One object per row, values by column key. |
| `filters` | `{ key: string ("all" matches every row); label: string; tone?: blue\|green\|orange\|red\|purple\|cyan\|yellow\|pink; count: number? (derived from the rows otherwise) }[]` |  | The chips. A row matches a chip when its filterKey field equals the chip's key. Without them: All, To do (orange), In Progress (blue), Completed (green), named by labels.statuses, for the values todo, progress, done. |
| `filterKey` | `string` | `"status"` | The row field the chips match. |
| `filter` | `string` | `"all"` | Bindable (React: `defaultFilter` and `onFilterChange`; Vue: `v-model:filter`; Svelte: `bind:filter`). The selected chip |
| `labels` | `object` |  | { filters, region, empty, none, columns: { task, date, status, owner } (built-in columns), statuses: { todo, progress, done } (built-in chips) } |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `change` | (filter) |

## States

`hover`, `press`, `focus-visible`, `checked`, `disabled`, `row-hover`, `row-hidden`, `empty`

## Keyboard and accessibility

Role: radiogroup + table.

Keyboard:

- Tab reaches the chip group once (the selected chip), then the table region
- ArrowRight / ArrowDown and ArrowLeft / ArrowUp move to the next / previous chip and select it
- Home / End select the first / last chip
- Space selects the focused chip
- The table region is focusable; ArrowLeft / ArrowRight scroll it when it overflows

Notes:

- The chips are the segmented control's radio group, labelled by labels.filters; each radio is named by its chip text and count.
- The table is role=table with row / columnheader / cell; rows that do not match are visibility: hidden, so they leave the accessibility tree.
- Filtering from the keyboard is instant (the rows carry kbd-instant).

## Motion

- chips: the segmented control's (variant chips): one thumb slides between chips at duration.move easing.move, colour on hover, press scale; instant from the keyboard
- row leave / return: grid-template-rows over duration.reveal easing.out-strong with opacity over duration.base; a leaving row gives its space back while it fades, so the rows below close the gap in one motion; no stagger
- keyboard selection: instant (kbd-instant)
- row hover: instant both ways (the tables' one hover)
- edge veils: when the table is cut by the card, the side it continues past fades into the surface; each veil shows at once while there is more on its side (data-overflow-start, data-overflow-end, set from the scroll position by lib/veil.ts, the same in every browser; no animation, never timed); nothing when the table fits, also after a scrolled card grows to fit

## Tokens

`color.surface`, `color.ink`, `color.ink-2`, `color.line`, `color.hover`, `color.accent`, `shadow.card`, `radius.card`, `text.sm`, `easing.out-strong`, `duration.fast`, `duration.base`, `duration.reveal`

## Dependencies

- [Segmented Control](/components/segmented-control.md)
- [Status Pill](/components/status-pill.md)
- [Tag](/components/tag.md)
- [Empty State](/components/empty-state.md)

## Notes

- A status is a StatusPill and a label people assign is a Tag: a column of states (to do, failed, live) is type status, a column of labels (environments, categories) is type tag.
- The chips' hues are the tag hues. In a status column green, orange, red and blue are the pill's own tones and the other hues a neutral pill with a dot of that hue, so give statuses those four; in a tag column every hue is the Tag's tone. A filter without a tone has no dot and its rows' pills or tags are neutral.

## Examples

### Support tickets by status

React · `default.tsx`

```tsx
import type { ComponentProps } from "react";
import { FilterTable } from "@/components/ui/filter-table";

type Props = ComponentProps<typeof FilterTable>;

const rows: Props["rows"] = [
  {
    task: "Reminder SMS sent twice for the same booking",
    date: "Nov 16",
    status: "todo",
    owner: "Brightline Dental",
  },
  {
    task: "Calendar sync stopped after Google re-auth",
    date: "Nov 15",
    status: "progress",
    owner: "Kestrel Logistics",
  },
  {
    task: "Can't export invoices as CSV",
    date: "Nov 14",
    status: "todo",
    owner: "Juniper Health",
  },
  {
    task: "Add a second location to our plan",
    date: "Nov 12",
    status: "progress",
    owner: "Saint Aldric Pediatric Dental Group",
  },
  {
    task: "Booking page shows the wrong time zone",
    date: "Nov 10",
    status: "done",
    owner: "Orbit Studio",
  },
];

const labels: Props["labels"] = {
  filters: "Filter tickets by status",
  region: "Support tickets",
  empty: "No tickets with this status",
  none: "No tickets yet",
  columns: { task: "Ticket", owner: "Customer" },
  statuses: { todo: "Open", progress: "Pending", done: "Solved" },
};

export default function SupportTickets() {
  return <FilterTable rows={rows} labels={labels} />;
}
```

Vue · `default.vue`

```vue
<script setup lang="ts">
import { FilterTable } from "@/components/ui/filter-table";

const rows = [
  {
    task: "Reminder SMS sent twice for the same booking",
    date: "Nov 16",
    status: "todo",
    owner: "Brightline Dental",
  },
  {
    task: "Calendar sync stopped after Google re-auth",
    date: "Nov 15",
    status: "progress",
    owner: "Kestrel Logistics",
  },
  {
    task: "Can't export invoices as CSV",
    date: "Nov 14",
    status: "todo",
    owner: "Juniper Health",
  },
  {
    task: "Add a second location to our plan",
    date: "Nov 12",
    status: "progress",
    owner: "Saint Aldric Pediatric Dental Group",
  },
  {
    task: "Booking page shows the wrong time zone",
    date: "Nov 10",
    status: "done",
    owner: "Orbit Studio",
  },
];

const labels = {
  filters: "Filter tickets by status",
  region: "Support tickets",
  empty: "No tickets with this status",
  none: "No tickets yet",
  columns: { task: "Ticket", owner: "Customer" },
  statuses: { todo: "Open", progress: "Pending", done: "Solved" },
};
</script>

<template>
  <FilterTable :rows="rows" :labels="labels" />
</template>
```

Svelte · `default.svelte`

```svelte
<script lang="ts">
  import { FilterTable } from "$lib/components/ui/filter-table";

  const rows = [
    {
      task: "Reminder SMS sent twice for the same booking",
      date: "Nov 16",
      status: "todo",
      owner: "Brightline Dental",
    },
    {
      task: "Calendar sync stopped after Google re-auth",
      date: "Nov 15",
      status: "progress",
      owner: "Kestrel Logistics",
    },
    {
      task: "Can't export invoices as CSV",
      date: "Nov 14",
      status: "todo",
      owner: "Juniper Health",
    },
    {
      task: "Add a second location to our plan",
      date: "Nov 12",
      status: "progress",
      owner: "Saint Aldric Pediatric Dental Group",
    },
    {
      task: "Booking page shows the wrong time zone",
      date: "Nov 10",
      status: "done",
      owner: "Orbit Studio",
    },
  ];

  const labels = {
    filters: "Filter tickets by status",
    region: "Support tickets",
    empty: "No tickets with this status",
    none: "No tickets yet",
    columns: { task: "Ticket", owner: "Customer" },
    statuses: { todo: "Open", progress: "Pending", done: "Solved" },
  };
</script>

<FilterTable rows={rows} labels={labels} />
```

### Deploys by environment (your own columns)

React · `deploys-by-environment.tsx`

```tsx
import { FilterTable, type FilterTableColumn, type FilterTableFilter } from "@/components/ui/filter-table";

const columns: FilterTableColumn[] = [
  { key: "commit", label: "Commit", type: "title" },
  { key: "env", label: "Environment", type: "tag" },
  { key: "author", label: "Author", type: "text" },
  { key: "duration", label: "Duration", type: "number" },
];

/* the chips match the env field; an environment is a label, not a status, so the column is a tag column and each chip's tone colours its dot and the rows' tags */
const filters: FilterTableFilter[] = [
  { key: "all", label: "All" },
  { key: "production", label: "Production", tone: "green" },
  { key: "staging", label: "Staging", tone: "orange" },
  { key: "preview", label: "Preview", tone: "blue" },
];

const rows = [
  { commit: "a1b2c3d Add retry to webhook delivery", env: "production", author: "Priya Raman", duration: "50s" },
  { commit: "9f8e7d6 Usage alerts behind a flag", env: "staging", author: "Daniel Okafor", duration: "1m 12s" },
  { commit: "4c5d6e7 Preview of the new billing page", env: "preview", author: "Aiko Tanaka", duration: "48s" },
  { commit: "0a9b8c7 Fix tax rounding", env: "production", author: "Jonas Weber", duration: "41s" },
];

const labels = { filters: "Filter deploys by environment", region: "Deploys of web-app", empty: "No deploys in this environment", none: "No deploys yet" };

export default function DeploysByEnvironment() {
  return <FilterTable className="max-w-[520px]" columns={columns} filters={filters} filterKey="env" rows={rows} labels={labels} />;
}
```

Vue · `deploys-by-environment.vue`

```vue
<script setup lang="ts">
import { FilterTable, type FilterTableColumn, type FilterTableFilter } from "@/components/ui/filter-table";

const columns: FilterTableColumn[] = [
  { key: "commit", label: "Commit", type: "title" },
  { key: "env", label: "Environment", type: "tag" },
  { key: "author", label: "Author", type: "text" },
  { key: "duration", label: "Duration", type: "number" },
];

/* the chips match the env field; an environment is a label, not a status, so the column is a tag column and each chip's tone colours its dot and the rows' tags */
const filters: FilterTableFilter[] = [
  { key: "all", label: "All" },
  { key: "production", label: "Production", tone: "green" },
  { key: "staging", label: "Staging", tone: "orange" },
  { key: "preview", label: "Preview", tone: "blue" },
];

const rows = [
  { commit: "a1b2c3d Add retry to webhook delivery", env: "production", author: "Priya Raman", duration: "50s" },
  { commit: "9f8e7d6 Usage alerts behind a flag", env: "staging", author: "Daniel Okafor", duration: "1m 12s" },
  { commit: "4c5d6e7 Preview of the new billing page", env: "preview", author: "Aiko Tanaka", duration: "48s" },
  { commit: "0a9b8c7 Fix tax rounding", env: "production", author: "Jonas Weber", duration: "41s" },
];

const labels = { filters: "Filter deploys by environment", region: "Deploys of web-app", empty: "No deploys in this environment", none: "No deploys yet" };
</script>

<template>
  <FilterTable class="max-w-[520px]" :columns="columns" :filters="filters" filter-key="env" :rows="rows" :labels="labels" />
</template>
```

Svelte · `deploys-by-environment.svelte`

```svelte
<script lang="ts">
  import { FilterTable, type FilterTableColumn, type FilterTableFilter } from "$lib/components/ui/filter-table";

  const columns: FilterTableColumn[] = [
    { key: "commit", label: "Commit", type: "title" },
    { key: "env", label: "Environment", type: "tag" },
    { key: "author", label: "Author", type: "text" },
    { key: "duration", label: "Duration", type: "number" },
  ];

  /* the chips match the env field; an environment is a label, not a status, so the column is a tag column and each chip's tone colours its dot and the rows' tags */
  const filters: FilterTableFilter[] = [
    { key: "all", label: "All" },
    { key: "production", label: "Production", tone: "green" },
    { key: "staging", label: "Staging", tone: "orange" },
    { key: "preview", label: "Preview", tone: "blue" },
  ];

  const rows = [
    { commit: "a1b2c3d Add retry to webhook delivery", env: "production", author: "Priya Raman", duration: "50s" },
    { commit: "9f8e7d6 Usage alerts behind a flag", env: "staging", author: "Daniel Okafor", duration: "1m 12s" },
    { commit: "4c5d6e7 Preview of the new billing page", env: "preview", author: "Aiko Tanaka", duration: "48s" },
    { commit: "0a9b8c7 Fix tax rounding", env: "production", author: "Jonas Weber", duration: "41s" },
  ];

  const labels = { filters: "Filter deploys by environment", region: "Deploys of web-app", empty: "No deploys in this environment", none: "No deploys yet" };
</script>

<FilterTable class="max-w-[520px]" {columns} {filters} filterKey="env" {rows} {labels} />
```

### Triage starts on open tickets

React · `open-queue.tsx`

```tsx
import type { ComponentProps } from "react";
import { FilterTable } from "@/components/ui/filter-table";

type Props = ComponentProps<typeof FilterTable>;

const rows: Props["rows"] = [
  {
    task: "Reminder SMS sent twice for the same booking",
    date: "Nov 16",
    status: "todo",
    owner: "Brightline Dental",
  },
  {
    task: "Calendar sync stopped after Google re-auth",
    date: "Nov 15",
    status: "progress",
    owner: "Kestrel Logistics",
  },
  {
    task: "Can't export invoices as CSV",
    date: "Nov 14",
    status: "todo",
    owner: "Juniper Health",
  },
  {
    task: "Add a second location to our plan",
    date: "Nov 12",
    status: "progress",
    owner: "Saint Aldric Pediatric Dental Group",
  },
  {
    task: "Booking page shows the wrong time zone",
    date: "Nov 10",
    status: "done",
    owner: "Orbit Studio",
  },
];

const labels: Props["labels"] = {
  filters: "Filter tickets by status",
  region: "Support tickets",
  empty: "No tickets with this status",
  none: "No tickets yet",
  columns: { task: "Ticket", owner: "Customer" },
  statuses: { todo: "Open", progress: "Pending", done: "Solved" },
};

export default function OpenQueue() {
  return <FilterTable rows={rows} labels={labels} defaultFilter="todo" />;
}
```

Vue · `open-queue.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { FilterTable } from "@/components/ui/filter-table";

const rows = [
  {
    task: "Reminder SMS sent twice for the same booking",
    date: "Nov 16",
    status: "todo",
    owner: "Brightline Dental",
  },
  {
    task: "Calendar sync stopped after Google re-auth",
    date: "Nov 15",
    status: "progress",
    owner: "Kestrel Logistics",
  },
  {
    task: "Can't export invoices as CSV",
    date: "Nov 14",
    status: "todo",
    owner: "Juniper Health",
  },
  {
    task: "Add a second location to our plan",
    date: "Nov 12",
    status: "progress",
    owner: "Saint Aldric Pediatric Dental Group",
  },
  {
    task: "Booking page shows the wrong time zone",
    date: "Nov 10",
    status: "done",
    owner: "Orbit Studio",
  },
];

const labels = {
  filters: "Filter tickets by status",
  region: "Support tickets",
  empty: "No tickets with this status",
  none: "No tickets yet",
  columns: { task: "Ticket", owner: "Customer" },
  statuses: { todo: "Open", progress: "Pending", done: "Solved" },
};

const filter = ref("todo");
</script>

<template>
  <FilterTable :rows="rows" :labels="labels" v-model:filter="filter" />
</template>
```

Svelte · `open-queue.svelte`

```svelte
<script lang="ts">
  import { FilterTable } from "$lib/components/ui/filter-table";

  const rows = [
    {
      task: "Reminder SMS sent twice for the same booking",
      date: "Nov 16",
      status: "todo",
      owner: "Brightline Dental",
    },
    {
      task: "Calendar sync stopped after Google re-auth",
      date: "Nov 15",
      status: "progress",
      owner: "Kestrel Logistics",
    },
    {
      task: "Can't export invoices as CSV",
      date: "Nov 14",
      status: "todo",
      owner: "Juniper Health",
    },
    {
      task: "Add a second location to our plan",
      date: "Nov 12",
      status: "progress",
      owner: "Saint Aldric Pediatric Dental Group",
    },
    {
      task: "Booking page shows the wrong time zone",
      date: "Nov 10",
      status: "done",
      owner: "Orbit Studio",
    },
  ];

  const labels = {
    filters: "Filter tickets by status",
    region: "Support tickets",
    empty: "No tickets with this status",
    none: "No tickets yet",
    columns: { task: "Ticket", owner: "Customer" },
    statuses: { todo: "Open", progress: "Pending", done: "Solved" },
  };

  let filter = $state("todo");
</script>

<FilterTable rows={rows} labels={labels} bind:filter={filter} />
```

### Nothing solved yet this week

React · `nothing-solved.tsx`

```tsx
import type { ComponentProps } from "react";
import { FilterTable } from "@/components/ui/filter-table";

type Props = ComponentProps<typeof FilterTable>;

const rows: Props["rows"] = [
  {
    task: "Reminder SMS sent twice for the same booking",
    date: "Nov 16",
    status: "todo",
    owner: "Brightline Dental",
  },
  {
    task: "Calendar sync stopped after Google re-auth",
    date: "Nov 15",
    status: "progress",
    owner: "Kestrel Logistics",
  },
  {
    task: "Can't export invoices as CSV",
    date: "Nov 14",
    status: "todo",
    owner: "Juniper Health",
  },
];

const labels: Props["labels"] = {
  filters: "Filter tickets by status",
  region: "Support tickets",
  empty: "Nothing solved yet this week",
  none: "No tickets yet",
  columns: { task: "Ticket", owner: "Customer" },
  statuses: { todo: "Open", progress: "Pending", done: "Solved" },
};

export default function NothingSolved() {
  return <FilterTable rows={rows} labels={labels} defaultFilter="done" />;
}
```

Vue · `nothing-solved.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { FilterTable } from "@/components/ui/filter-table";

const rows = [
  {
    task: "Reminder SMS sent twice for the same booking",
    date: "Nov 16",
    status: "todo",
    owner: "Brightline Dental",
  },
  {
    task: "Calendar sync stopped after Google re-auth",
    date: "Nov 15",
    status: "progress",
    owner: "Kestrel Logistics",
  },
  {
    task: "Can't export invoices as CSV",
    date: "Nov 14",
    status: "todo",
    owner: "Juniper Health",
  },
];

const labels = {
  filters: "Filter tickets by status",
  region: "Support tickets",
  empty: "Nothing solved yet this week",
  none: "No tickets yet",
  columns: { task: "Ticket", owner: "Customer" },
  statuses: { todo: "Open", progress: "Pending", done: "Solved" },
};

const filter = ref("done");
</script>

<template>
  <FilterTable :rows="rows" :labels="labels" v-model:filter="filter" />
</template>
```

Svelte · `nothing-solved.svelte`

```svelte
<script lang="ts">
  import { FilterTable } from "$lib/components/ui/filter-table";

  const rows = [
    {
      task: "Reminder SMS sent twice for the same booking",
      date: "Nov 16",
      status: "todo",
      owner: "Brightline Dental",
    },
    {
      task: "Calendar sync stopped after Google re-auth",
      date: "Nov 15",
      status: "progress",
      owner: "Kestrel Logistics",
    },
    {
      task: "Can't export invoices as CSV",
      date: "Nov 14",
      status: "todo",
      owner: "Juniper Health",
    },
  ];

  const labels = {
    filters: "Filter tickets by status",
    region: "Support tickets",
    empty: "Nothing solved yet this week",
    none: "No tickets yet",
    columns: { task: "Ticket", owner: "Customer" },
    statuses: { todo: "Open", progress: "Pending", done: "Solved" },
  };

  let filter = $state("done");
</script>

<FilterTable rows={rows} labels={labels} bind:filter={filter} />
```

### A queue with no tickets

React · `no-tickets.tsx`

```tsx
import type { ComponentProps } from "react";
import { FilterTable } from "@/components/ui/filter-table";

type Props = ComponentProps<typeof FilterTable>;

const labels: Props["labels"] = {
  filters: "Filter tickets by status",
  region: "Support tickets",
  empty: "No tickets with this status",
  none: "No tickets yet. New requests from customers land here.",
  columns: { task: "Ticket", owner: "Customer" },
  statuses: { todo: "Open", progress: "Pending", done: "Solved" },
};

export default function NoTickets() {
  return <FilterTable rows={[]} labels={labels} />;
}
```

Vue · `no-tickets.vue`

```vue
<script setup lang="ts">
import { FilterTable } from "@/components/ui/filter-table";

const labels = {
  filters: "Filter tickets by status",
  region: "Support tickets",
  empty: "No tickets with this status",
  none: "No tickets yet. New requests from customers land here.",
  columns: { task: "Ticket", owner: "Customer" },
  statuses: { todo: "Open", progress: "Pending", done: "Solved" },
};
</script>

<template>
  <FilterTable :rows="[]" :labels="labels" />
</template>
```

Svelte · `no-tickets.svelte`

```svelte
<script lang="ts">
  import { FilterTable } from "$lib/components/ui/filter-table";

  const labels = {
    filters: "Filter tickets by status",
    region: "Support tickets",
    empty: "No tickets with this status",
    none: "No tickets yet. New requests from customers land here.",
    columns: { task: "Ticket", owner: "Customer" },
    statuses: { todo: "Open", progress: "Pending", done: "Solved" },
  };
</script>

<FilterTable rows={[]} labels={labels} />
```

## Recipe

`filter-table.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* filter-table — chips that directly filter a table. Its columns, rows and chips come from props
 * (filter-table.logic.ts); without them it is the built-in task table. The grid of the head and of
 * every row is --fndn-filter-cols (each column's share, set by the adapter from the columns), and the
 * table is at least --fndn-filter-min wide (105px a column, 420 at least). A column's type sets its
 * look: title, text, date, number, status, tag.
 * The chips are the real SegmentedControl (variant chips: one radio group, a sliding thumb, a
 * status dot and a count in each label), so they are a single tab stop and the arrow keys move
 * and select; `filters` is passed to it as className. A status cell is the real StatusPill (sm),
 * a tag cell the real Tag; "nothing matches" is the real EmptyState (`empty`, as className). The
 * built-in statuses are pill tones (to do: orange, in progress: blue, completed: green).
 *
 * The table card scrolls sideways when the table is wider than the card: a one-column grid as wide
 * as the table (at least the card), so the edge veils can share the table's area.
 *
 * Motion (`docs motion`):
 *   rows     a row that leaves gives its space back while it fades (grid rows 1fr → 0fr at
 *            duration.reveal easing.out-strong, opacity at duration.base, visibility at the end), so
 *            the rows below close the gap in the same motion; rows that return do the reverse. No
 *            stagger: the table is refiltered constantly. From the keyboard it is instant
 *            (kbd-instant). Not a disclosure, so it is not the collapsible.
 *   hover    a row's fill, instant both ways (as the other tables)
 * Parts rendered by other components are marked data-filter-table="filters|status|tag|empty". */

/* the grid lines: --_grid-line, set on the root */
export const filterTable = tv({
  slots: {
    base: "[--_grid-line:var(--fndn-line)] w-full max-w-[420px] min-w-0",
    /* on the SegmentedControl: the chip row reaches 4px past the card on each side, so its padding
     * (which keeps the focus ring and the thumb's shadow inside the scroller) does not indent the
     * first chip */
    filters: "mt-0 mb-1 -mx-1",
    card: [
      "@container grid grid-cols-[minmax(min-content,1fr)] grid-rows-[auto_auto]",
      "overflow-x-auto overscroll-x-contain rounded-card bg-surface shadow-card",
      "[scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
      "focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-accent focus-visible:outline-offset-2",
      /* a table cut by the card's edge fades into the surface on the side it continues past (a mask
       * is ruled out: it would cut the card's shadow). Two sticky veils ride the card's edges over the
       * whole table. Each shows while there is more on its side, at once (no time involved):
       * data-overflow-start and data-overflow-end, kept in step with the scroll position by
       * watchVeils (lib/veil.ts). A card that fits has neither and shows none. */
      "before:content-[''] before:[grid-area:1/1/-1/2] before:sticky before:z-1 before:w-6 before:pointer-events-none before:opacity-0",
      "after:content-[''] after:[grid-area:1/1/-1/2] after:sticky after:z-1 after:w-6 after:pointer-events-none after:opacity-0",
      "before:[justify-self:start] before:start-0 before:bg-[linear-gradient(to_var(--_end,right),var(--fndn-surface),transparent)]",
      "after:[justify-self:end] after:end-0 after:bg-[linear-gradient(to_var(--_start,left),var(--fndn-surface),transparent)]",
      "rtl:[--_end:left] rtl:[--_start:right]",
      "data-overflow-start:before:opacity-100 data-overflow-end:after:opacity-100",
    ],
    table: "[grid-area:1/1] min-w-(--fndn-filter-min,420px)",
    head: [
      "grid grid-cols-(--fndn-filter-cols)",
      "border-b border-b-(color:--_grid-line) text-dense font-medium text-ink-2",
    ],
    th: "min-w-0 px-3 py-2 border-e border-e-(color:--_grid-line) last:border-e-0 last:border-e-current overflow-hidden text-ellipsis whitespace-nowrap text-start",
    row: [
      "kbd-instant",
      "grid grid-rows-[0fr] opacity-0 invisible [&>*]:min-h-0 [&>*]:overflow-hidden",
      "motion-size-reveal motion-opacity-base motion-also-[visibility_var(--fndn-duration-reveal)]",
    ],
    cells: [
      "grid grid-cols-(--fndn-filter-cols)",
      /* the row hover is instant both ways (the tables' one hover) */
      "border-b border-b-(color:--_grid-line) text-sm hover:bg-hover",
    ],
    /* long names truncate at the end; the full value is in the title */
    cell: [
      "flex min-w-0 items-center px-3 py-2 border-e border-e-(color:--_grid-line) last:border-e-0 last:border-e-current text-ink-2",
      "[&>span:not([data-filter-table])]:min-w-0 [&>span:not([data-filter-table])]:overflow-hidden",
      "[&>span:not([data-filter-table])]:text-ellipsis [&>span:not([data-filter-table])]:whitespace-nowrap",
    ],
    /* on the StatusPill and on the Tag: either may run into the cell's end padding before it truncates */
    status: "max-w-[calc(100%+10px)]",
    tag: "max-w-[calc(100%+10px)]",
    /* on the EmptyState: it takes the card's width and stays in view while the table scrolls */
    empty: "[grid-area:2/1] sticky start-0 [justify-self:start] w-[100cqi]",
  },
  variants: {
    /* author text keeps its own direction (cut at its own end) while the layout follows the page */
    type: {
      title: { cell: "font-medium text-ink [&>span]:[unicode-bidi:plaintext] [&>span]:[text-align:match-parent]" },
      text: { cell: "[&>span]:[unicode-bidi:plaintext] [&>span]:[text-align:match-parent]" },
      date: { cell: "whitespace-nowrap tabular-nums" },
      number: { th: "text-end", cell: "justify-end whitespace-nowrap tabular-nums" },
      /* the sm pill is 22px, the Tag 24px: a status row keeps the 40px of a tag row, so rows and
       * baselines do not move with the column type */
      status: { cell: "min-h-10" },
      tag: {},
    },
    /* the row matches the filter */
    shown: { true: { row: "grid-rows-[1fr] opacity-100 visible" } },
    /* "nothing matches" (a row) keeps the table's own breathing room; no rows at all is a block */
    empty: {
      row: { empty: "py-5" },
      block: {},
    },
  },
});

export type FilterTableRecipeProps = VariantProps<typeof filterTable>;
```
