DataList
Registros uno debajo del otro, cada uno con su nombre y unos pocos datos en columnas con nombre. Más ligero que una tabla cuando cada registro importa más que comparar columnas.
import { DataList, DataListSkeleton } from '@sypnia/ui/react'
Despliegues de un proyecto
- Deploy #120by Ana Ruiz
- State
- Live
- Branch
main- Commit
9f2c41a…9f2c41ab00- Took
- 38 s
- Deploy #119by Bo Chen
- State
- Live
- Branch
fix/checkout- Commit
1d7e0c9…1d7e0c9301- Took
- 45 s
- Deploy #118by Lucía Gómez
- State
- Failed
- Branch
main- Commit
b44a2e1…b44a2e1002- Took
- 52 s
- Deploy #117by Ana Ruiz
- State
- Live
- Branch
feat/search- Commit
7c91fe0…7c91fe0203- Took
- 59 s
- Deploy #116by Bo Chen
- State
- Live
- Branch
main- Commit
9f2c41a…9f2c41ab04- Took
- 66 s
- Deploy #115by Lucía Gómez
- State
- Live
- Branch
fix/checkout- Commit
1d7e0c9…1d7e0c9305- Took
- 73 s
- Deploy #114by Ana Ruiz
- State
- Live
- Branch
main- Commit
b44a2e1…b44a2e1006- Took
- 40 s
- Deploy #113by Bo Chen
- State
- Live
- Branch
feat/search- Commit
7c91fe0…7c91fe0207- Took
- 47 s
1–8 de 19
Código
import { Badge, DataList, Hash, RowActions } from '@sypnia/ui/react';
// Each deploy matters more than comparing columns: a name, a second line, and a few named facts. Past 8 it paginates.
const deploys = Array.from({ length: 19 }, (_, i) => ({
id: 120 - i,
branch: ['main', 'fix/checkout', 'main', 'feat/search'][i % 4],
commit: ['9f2c41ab', '1d7e0c93', 'b44a2e10', '7c91fe02'][i % 4] + String(i).padStart(2, '0'),
state: i === 2 ? 'failed' : 'live',
took: 38 + ((i * 7) % 40),
by: ['Ana Ruiz', 'Bo Chen', 'Lucía Gómez'][i % 3],
}));
export default function Deploys() {
return (
<DataList label="Deploys" rows={deploys} rowKey={(d) => d.id} pageSize={8}
title={(d) => `Deploy #${d.id}`} description={(d) => `by ${d.by}`} href={(d) => `#deploy-${d.id}`}
fields={[
{ id: 'state', label: 'State', value: (d) => <Badge tone={d.state === 'live' ? 'ok' : 'fail'} dot>{d.state === 'live' ? 'Live' : 'Failed'}</Badge> },
{ id: 'branch', label: 'Branch', value: (d) => <code>{d.branch}</code> },
{ id: 'commit', label: 'Commit', value: (d) => <Hash value={d.commit} copy={false} /> },
{ id: 'took', label: 'Took', numeric: true, value: (d) => `${d.took} s` },
]}
actions={(d) => <RowActions label={`Actions for deploy ${d.id}`} actions={[{ id: 'logs', label: 'View logs', icon: 'logs', onAction: () => {} }, { id: 'rollback', label: 'Roll back to this one', icon: 'rollback', onAction: () => {} }]} />} />
);
} Cargando y vacío
And the skeleton on its own, before even the fields are known:
Código
import { useState } from 'react';
import { DataList, DataListSkeleton, EmptyState, SegmentedControl } from '@sypnia/ui/react';
// While the records come, a skeleton of the same shape; with none, an empty state that says what happens next.
export default function States() {
const [state, setState] = useState('loading');
return (
<div className="sy-stack">
<div><SegmentedControl label="State" value={state} onChange={setState} options={[{ value: 'loading', label: 'Loading' }, { value: 'empty', label: 'Empty' }]} /></div>
<DataList label="Invoices" rows={state === 'loading' ? undefined : []} rowKey={(r: { id: number }) => r.id} title={() => ''} fields={[{ id: 'a', label: 'Amount', value: () => '' }, { id: 'b', label: 'Due', value: () => '' }]}
empty={<EmptyState compact icon="invoice" title="No invoices yet">The first one is sent on December 1.</EmptyState>} />
<p className="sy-text--muted">And the skeleton on its own, before even the fields are known:</p>
<DataListSkeleton items={2} fields={2} />
</div>
);
} Skeleton
- Deploy #120by Ana Ruiz
- Took
- 42 s
Código
import { DataList, DataListSkeleton } from '@sypnia/ui/react';
// A record and the skeleton of one: the name, its second line and each field, in the same row.
export default function Skeleton() {
return (
<div className="sy-cols sy-cols--stack">
<DataList label="Deploys" rows={[{ id: 1, name: 'Deploy #120', by: 'Ana Ruiz', took: '42 s' }]} rowKey={(r) => r.id} title={(r) => r.name} description={(r) => `by ${r.by}`} fields={[{ id: 't', label: 'Took', value: (r) => r.took }]} />
<DataListSkeleton items={1} fields={1} />
</div>
);
} Cuándo usarlo
Úsalo cuando
- Despliegues, facturas, miembros: unos pocos datos por registro.
hrefhace de cada registro un enlace;actionsagrega RowActions al final.
No lo uses cuando
- Comparar muchas columnas u ordenar por ellas: usa Table o DataTable.
- Una sola línea por cosa: usa List.
Para todos
- Es una lista; cada dato es un término y su valor, leídos en orden.
- Si es más larga que una página se pagina, y la barra dice qué registros están en pantalla.
Props
| DataList | Tipo | Por defecto |
|---|---|---|
fieldsobligatorioThe facts of each record, by name. | DataField<Row>[] | |
labelobligatorioA name for screen readers. | string | |
rowKeyobligatorio | (row: Row) => string | number | |
rowsobligatorio | Row[] | undefined | |
titleobligatorioThe name of each record: the first thing read. | (row: Row) => ReactNode | |
actionsWhat can be done to each record (RowActions). | ((row: Row) => ReactNode) | |
descriptionA second line under the name. | ((row: Row) => ReactNode) | |
emptyWhat to say when there are none. | ReactNode | |
hrefWith it each record is a link. | ((row: Row) => string) | |
loadingThe records are on their way: skeletons of the same shape. | boolean | |
mediaSomething at the start of each record: an Avatar, an icon. | ((row: Row) => ReactNode) | |
pageSize | number | 20 |
| DataListSkeleton | Tipo | Por defecto |
|---|---|---|
description | boolean | true |
fields | number | 3 |
items | number | 4 |
pagination | boolean |