Data Display

DataList

Semantic list container for like rows: empty state, density, day groups, a shared status column, and announced live insertion.

import { DataList } from '@lostgradient/cinder';
listiterator
01

Overview

Reference usage

A semantic list container (<ul role="list">) for a homogeneous collection of records. DataList owns the list element, the list reset, and the empty state; it delegates row chrome (padding, dividers, density) to the row primitive. Each record is rendered through the children snippet, which must render an <li> — StackedListItem is the recommended row.

Reach for DataList when you have a vertical list of like records. For key–value metadata about a single entity use DescriptionList; for tabular rows and columns use Table.

The headings follow Cinder’s group label pattern.

Usage

svelte
<script lang="ts">
  import { DataList } from '@lostgradient/cinder';
  import { StackedListItem } from '@lostgradient/cinder';

  const members = [
    { id: 'a', name: 'Alice Chen', role: 'Engineer' },
    { id: 'b', name: 'Bob Osei', role: 'Designer' },
  ];
</script>

<DataList items={members} key={(member) => member.id} density="condensed">
  {#snippet children(member)}
    <StackedListItem>
      {#snippet title()}{member.name}{/snippet}
      {#snippet meta()}{member.role}{/snippet}
    </StackedListItem>
  {/snippet}
  {#snippet empty()}
    No members yet.
  {/snippet}
</DataList>

A list-level density is inherited by every StackedListItem row that does not set its own density prop. The empty snippet renders inside a component-owned <li class="cinder-data-list-empty">, so it needs no inline styling.

Day groups

Pass groupBy to put consecutive rows under a group header: it returns { key, label, detail } for an item, and consecutive items with one key share a header (Today, Monday, Nov 2, with Central time at the right). Each group is a nested list named by its header, so a screen reader announces the day. Pass items already sorted; they are not reordered.

svelte
<DataList
  items={runs}
  key={(run) => run.id}
  statusColumn
  groupBy={(run) => ({ key: run.day, label: run.dayLabel, detail: 'Central time' })}
>
  {#snippet children(run)}
    <StackedListItem href={`/runs/${run.id}`}>
      {#snippet status()}<StatusDot word={run.status} />{/snippet}
      {#snippet title()}{run.title}{/snippet}
      {#snippet time()}{run.time}{/snippet}
    </StackedListItem>
  {/snippet}
</DataList>

statusColumn keeps the 128px status column for rows that have no status, so titles line up down the whole list. A status word is never cut: one longer than the column wraps onto a second line inside it, with a 12px gap before the title.

A quiet hairline separates the rows of a list, inset to the row's text. The last row of a list, or of a group, draws none, so rows are separated only between each other. Timeline items and Skeleton rows, which also use StackedListItem, draw none.

statusTrack widens that status column for every two-line row in a list when its status words carry a qualifier. For example, a goal's "Running, checking the result" uses statusTrack="12rem" so it remains separate from the row title; omit it to retain Cinder's 128px default.

trailingTrack does the same for the trailing column of two-line rows: a list whose rows carry a figure in trailing (a cost, a count) passes the width of its widest figure (trailingTrack="9rem"), so the track is one width in every row, with a trailing region or without, and the times before it end at one edge. trailingAlign="baseline" holds a figure on the first line's baseline; trailingAlign="line" centers a control in the title's first-line box on desktop. Pass them only at the widths where rows keep their trailing column; omitted, each row sizes the column by its own content.

Rows that change while you watch

Pass insertionAnnouncement to make the list live: a new row, such as a run that starts while the page is open, appears at the top of its group, and the function receives the number of new rows and returns the text (1 new run) that a polite live region speaks and draws as an accent status strip above the first group. Before any row arrives the region takes no space, so the first render announces and draws nothing, and the list holds the reader's place when the strip appears. Rows inserted above the viewport do not move what the reader is looking at: browsers with scroll anchoring already hold the position, and the list scrolls by the difference where they do not. A list scrolled to its top is left alone, so the new row is seen.

Row actions stay in a fixed column

A row's trailing actions sit in a fixed column at the end of the row, so a status badge or other metadata never changes where an action button lands. Put badges with the metadata in the row's content column, as StackedListItem does, and keep the trailing region for the actions alone.

Long values

The list wraps unbroken values (an identifier) anywhere by default, and StackedListItem rows clamp their titles at two lines, so no value widens the list past its frame.

Live preview

Basic data list

  • Alice Chen
    Engineer, Active
  • Bob Osei
    Designer, Active
  • Carol Mwangi
    Product, Invited

02

When to use

Use when
  • Rendering a vertical list of like records where each row shares the same layout.
  • Pairing with StackedListItem rows for leading/title/description/meta/trailing content.
  • Showing a dedicated empty state when the collection has no items.
  • Grouping rows under day headers, or announcing rows that arrive while the list is on screen.
Avoid when
  • Presenting key-value metadata for a single entity — use description-list instead.
  • Rendering tabular data with rows and columns — use table instead.
03

Examples

Basic data list

A list of homogeneous records. DataList is the semantic `<ul role="list">` container; each row is a StackedListItem with a title and trailing meta. Row chrome (padding, dividers, density) is owned by the row, so content stays compactly aligned instead of stretching to the viewport edges.

Day groups with a shared status column

groupBy puts consecutive rows under a group header that names a nested list, and statusColumn keeps the status column for rows with nothing to report so titles line up.

Empty state fallback

When items is empty, the empty snippet renders inside a component-owned `<li class="cinder-data-list-empty">` — centered, muted padding, no inline styles required.

A row inserted while you watch

insertionAnnouncement makes the list live: a new run appears at the top of its group, a polite live region says "1 new run", and the page does not change size or lose its place.

04

Props

Props for data-list
Name
Type
Default
Description
items required T[] The records to render. Each is passed to children.
key required (item: T) => string | number Key extractor for stable DOM reconciliation. Svelte uses this to identify each row when the list is reordered, filtered, or updated. Without a key, rows are matched by index and the wrong row instances may receive updated props, causing O(n) churn and incorrect rendering. ``svelte <DataList {items} key={(m) => m.id}> ``
density 'comfortable' | 'condensed' List-level density inherited by StackedListItem rows that do not set their own density prop. Omit to let each row use its own default. A per-row density always overrides this list-level value. Note: when passing a variable that may be undefined, spread conditionally because exactOptionalPropertyTypes is enabled: {...(density ? { density } : {})}
statusColumn boolean Keep the status column's width for every row that has no status (a workflow, an agent with nothing to report), so titles line up down the whole list. A row's own statusColumn wins.
statusTrack text The width of the leading status column in every two-line StackedListItem row in the list (a CSS length, such as 12rem). Use this only when a list's status words carry a qualifier that needs more room than Cinder's normal status column; titles remain aligned across the list.
trailingTrack text The width of the trailing column of every two-line StackedListItem row in the list (a CSS length, such as 9rem): the width of the widest figure a row carries in trailing (a cost, a count). The track is then one width in every row, with a trailing region or without, so the times before it end at one edge. Omit it and each row sizes the track by its own content. Pass it only at the widths where rows keep their trailing column.
trailingAlign 'center' | 'baseline' | 'line' Where a two-line row's trailing region sits against the row's lines: center (the default) centers it on both lines, baseline holds a figure on the first baseline, and line centers a control within the title's first line.
groupBy (item: T) => DataListGroup Group consecutive items under a group header, newest group first as the items arrive. Each group is a nested list named by its header, so a screen reader announces the day. Items are not reordered; pass them already sorted.
insertionAnnouncement (count: number) => string Announce rows inserted while the list is on screen. Called with the number of new rows; the returned text (1 new run) is spoken politely through a live region that is also drawn as a status strip above the first group. The first render announces nothing. Rows inserted above the viewport do not move what the reader is looking at.
children required snippet Row renderer. MUST render an <li> (the list root is a <ul role="list">). StackedListItem is the recommended row — it renders an <li> with leading/title/description/meta/trailing slots.
empty snippet Rendered when items is empty. The component automatically wraps the snippet output in <li class="cinder-data-list-empty">. Do NOT wrap in an <li> yourself — the component provides the <li> wrapper automatically. Pass only inner content (e.g. a <p>, a <div>, or plain text). Contrast with children, which must render an <li>.