Sort Builder
ProNewA sort with several levels: each rule is a sentence whose field and direction are controls, rules move up and down, a field is used once, and the whole sort is read back in words.
Installation
pnpm dlx shadcn@latest add @viewport/sort-builder
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above comes with Truffle Pro.
Props
| Prop | Type | Default |
|---|---|---|
| fields* | { id: string; label: string }[]The fields that can be sorted by. | — |
| value* | SortRule[]The sort, most important rule first. | — |
| onValueChange* | (value: SortRule[]) => void | — |
| max | numberThe most rules allowed. | 4 |
| className | string | — |
Accessibility
- Every control is named with its rule and field.
- The sort is announced in words as it changes.
- Move buttons disable at the ends.
- Fields keep 16px text on phones.
- Respects prefers-reduced-motion.