Skip to content

SearchAndFilter

Finding one thing among hundreds: words to search, filters that show as chips, an order, and a count that says how many match. Nothing matching is said with what was asked and a way back.

import { SearchInput, FilterBar, SortMenu } from '@sypnia/ui/react'

On this page
  1. On a desktop
  2. On a phone
  3. Nothing matches
  4. Skeleton
  5. When to use it
  6. For everyone
  7. Props

On a desktop

Search «refunds», filter by status, change the order. The count follows.

Deploys

Every version of northwind-shop that was built, newest first.

132 deploys
132 deploys
DeployStatusEnvironmentWhenBuild time
Fix rounding in refunds
9f3a2c1…9f3a2c1a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
LivePreview · Ana Ruiznow38 sec
Move images to the new bucket
9f3c1b0…9f3c1b0a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyProduction · Kenji Mori5 hours ago1 min
Speed up the product search
9f3e09f…9f3e09fa3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyProduction · Marta Gil11 hours ago2 min
Bump dependencies
9f3ff8e…9f3ff8ea3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyPreview · Luis Ortega16 hours ago59 sec
Retry webhooks on 502
9f41e7d…9f41e7da3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
FailedProduction · Ana Ruiz21 hours ago2 min
Add the refunds table
9f43d6c…9f43d6ca3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyProduction · Kenji Moriyesterday43 sec
Show stock on the product page
9f45c5b…9f45c5ba3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyPreview · Marta Gilyesterday1 min
Update the checkout copy
9f47b4a…9f47b4aa3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyProduction · Luis Ortega2 days ago2 min
Fix rounding in refunds
9f49a39…9f49a39a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyProduction · Ana Ruiz2 days ago1 min
Move images to the new bucket
9f4b928…9f4b928a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
CancelledPreview · Kenji Mori2 days ago2 min
Speed up the product search
9f4d817…9f4d817a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyProduction · Marta Gil2 days ago48 sec
Bump dependencies
9f4f706…9f4f706a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyProduction · Luis Ortega2 days ago1 min
Retry webhooks on 502
9f515f5…9f515f5a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyPreview · Ana Ruiz3 days ago2 min
Add the refunds table
9f534e4…9f534e4a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyProduction · Kenji Mori3 days ago1 min
Show stock on the product page
9f553d3…9f553d3a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyProduction · Marta Gil3 days ago2 min
Update the checkout copy
9f572c2…9f572c2a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
FailedPreview · Luis Ortega3 days ago53 sec
Fix rounding in refunds
9f591b1…9f591b1a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyProduction · Ana Ruiz4 days ago2 min
Move images to the new bucket
9f5b0a0…9f5b0a0a3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyProduction · Kenji Mori4 days ago2 min
Speed up the product search
9f5cf8f…9f5cf8fa3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyPreview · Marta Gil4 days ago1 min
Bump dependencies
9f5ee7e…9f5ee7ea3c9a3c9a3c9a3c9a3c9a3c9a3c9a3c9a
ReadyProduction · Luis Ortega4 days ago2 min
1–20 of 132
Code
import { useMemo, useState } from 'react';
import {
  Badge, Button, EmptyState, FilterBar, Hash, LiveRegion, Page, PageHeader, SearchInput, SkeletonOf, SkeletonWords, SortMenu, Table, TableToolbar,
  useSypnia, type DataFilters, type DataSort,
} from '@sypnia/ui/react';

// Finding one thing among hundreds: words to search, filters that show as chips, an order, and a count that says how
// many match. Nothing matching is said with what was asked and a way back. The table paginates and says which rows
// are on screen.
type Deploy = { id: string; commit: string; message: string; env: 'production' | 'preview'; status: 'live' | 'ready' | 'failed' | 'cancelled'; author: string; at: number; secs: number };
const en = {
  title: 'Deploys', lead: 'Every version of northwind-shop that was built, newest first.', search: 'Search deploys', searchHint: 'Commit message or hash',
  filters: 'Filter deploys', env: 'Environment', status: 'Status', author: 'Author', authorHint: 'Name', sort: 'Order', newest: 'Date', duration: 'Build time',
  deploy: 'Deploy', when: 'When', time: 'Build time', count: (n: number, all: number) => (n === all ? `${all} deploys` : `${n} of ${all} deploys match`),
  envs: { production: 'Production', preview: 'Preview' }, statuses: { live: 'Live', ready: 'Ready', failed: 'Failed', cancelled: 'Cancelled' },
  none: (q: string) => (q ? `No deploy matches «${q}» with these filters` : 'No deploy matches these filters'), noneBody: 'Try fewer words, or clear the filters to see every deploy.', clear: 'Clear search and filters',
  failed: 'The deploys could not be loaded. Nothing changed in your project.',
};
const es: typeof en = {
  title: 'Despliegues', lead: 'Cada versión de northwind-shop que se construyó, la más nueva primero.', search: 'Buscar despliegues', searchHint: 'Mensaje o hash del commit',
  filters: 'Filtrar despliegues', env: 'Entorno', status: 'Estado', author: 'Autor', authorHint: 'Nombre', sort: 'Orden', newest: 'Fecha', duration: 'Tiempo de construcción',
  deploy: 'Despliegue', when: 'Cuándo', time: 'Construcción', count: (n: number, all: number) => (n === all ? `${all} despliegues` : `${n} de ${all} despliegues coinciden`),
  envs: { production: 'Producción', preview: 'Vista previa' }, statuses: { live: 'En línea', ready: 'Listo', failed: 'Falló', cancelled: 'Cancelado' },
  none: (q: string) => (q ? `Ningún despliegue coincide con «${q}» y estos filtros` : 'Ningún despliegue coincide con estos filtros'), noneBody: 'Prueba con menos palabras, o borra los filtros para ver todos los despliegues.', clear: 'Borrar búsqueda y filtros',
  failed: 'No se pudieron cargar los despliegues. Nada cambió en tu proyecto.',
};
const messages = ['Fix rounding in refunds', 'Add the refunds table', 'Speed up the product search', 'Update the checkout copy', 'Retry webhooks on 502', 'Move images to the new bucket', 'Show stock on the product page', 'Bump dependencies'];
const people = ['Ana Ruiz', 'Luis Ortega', 'Marta Gil', 'Kenji Mori'];
const now = Date.UTC(2026, 10, 17, 15);
const all: Deploy[] = Array.from({ length: 132 }, (_, i) => ({
  id: `dpl_${(9137 - i).toString(36)}`, commit: (0x9f3a2c1 + i * 7919).toString(16).padEnd(40, 'a3c9'), message: messages[(i * 5) % messages.length],
  env: i % 3 === 0 ? 'preview' : 'production', status: i === 0 ? 'live' : i % 11 === 4 ? 'failed' : i % 17 === 9 ? 'cancelled' : 'ready',
  author: people[(i * 3) % 4], at: now - i * 5.3 * 3600e3, secs: 38 + ((i * 37) % 90),
}));
const tone = { live: 'light', ready: 'ok', failed: 'fail', cancelled: 'neutral' } as const;

export default function SearchAndFilter({ state = 'ready' }: { state?: 'ready' | 'loading' | 'none' | 'error' }) {
  const { locale, format } = useSypnia();
  const c = locale.startsWith('es') ? es : en;
  const [query, setQuery] = useState(state === 'none' ? 'invoice pdf' : '');
  const [filters, setFilters] = useState<DataFilters>(state === 'none' ? { env: 'production' } : {});
  const [sort, setSort] = useState<DataSort | null>({ id: 'at', dir: 'descending' });
  const [failed, setFailed] = useState(state === 'error');
  const shown = useMemo(() => {
    const q = query.trim().toLowerCase();
    const out = all.filter((d) => (!q || `${d.message} ${d.commit}`.toLowerCase().includes(q))
      && (!filters.env || d.env === filters.env) && (!filters.status || d.status === filters.status)
      && (!filters.author || d.author.toLowerCase().includes(filters.author.toLowerCase())));
    if (sort) out.sort((a, b) => (sort.id === 'secs' ? a.secs - b.secs : a.at - b.at) * (sort.dir === 'ascending' ? 1 : -1));
    return out;
  }, [query, filters, sort]);
  // Loading: the real page. The search, order and filters are the person's, so they are there; the deploys are a page
  // of rows (and the pagination bar: there were more than a page last time), each value as long as a real one.
  const loading = state === 'loading';
  const was = (i: number) => all[i % all.length];
  const fields = [
    { id: 'env', label: c.env, type: 'select' as const, options: (['production', 'preview'] as const).map((v) => ({ value: v, label: c.envs[v] })) },
    { id: 'status', label: c.status, type: 'select' as const, options: (['live', 'ready', 'failed', 'cancelled'] as const).map((v) => ({ value: v, label: c.statuses[v] })) },
    { id: 'author', label: c.author, placeholder: c.authorHint },
  ];
  const clear = () => { setQuery(''); setFilters({}); };
  return (
    <Page>
      <PageHeader title={c.title} lead={c.lead} />
      <form role="search" aria-label={c.search} onSubmit={(e) => e.preventDefault()}>
        <TableToolbar label={c.search} actions={<SortMenu value={sort} onChange={setSort} options={[{ id: 'at', label: c.newest }, { id: 'secs', label: c.duration }]} />}>
          <SearchInput aria-label={c.search} placeholder={c.searchHint} value={query} onChange={(e) => setQuery(e.target.value)} />
        </TableToolbar>
      </form>
      <FilterBar label={c.filters} fields={fields} values={filters} onChange={setFilters} />
      <LiveRegion visible={false}>{c.count(shown.length, all.length)}</LiveRegion>
      <Table label={c.title} rows={failed || loading ? undefined : shown} rowKey={(d) => d.id} pageSize={20} loading={loading} loadingRows={all.length}
        error={failed ? c.failed : undefined} onRetry={() => setFailed(false)}
        toolbar={loading ? <SkeletonOf><Badge tone="neutral">{c.count(all.length, all.length)}</Badge></SkeletonOf> : <Badge tone="neutral">{c.count(shown.length, all.length)}</Badge>}
        empty={<EmptyState icon="search" compact title={c.none(query.trim())} actions={<Button onClick={clear}>{c.clear}</Button>}>{c.noneBody}</EmptyState>}
        columns={[
          { id: 'deploy', header: c.deploy, cell: (d) => <span><b>{d.message}</b><br /><Hash value={d.commit} label="commit" /></span>,
            skeleton: (i) => <span><b><SkeletonWords>{was(i).message}</SkeletonWords></b><br /><SkeletonOf><Hash value={was(i).commit} label="commit" /></SkeletonOf></span> },
          { id: 'status', header: c.status, cell: (d) => <Badge tone={tone[d.status]} dot>{c.statuses[d.status]}</Badge>, skeleton: (i) => <SkeletonOf><Badge dot>{c.statuses[was(i).status]}</Badge></SkeletonOf> },
          { id: 'env', header: c.env, cell: (d) => `${c.envs[d.env]} · ${d.author}`, skeleton: (i) => <SkeletonWords>{`${c.envs[was(i).env]} · ${was(i).author}`}</SkeletonWords> },
          { id: 'at', header: c.when, cell: (d) => format.relative(new Date(d.at), now), skeleton: (i) => <SkeletonWords>{format.relative(new Date(was(i).at), now)}</SkeletonWords> },
          { id: 'secs', header: c.time, numeric: true, cell: (d) => format.duration(d.secs * 1000), skeleton: (i) => <SkeletonWords>{format.duration(was(i).secs * 1000)}</SkeletonWords> },
        ]} />
    </Page>
  );
}

On a phone

On a phone the filters sit two by two and every deploy is a card.

Nothing matches

The words and the filters stay, and one button clears them.

Deploys

Every version of northwind-shop that was built, newest first.

0 of 132 deploys match
0 of 132 deploys match

No deploy matches «invoice pdf» with these filters

Try fewer words, or clear the filters to see every deploy.

Skeleton

The search, order and filters stay (they are the person's); the table draws a page of rows sized like real deploys, and the pagination bar.

Deploys

Every version of northwind-shop that was built, newest first.

132 deploys
DeployStatusEnvironmentWhenBuild time




















When to use it

Use it when

  • Any list longer than a screen: deploys, orders, logs, customers.
  • A count that changes as the person types, read to screen readers too.

Do not use it when

  • Filters hidden behind a button when there are only two or three.
  • «No results» alone: say what was searched and offer to clear it.

For everyone

  • The search is a search landmark; every filter that is on is a chip with its own remove button.
  • The number of matches is announced politely as it changes.
  • The table paginates and says which rows are on screen.

Props

SearchInputTypeDefault
machine

Machine text (ids, keys, code): set in the mono face.

boolean
size "sm" | "md" | "lg"
FilterBarTypeDefault
fieldsrequired FilterField[]
onChangerequired (values: DataFilters) => void
valuesrequired

The value of each filter by field id. An empty or missing value means the filter is off.

DataFilters
collapsed

Only the chips of the filters that are on, without the fields.

boolean
label

A name for screen readers.

string
SortMenuTypeDefault
onChangerequired (sort: DataSort | null) => void
optionsrequired SortOption[]
valuerequired DataSort | null
none

Offers «No order», which goes back to the order the data came in.

boolean true
size "sm" | "md" sm
  1. On a desktop
  2. On a phone
  3. Nothing matches
  4. Skeleton
  5. When to use it
  6. For everyone
  7. Props

    Search pages, sections and terms