# Keysort filter

Edge-notched cards from the 1950s office: each hole along the top is an attribute, notched open if the card has it. Push needles down the columns and the cards notched for all of them fall free. AND filtering you can see. For documents, tickets and records with tags.

- Category: Records
- Docs: https://bevel-ui.vercel.app/components/keysort-filter
- Import from: `@/components/ui/keysort-filter`

## Install

```bash
npx shadcn@latest add @bevel/keysort-filter
```

npm dependencies (installed by the CLI): `@base-ui/react`, `cn`.

## Anatomy

```tsx
<KeysortFilter aria-label="Contracts">
  <KeysortFilterNeedles>
    <KeysortFilterNeedle value="nda">NDA</KeysortFilterNeedle>
    <KeysortFilterNeedle value="signed">Signed</KeysortFilterNeedle>
  </KeysortFilterNeedles>
  <KeysortFilterDeck>
    <KeysortFilterCard notches={["nda", "signed"]}>Acme mutual NDA</KeysortFilterCard>
  </KeysortFilterDeck>
  <KeysortFilterCount />
</KeysortFilter>
```

## Parts

| Part | Renders | Description |
| --- | --- | --- |
| `KeysortFilter` | div (group) | value, defaultValue and onValueChange: the needles pushed through. Give it an aria-label. |
| `KeysortFilterNeedles` | div (group) | The needle handles, one above each column of holes. |
| `KeysortFilterNeedle` | Toggle | One attribute, and the column of holes under it, in the order listed. Pushed in, a rod runs down the column. |
| `KeysortFilterDeck` | ul | The cards, one per row, with the needles running down behind them. |
| `KeysortFilterCard` | li | notches: the attributes it has. Caught cards show the needle through their hole; free ones get a tab and say “Matches”. |
| `KeysortFilterCount` | p (status) | “2 of 8 cards match NDA and Signed.” Announced as needles go in and out. |

## Example: A drawer of contracts

Push needles through to find the contracts with every attribute.

```tsx
"use client"

import {
  KeysortFilter,
  KeysortFilterCard,
  KeysortFilterCount,
  KeysortFilterDeck,
  KeysortFilterNeedle,
  KeysortFilterNeedles,
} from "@/components/ui/keysort-filter"

const contracts = [
  { title: "Acme mutual NDA", tags: ["nda", "signed", "auto"] },
  { title: "Globex NDA, redlined", tags: ["nda", "eu"] },
  { title: "Initech supply agreement", tags: ["signed", "eu", "auto"] },
  { title: "Umbrella term sheet", tags: [] },
  { title: "Hooli data processing addendum", tags: ["signed", "eu", "dpa"] },
  { title: "Stark consulting SOW", tags: ["signed", "auto"] },
  { title: "Wayne one-way NDA", tags: ["nda"] },
  { title: "Tyrell DPA, draft", tags: ["eu", "dpa"] },
]

/** A drawer of contracts. Push needles in to find the ones with every attribute. */
export function KeysortFilterContracts() {
  return (
    <KeysortFilter aria-label="Contracts" className="max-w-2xl">
      <KeysortFilterNeedles>
        <KeysortFilterNeedle value="nda">NDA</KeysortFilterNeedle>
        <KeysortFilterNeedle value="signed">Signed</KeysortFilterNeedle>
        <KeysortFilterNeedle value="eu">EU</KeysortFilterNeedle>
        <KeysortFilterNeedle value="auto">Renews</KeysortFilterNeedle>
        <KeysortFilterNeedle value="dpa">DPA</KeysortFilterNeedle>
      </KeysortFilterNeedles>
      <KeysortFilterDeck>
        {contracts.map((c) => (
          <KeysortFilterCard key={c.title} notches={c.tags}>
            {c.title}
          </KeysortFilterCard>
        ))}
      </KeysortFilterDeck>
      <KeysortFilterCount />
    </KeysortFilter>
  )
}
```
