HapplyUI

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

NameLast 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

NameSessionsBooked %
Person oneCompany one
12892%
Person twoCompany two
9674%
Person threeCompany three
5461%
Person fourCompany four
1218%
<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

SessionAttendeesComments
Session one1,24086
Session two98054
Session three with a much longer name than the rest61241
Session four24012
<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.

PropTypeDefaultDescription
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.

PropTypeDefaultDescription

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.

PropTypeDefaultDescription

MetricList.Body

Holds the rows.

PropTypeDefaultDescription

MetricList.Row

One row. Give it one Entity and a Value per figure column.

PropTypeDefaultDescription

MetricList.Entity

The first cell: what the row is about. The label truncates and keeps its full text in title.

PropTypeDefaultDescription
mediaReactNode-The leading slot: an Avatar on a person, a thumbnail on a thing
labelstring-The name of the person or thing
sublabelstring-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.

PropTypeDefaultDescription

Previous
Section Toggle