Components
Metric List
The small table a card shows as a preview: who or what, and the figures beside it. A real table, so each column's width is written once on its header and every row follows it.
Installation
bunx @happlyui/cli@latest add metric-list
Dependencies
Registry dependencies
These are automatically installed when you add this component.
happly-ui-utils
Usage
import * as MetricList from "@/components/ui/metric-list"
<MetricList.Root>
<MetricList.Header>
<MetricList.Column>Name</MetricList.Column>
<MetricList.Column className="w-[120px]">Last activity</MetricList.Column>
</MetricList.Header>
<MetricList.Body>
<MetricList.Row>
<MetricList.Entity media={<Avatar.Root size="32" />} label="Person one" sublabel="Company one" />
<MetricList.Value>5d ago</MetricList.Value>
</MetricList.Row>
</MetricList.Body>
</MetricList.Root>
Examples
Default
A 32px avatar, a name with its sublabel, and one figure column. Values are passed already formatted, so a relative date or a fallback reads like any other figure.
Card title
| Name | Last activity |
|---|---|
| Person oneCompany one | No app activity |
| Person twoCompany two | 5d ago |
| Person threeCompany three | 2w ago |
| Person four | — |
<MetricList.Row>
<MetricList.Entity
media={<Avatar.Root size="32" color="gray" placeholderType="user" />}
label="Person one"
sublabel="Company one"
/>
<MetricList.Value>No app activity</MetricList.Value>
</MetricList.Row>
Two figures
Add a Column and a Value per figure. The width on the Column is a minimum for the cells under it, so the header and the rows cannot drift apart and a long value still fits on one line.
Card title
| Name | Sessions | Booked % |
|---|---|---|
| Person oneCompany one | 128 | 92% |
| Person twoCompany two | 96 | 74% |
| Person threeCompany three | 54 | 61% |
| Person fourCompany four | 12 | 18% |
<MetricList.Header>
<MetricList.Column>Name</MetricList.Column>
<MetricList.Column className="w-[88px]">Sessions</MetricList.Column>
<MetricList.Column className="w-[72px]">Booked %</MetricList.Column>
</MetricList.Header>
Compact
size="sm" for rows that are one line, such as a thumbnail and a title. Leave out sublabel and the row keeps a single line.
Card title
| Session | Attendees | Comments |
|---|---|---|
| Session one | 1,240 | 86 |
| Session two | 980 | 54 |
| Session three with a much longer name than the rest | 612 | 41 |
| Session four | 240 | 12 |
<MetricList.Root size="sm">
…
<MetricList.Entity
media={<span className="bg-bg-weak-50 h-5 w-9 shrink-0 rounded" />}
label="Session one"
/>
</MetricList.Root>
API Reference
MetricList.Root
The table. Fills its container's width and spaces its rows; it does not scroll, so cap the rows you pass.
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'md' | 'sm' | 'md' | 'md' for rows carrying an avatar and a sublabel, 'sm' for single-line rows |
MetricList.Header
The row of column labels. No rule and no band, as the design draws it. Renders its children as one row.
| Prop | Type | Default | Description |
|---|
MetricList.Column
One column's label. The first column takes the slack; the rest align to the end. A width set with className is a minimum — the column grows if a value needs more, and the first column gives up the difference.
| Prop | Type | Default | Description |
|---|
MetricList.Body
Holds the rows.
| Prop | Type | Default | Description |
|---|
MetricList.Row
One row. Give it one Entity and a Value per figure column.
| Prop | Type | Default | Description |
|---|
MetricList.Entity
The first cell: what the row is about. The label truncates and keeps its full text in title.
| Prop | Type | Default | Description |
|---|---|---|---|
media | ReactNode | - | The leading slot: an Avatar on a person, a thumbnail on a thing |
label | string | - | The name of the person or thing |
sublabel | string | - | Under the label, in the quieter colour. Leave it out and the row is one line |
MetricList.Value
One figure, aligned to the end with tabular digits. Pass it already formatted — a count, a duration, a percentage or a fallback all read the same.
| Prop | Type | Default | Description |
|---|