FilterChip
Un filtro activo: qué se filtra, por qué valor y un botón para quitarlo.
import { FilterChip } from '@sypnia/ui/react'
En esta página
Filtros activos
Pulsa una x. La última ficha no tiene x: no se puede quitar.
StatusPaidCountryColombiaTotalover US$ 100Placedthis month
Código
import { useState } from 'react';
import { Button, FilterChip } from '@sypnia/ui/react';
const start = [{ id: 'status', label: 'Status', value: 'Paid' }, { id: 'country', label: 'Country', value: 'Colombia' }, { id: 'total', label: 'Total', value: 'over US$ 100' }];
// One filter that is on: its name, its value, and an x that takes it away.
export default function Basic() {
const [chips, setChips] = useState(start);
return (
<div className="sy-row">
{chips.map((c) => <FilterChip key={c.id} label={c.label} value={c.value} onRemove={() => setChips((all) => all.filter((x) => x.id !== c.id))} />)}
{chips.length === 0 ? <Button size="sm" onClick={() => setChips(start)}>Put them back</Button> : <FilterChip label="Placed" value="this month" />}
</div>
);
} Cuándo usarlo
Úsalo cuando
- Sobre una lista, para decir qué filtros están activos y que nadie se pregunte por qué faltan filas.
- Sin
onRemovesolo dice que el filtro está: para un filtro que la persona no puede quitar.
No lo uses cuando
- Es una opción que la persona aún no ha elegido: Chip o un select.
- Es una etiqueta de una cosa: Tag o Badge.
Para todos
- La x es un botón de verdad con el nombre del filtro: «Quitar Estado».
- Su área es de al menos 24 px, y de 44 px en pantallas táctiles.
Props
| FilterChip | Tipo | Por defecto |
|---|---|---|
labelobligatorioWhat is filtered: the column's name. | string | |
valueobligatorioThe value it is filtered by. | ReactNode | |
onRemove | (() => void) |