Cómo funciona
A card with no outer border. The title row holds the title and a filled, fully round search pill; below it, single-select chips each show the count they would leave, and the active chip is an ink pill that pops when chosen. Search is case-insensitive over all columns unless excluded, and matches are wrapped in <mark> (accent ink on its soft partner). The body is fixed at bodyRows rows with a sticky header, so the card never changes height. When results change, staying rows slide with FLIP and new rows fade in. Typing waits for an input method to commit.
Úsalo para
- Admin and catalog list pages with a few hundred rows at most.
- Lists where people search by words and also narrow by status or type.
- Server-side search: use it controlled, request data in onQueryChange and pass the results as rows.
Busca otra opción cuando
- Large datasets that need pagination or virtual scrolling: above 200 rows the move animations are skipped, and a pager fits better.
- Tables that need sorting, column resizing or selection: use a full data grid.
- Simple lists with no columns: use a list with a search field.
Uso
import { FilterTable } from './FilterTable.jsx'
const STATUS = { confirmed: 'Confirmed', waiting: 'Waiting', cancelled: 'Cancelled' }
const columns = [
// Custom cell: searchText decides what is searched, highlight keeps the match highlight
{
key: 'patient',
title: 'Patient',
searchText: (r) => `${r.name} ${r.reason}`,
render: (r, { highlight }) => (
<>
{highlight(r.name)} · {highlight(r.reason)}
</>
),
},
// Times do not take part in search
{ key: 'time', title: 'Time', width: 68, align: 'right', searchable: false },
{ key: 'status', title: 'Status', width: 108, searchText: (r) => STATUS[r.status], render: (r, { highlight }) => highlight(STATUS[r.status]) },
]
const rows = [
{ id: 'v1', name: 'Mara Olsen', reason: 'Check-up', time: '09:00', status: 'confirmed' },
{ id: 'v2', name: 'Tomás Ortega', reason: 'Vaccination', time: '09:30', status: 'waiting' },
{ id: 'v3', name: 'Priya Raman', reason: 'Blood test', time: '10:45', status: 'cancelled' },
]
export function Appointments() {
return (
<FilterTable
title="Appointments"
subtitle="Today"
placeholder="Search"
columns={columns}
rows={rows}
rowKey={(r) => r.id}
filters={Object.entries(STATUS).map(([key, label]) => ({ key, label, predicate: (r) => r.status === key }))}
bodyRows={6}
/>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
columns | FilterTableColumn<T>[] | — | Column definitions: key (id and default value field), title, width, align, searchable (default true), searchText (text to compare when searching), and render(row, { highlight, index, query }) for custom cells; call highlight(text) to keep the highlight. |
rows | T[] | — | All data rows. The component filters them by the query and the chosen filter. |
rowKey | (row: T) => string | number | — | Unique id of a row. Rows that stay after filtering are recognised by it and slide to their new place. |
query | string | — | Controlled: the current query. Omit it and the component keeps its own. |
defaultQuery | string | '' | Initial query when uncontrolled. |
onQueryChange | (query: string) => void | — | Called when the query changes. Not called while an input method is composing, only once the text is committed. |
filters | { key: string; label: string; predicate: (row: T) => boolean }[] | — | Filter options, shown as single-select chips with counts. “All” is added in front automatically. Omit it for a search box only. |
filter | string | null | — | Controlled: key of the current filter, null for “All”. Omit it and the component keeps its own. |
defaultFilter | string | null | null | Initial filter when uncontrolled. |
onFilterChange | (key: string | null) => void | — | Called when the filter changes; null means back to “All”. |
allLabel | string | 'All' | Text of the “All” chip. |
placeholder | string | 'Search' | Placeholder and accessible name of the search pill. Keep it short when there is a title: the pill shares the title row. |
bodyRows | number | 5 | Height of the table body in rows (at least 2). More rows scroll inside, fewer leave blank space, so the frame never changes height. |
highlightMatches | boolean | true | Whether matching text is highlighted. |
emptyText | (query: string) => ReactNode | No results for “query” | Text when there are no results; receives the current query (maybe empty). |
labels | object | — | Replaces built-in text (found, noResults, emptyQuery, emptyFilter, empty, clearQuery, filters, table, scrollable, reset). Shallow-merged over the English defaults. The placeholder and “All” chip have their own props. |
onResultChange | (rows: T[]) => void | — | Called when the filtered result changes (also once on mount) with the rows now shown. |
title | ReactNode | — | Card title. With a title (or icon / subtitle) the search pill moves to the right of the title row; without one it fills the row. A string title also names the table for screen readers when label is not given. |
subtitle | ReactNode | — | Muted qualifier after the title, such as a period ("This week"). |
icon | ReactNode | — | Icon before the title, drawn in a tinted 32px rounded square. Decorative (aria-hidden). |
actions | ReactNode | — | Extra controls at the right end of the title row, after the search pill. |
label | string | — | Table name for screen readers (the <caption>). Defaults to title when title is a string. |
...rest | HTMLAttributes<HTMLDivElement> | — | Other attributes go to the root <div>. |
Accesibilidad
- The search box is named by its placeholder, and a clear button is available only when there is text.
- Filter chips are toggle buttons with aria-pressed inside a labelled group.
- A polite live region announces the number of results after each change.
- When rows overflow, the body becomes a focusable group so arrow keys can scroll it.
- Esc clears the search without closing an outer dialog; reduced motion skips the slide and fade.
Movimiento
Rows that stay move with translateY over 360ms ease-in-out; new rows fade in over 240ms ease-out. The chosen chip turns ink and pops (0.92 → 1.04 → 1, 360ms spring); chips shrink to 0.96 while pressed. The empty state fades in and rises 6px over 240ms. The search pill's focus ring, the clear button and the header shadow use 160ms.
Añádelo a tu proyecto
Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.
FilterTable.jsxfilter-table.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.





