Skip to content

DataList

Records one below the other, each with its name and a few facts in named columns. Lighter than a table when each record matters more than comparing columns.

import { DataList, DataListSkeleton } from '@sypnia/ui/react'

On this page
  1. Deploys of a project
  2. Loading and empty
  3. Skeleton
  4. When to use it
  5. For everyone
  6. Props

Deploys of a project

Code
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: () => {} }]} />} />
  );
}

Loading and empty

And the skeleton on its own, before even the fields are known:

Code
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
Code
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>
  );
}

When to use it

Use it when

  • Deploys, invoices, members: a handful of facts per record.
  • href makes each record a link; actions adds RowActions at the end.

Do not use it when

  • Comparing many columns or sorting by them: use Table or DataTable.
  • A single line per thing: use List.

For everyone

  • It is a list; each fact is a term and its value, read in order.
  • Longer than a page, it paginates, and the bar says which records are on screen.

Props

DataListTypeDefault
fieldsrequired

The facts of each record, by name.

DataField<Row>[]
labelrequired

A name for screen readers.

string
rowKeyrequired (row: Row) => string | number
rowsrequired Row[] | undefined
titlerequired

The name of each record: the first thing read.

(row: Row) => ReactNode
actions

What can be done to each record (RowActions).

((row: Row) => ReactNode)
description

A second line under the name.

((row: Row) => ReactNode)
empty

What to say when there are none.

ReactNode
href

With it each record is a link.

((row: Row) => string)
loading

The records are on their way: skeletons of the same shape.

boolean
media

Something at the start of each record: an Avatar, an icon.

((row: Row) => ReactNode)
pageSize number 20
DataListSkeletonTypeDefault
description boolean true
fields number 3
items number 4
pagination boolean
  1. Deploys of a project
  2. Loading and empty
  3. Skeleton
  4. When to use it
  5. For everyone
  6. Props

    Search pages, sections and terms