# Collections

> The components of songstress/ui for collections, each as Songstress draws it, with its props and an example.

Page: https://songstress.app/docs/develop/components/collections/

Many of a kind: rows in a list, rows of cells in a table, nodes in a tree, cards on a shelf. Each row and card is your own; to show the library’s own songs and albums, use its items ([The library](/docs/develop/components/library/)).

Each picture is the SDK’s own test tree for the component, drawn by the web app; every app draws the same tree with its own controls, the phones natively. Each example is the one in the SDK’s doc comment, which its tests compile, and the props are read from its types.

## List [#list]

<Shot name="gallery/list" alt="A list titled Loved lately: rows with a cover, a badge and a switch" />

Rows, as a block: a `list` node, its rows its children. Its empty state
is `emptyTitle`, `emptyText` and `emptyIcon`.

```tsx
import { List, SongItem } from 'songstress/ui'

const songIds = ['s1', 's2', 's3']
const recent = (
  <List title="Played lately" emptyTitle="Nothing played yet" emptyIcon="music">
    {songIds.map((id) => <SongItem key={id} id={id} />)}
  </List>
)
```

A `List`'s props: its rows are its children (`ListItem`, `SongItem`, or
hand-written rows).

| Field | Type | Description |
|---|---|---|
| `emptyTitle?` | `string \| undefined` | What it says with no rows. Left out, "Nothing here yet". |
| `emptyText?` | `string \| undefined` | A sentence more, with no rows. |
| `emptyIcon?` | `IconName \| undefined` | An icon, with no rows. |
| `children?` | `UiNode` | Its rows. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |
| `title?` | `string \| undefined` | A heading over the rows. |

### ListItem [#listitem]

A row of a `List`: a `row` node, `onPress` its `action`.

```tsx
import { Badge, List, ListItem } from 'songstress/ui'

const stations = (
  <List>
    <ListItem id="night" title="Night radio" subtitle="Slow songs, after ten" icon="radio" trailing={<Badge>New</Badge>} onPress={{ type: 'navigate', to: { page: 'night' } }} />
  </List>
)
```

A `ListItem`'s props: a `row` node.

| Field | Type | Description |
|---|---|---|
| `onPress?` | `Handler<void> \| undefined` | What pressing it does. |
| `leading?` | `UiNode` | What stands at its start: one `Glyph`, `Image`, `Cover` or `Sprite`. |
| `trailing?` | `UiNode` | What stands at its end: one `Text`, `Badge`, `Glyph`, `Progress`, `Switch`, `IconButton` or `Button`. |
| `badge?` | `UiNode` | A short word at its end: one `Badge`. |
| `menu?` | `UiNode` | More to do with it: `MenuOption` elements. |
| `id` | `string` | Unique among the rows of its list. |
| `title` | `string` | Its title. |
| `subtitle?` | `string \| undefined` | A line under the title. |
| `icon?` | `IconName \| undefined` | An icon from Songstress's icon set. |
| `image?` | `ImageSource \| undefined` | A picture beside it. |
| `disabled?` | `boolean \| undefined` | Shown, but it cannot be chosen. |

## Table [#table]

<Shot name="gallery/table" alt="A table of rows under its columns: text, a badge, progress and a time" />

Rows of cells under column headings: a `table` node.

```tsx
import { Table } from 'songstress/ui'

const top = (
  <Table
    columns={[{ id: 'song', title: 'Song' }, { id: 'plays', title: 'Plays', align: 'end' }]}
    rows={[{ id: 's1', cells: ['So What', 12] }, { id: 's2', cells: ['Blue in Green', 9] }]}
  />
)
```

A `Table`'s props.

| Field | Type | Description |
|---|---|---|
| `rows` | `TableRow[]` | The rows, at most 200. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |
| `columns` | `{ id: string; title: string; align?: 'start' \| 'end'; }[]` | The columns, one to eight. |
| `empty?` | `EmptyState \| undefined` | What it shows when it holds no rows. Left out, "Nothing here yet". |

## Tree [#tree]

<Shot name="gallery/tree" alt="A tree of nodes, one open on the nodes it holds" />

Nodes that hold nodes, as a block: a `tree` node, its top nodes its
children. A node's `open` is how it stands at first: the app keeps what the
person opens and closes, and tells `onExpand`.

```tsx
import { Tree, TreeItem } from 'songstress/ui'

// 2026 stands open at first; a tap closes it, and the handler is told.
const years = (
  <Tree onExpand={({ id, open }) => console.log(id, open)}>
    <TreeItem id="2026" title="2026" open>
      <TreeItem id="2026-11" title="November" subtitle="42 plays" />
    </TreeItem>
  </Tree>
)
```

A `Tree`'s props: its top nodes are its children (`TreeItem`, `SongItem`).

| Field | Type | Description |
|---|---|---|
| `onExpand?` | `Handler<{ id: string; open: boolean; }> \| undefined` | Told `{ id, open }` when the person opens or closes a node. The app keeps what the person chose: a node's `open` is how it stands at first, and a later tree's `open` does not take the choice back. |
| `children?` | `UiNode` | Its top nodes. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |

### TreeItem [#treeitem]

A node of a `Tree`: a `node` node, `onPress` its `action`, the nodes
under it its children.

```tsx
import { Tree, TreeItem } from 'songstress/ui'

// A node whose nodes come later: `expandable`, and the tree's onExpand loads them.
const folders = (
  <Tree onExpand={{ type: 'refresh' }}>
    <TreeItem id="jazz" title="Jazz" icon="folder" expandable />
  </Tree>
)
```

A `TreeItem`'s props: a tree's `node`; its children are the nodes under
it (`TreeItem`, `SongItem`).

| Field | Type | Description |
|---|---|---|
| `children?` | `UiNode` | The nodes under it. |
| `onPress?` | `Handler<void> \| undefined` | What pressing it does. |
| `leading?` | `UiNode` | What stands at its start: one `Glyph`, `Image`, `Cover` or `Sprite`. |
| `trailing?` | `UiNode` | What stands at its end: one `Text`, `Badge`, `Glyph`, `Progress`, `Switch`, `IconButton` or `Button`. |
| `badge?` | `UiNode` | A short word at its end: one `Badge`. |
| `menu?` | `UiNode` | More to do with it: `MenuOption` elements. |
| `id` | `string` | Unique in the tree. |
| `title` | `string` | Its title. |
| `subtitle?` | `string \| undefined` | A line under the title. |
| `icon?` | `IconName \| undefined` | An icon from Songstress's icon set. |
| `image?` | `ImageSource \| undefined` | A picture beside it. |
| `expandable?` | `boolean \| undefined` | It has nodes under it that are not given now: when the person opens it, the page is rendered again with its id in `RenderContext.node`, and the answer's `nodes` are drawn under it. Left out when `children` is given. |
| `open?` | `boolean \| undefined` | Open at first, on the web and the desktop; then the app keeps what the person opens and closes. A phone opens a node with nodes under it as a page of its own. |
| `disabled?` | `boolean \| undefined` | Shown, but it cannot be chosen. |

## Shelf [#shelf]

<Shot name="gallery/shelf" alt="A shelf titled For you: cards that scroll sideways" />

A row of cards that scrolls sideways: a `shelf` node, its cards its
children.

```tsx
import { MediaCard, Shelf } from 'songstress/ui'

const mixes = (
  <Shelf title="Mixes">
    <MediaCard id="night" title="Night radio" image={{ asset: 'images/night.png' }} onPress={{ type: 'navigate', to: { page: 'night' } }} />
    <MediaCard id="morning" title="Morning" image={{ asset: 'images/morning.png' }} onPress={{ type: 'navigate', to: { page: 'morning' } }} />
  </Shelf>
)
```

A `Shelf`'s props: its cards are its children (`MediaCard`, `SongItem`,
`AlbumItem`, `ArtistItem`, `PlaylistItem`).

| Field | Type | Description |
|---|---|---|
| `children?` | `UiNode` | Its cards, side by side. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |
| `title` | `string` | The shelf's heading. |

### MediaCard [#mediacard]

A card of the extension's own: a `card` node, `onPress` its `action`.

```tsx
import { MediaCard, Shelf } from 'songstress/ui'

const mixes = (
  <Shelf title="Mixes">
    <MediaCard id="night" title="Night radio" subtitle="Slow songs, after ten" image={{ asset: 'images/night.png' }} onPress={{ type: 'toast', message: 'Starting' }} />
  </Shelf>
)
```

A `MediaCard`'s props: a `card` node.

| Field | Type | Description |
|---|---|---|
| `onPress?` | `Handler<void> \| undefined` | What pressing it does. |
| `menu?` | `UiNode` | Its menu: `MenuOption` elements. |
| `grow?` | `boolean \| undefined` | In a horizontal stack, it takes the room left over. Elsewhere it does nothing. |
| `width?` | `Width \| undefined` | Across its parent, or as wide as what it holds. Left out, the block's own way. |
| `id` | `string` | Unique among the cards beside it. |
| `title` | `string` | Its title. |
| `subtitle?` | `string \| undefined` | A line under the title. |
| `image?` | `ImageSource \| undefined` | Its picture. |
