Rost

← All components

component

Table

Rows of the same kind of thing, side by side in columns, like the accounting app's payments. No box, a hairline between rows.

In code Contract: review Guidance: agreed Contract on GitHub Figma 527:596 As markdown
What to pay, and when
URSSAF31 OctQ3 contributions€1,284
Income tax15 NovInstalment 2 of 3estimate€640
URSSAF31 JanQ4 contributionsestimate€1,310
With a caption
Rows as links
PaymentAmount
URSSAF31 OctQ3 contributions€1,284
Income tax15 NovInstalment 2 of 3estimate€640
URSSAF31 JanQ4 contributionsestimate€1,310
With column headers

Install

npx github:Runceanu/rost add table

It lands in src/rost/table/, with what it needs and its contract. Install has the rest.

When to use

  • Data read across

    Several things of the same kind with the same few facts each, read across: payments with a date, what they're for and an amount.

  • Columns that mean something

    When the columns mean something: an amount in the same place on every row, so the eye runs down them.

When not to use

  • One fact each

    A list of things to pick or go to, one fact each. That's ListItem.

    Use ListItem

  • Laying out a page

    Laying out a page or a form. A table is for data.

  • Too many columns

    More columns than fit on a phone. Two or three is right: put the rest in the row's description, the way the accounting app puts "leaves €4,210" under the date.

Behaviour

The table draws nothing itself. Each TableRow draws a hairline under it, the last one too, so the table has an end. Rows that are links or can be picked react to the pointer; the others don't. Sorting: give a column header sort and onSort, and its words become a button with an arrow on the sorted column. The sorting itself is the app's: Rost draws the header and says which way it's sorted. Picking several rows: a Checkbox in each row's first cell, named for its row ("Select Client One"), and the row selected while it's ticked. A Checkbox in the first column header picks them all; it's indeterminate while only some are picked. A row that's a link or a button already uses its header cell, so a table either picks rows with checkboxes or opens them, not both.

Accessibility

  • Element

    a <table> with a <caption>, a <thead> when there are column headers and a <tbody>. Each row's first cell is usually its header (<th scope="row">), so a screen reader names the row when it reads an amount. A sorted column header has aria-sort (ascending or descending), so a screen reader says how the table is ordered; the others have aria-sort="none".

  • Name

    the caption. Without one, an aria-label or aria-labelledby on the table.

  • Keyboard

    nothing of its own. A row that's a link or a button is one Tab stop, through its header cell. A sortable column header is a button: Tab reaches it, Enter or Space sorts. A row's Checkbox is its own Tab stop.

  • Focus

    TableRow's focus ring, on the whole row.

Content

A caption in sentence case, a few words. Column headers are one or two words.

Props

PropTypeValuesDefault
caption slot
head slot
rows slot

Values

Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.

Never changes

root

  • font-family 'General Sans Variable' font-family/base
  • font-weight 400 typography/paragraph/font-weight/regular
  • font-size 14px typography/paragraph/font-size
  • line-height 20px typography/paragraph/line-height
  • letter-spacing 0px typography/paragraph/letter-spacing
  • color #ededed non-interactive/foreground/primary

width100% · border-collapsecollapse

caption

  • padding-left 12px spacing/gap/small-medium
  • padding-right 12px spacing/gap/small-medium
  • padding-bottom 8px spacing/gap/small
  • font-weight 500 typography/paragraph/font-weight/medium
  • color #ededed non-interactive/foreground/primary

caption-sidetop · text-alignleft

head

vertical-alignbottom

body

vertical-alignmiddle

Part of Table

TableItem

One cell of a TableRow. Its content with an optional line under it, and leading and trailing slots for a Badge or an icon.

In code Contract: review Guidance: agreed Contract on GitHub Figma 527:126 As markdown
labelLabelDescriptionlabel
None · Not numeric · None
labelLabelDescriptionlabel
None · Numeric · None
labelLabelDescriptionlabel
Row · Not numeric · None
labelLabelDescriptionlabel
Row · Numeric · None
labelLabelDescriptionlabel
Column · Not numeric · None
labelLabelDescriptionlabel
Column · Numeric · None
Column · Not numeric · Ascending
Column · Not numeric · Descending

Install

npx github:Runceanu/rost add table-item

It lands in src/rost/table-item/, with what it needs and its contract. Install has the rest.

When to use

  • Every cell

    Every cell of a TableRow.

  • Leading and trailing

    leading for what kind of thing the row is (a Badge), trailing for a note on this one value (an estimate Badge).

  • Amounts

    numeric for every amount, and on that column's header.

When not to use

Behaviour

A cell doesn't react. In a row with href or onSelect the header cell holds the link or button, and the row draws hover, press and focus for it.

Accessibility

  • Element

    <td>, or <th> with scope="row" or scope="col" from header.

  • Name

    a row's header cell names its row for screen readers, and names its link or button. A Badge in leading or trailing is read with the cell. An icon there should be aria-hidden; if it means something, say it in words too.

  • Keyboard

    nothing of its own. See TableRow.

  • Focus

    none of its own. The row draws the ring.

Content

Short. A date, a name, an amount. The description is one line.

Props

PropTypeValuesDefault
content slot
description slot
leading slot
trailing slot
header enum None · Row · Column None
numeric boolean false
sort enum None · Ascending · Descending None

States: Default, Highlighted, SelectedRow, SortHover, SortFocus.

Values

Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.

Never changes

root

  • padding-top 8px spacing/gap/small
  • padding-bottom 8px spacing/gap/small
  • padding-left 12px spacing/gap/small-medium
  • padding-right 12px spacing/gap/small-medium

text-alignleft · font-weightinherit

action

displayblock · width100% · padding0 · backgroundnone · bordernone · colorinherit · fontinherit · text-aligninherit · text-decorationnone · cursorpointer · outlinenone

cover

positionabsolute · inset0

sort

  • gap 4px spacing/gap/2xsmall
  • border-radius 4px spacing/radius/xsmall

displayinline-flex · align-itemscenter · padding0 · bordernone · backgroundnone · colorinherit · fontinherit · text-aligninherit · cursorpointer · outlinenone

sort-icon

  • width 16px spacing/size/2xsmall
  • height 16px spacing/size/2xsmall

displayblock · flex-shrink0 · backgroundcurrentColor · mask-size100% 100% · mask-repeatno-repeat

content

  • gap 8px spacing/gap/small

displayflex · align-itemscenter

leading

displayflex · align-itemscenter · flex-shrink0

text

  • gap 2px spacing/gap/3xsmall

displayflex · flex-directioncolumn · min-width0

label

overflow-wrapanywhere

description

  • font-weight 400 typography/label/font-weight/regular
  • font-size 12px typography/label/font-size
  • line-height 14px typography/label/line-height
  • letter-spacing 0px typography/label/letter-spacing
  • color #999999 table-item/sub-label

trailing

displayflex · align-itemscenter · flex-shrink0

Changes by variant

10 variants. Each table is what one thing changes with: a column per header, a row per property. Where every row starts with the same token path, it's written once, under the property.

Follows header

In 2 variants

PropertyRowColumn
label.font-weighttypography/… paragraph/font-weight/medium 500 label/font-weight/medium 500

Follows sort

In 2 variants

PropertyAscendingDescending
sort-icon.mask-image url(./icon-arrow-up.svg) url(./icon-arrow-down.svg)

Only in some variants

These don't change: they're just set in some variants and not others.

Numeric

  • content.justify-content flex-end layout
  • label.white-space nowrap layout
  • root.text-align right layout
  • text.align-items flex-end layout

Highlighted

  • description.color #ededed table-item/highlighted/sub-label

Column

  • label.font-size 12px typography/label/font-size
  • label.letter-spacing 0px typography/label/letter-spacing
  • label.line-height 14px typography/label/line-height
  • root.padding-bottom 4px spacing/gap/2xsmall
  • root.padding-top 4px spacing/gap/2xsmall
  • root.vertical-align bottom layout

SelectedRow

  • root.box-shadow inset var(--spacing-outline-medium) 0 0 0 var(--table-item-selected-row-edge) on purpose: Composed from tokens: a 2px bar down the left of a selected row's first cell. The row's dark green fill is 2:1 against the page, under the 3:1 a selected row needs to be seen (WCAG 1.4.11); the bar is 10:1 in dark and 6:1 in light. A `<tr>` can't draw it, so its first cell does.

None

  • sort-icon.display none layout

SortFocus

  • sort.outline var(--spacing-outline-medium) solid var(--table-item-sort-focus-ring) on purpose: Composed from tokens: a 2px ring in table-item/sort/focus-ring.
  • sort.outline-offset 2px spacing/gap/3xsmall

SortHover

  • sort.text-decoration underline Figma frame size
  • sort.text-underline-offset 2px spacing/gap/3xsmall

Part of Table

TableRow

One row of a Table, with a hairline under it. It can be a link or something you pick, through its header cell.

In code Contract: review Guidance: agreed Contract on GitHub Figma 527:483 As markdown
Default · Not selected
Default · Selected

Hover, press or tab to one to see the other 6 states.

Install

npx github:Runceanu/rost add table-row

It lands in src/rost/table-row/, with what it needs and its contract. Install has the rest.

When to use

When not to use

  • Controls in a linked row

    Links or buttons in several cells of a row that's itself a link. The cover sits over them. Pick one: the row, or the controls.

  • A status as a fill

    Showing a status with the fill. selected means picked; a status is a Badge in a cell.

    Use Badge

Behaviour

A row with href or onSelect is one target: the pointer anywhere on it hovers and presses it, and focus draws a ring round the whole row. A plain row doesn't react. selected keeps its fill on hover, a shade lighter.

Accessibility

  • Element

    a <tr>. The link or button lives in the row's header cell, because a <tr> can't be one. Its cover stretches over the row, so the whole row is the target.

  • Name

    the header cell's content: the link or button is named by what's in it, a date or a client's name. Make that cell say which row it is.

  • Keyboard

    a linked row is one Tab stop. Enter follows the link; Enter or Space presses the button.

  • Focus

    a 2px ring inside the row, on :focus-visible of its link or button.

Content

One thing per row. The header cell names it.

Props

PropTypeValuesDefault
items slot
href string
selected boolean false

States: Default, Hover, Pressed, Focus.

Values

Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.

Never changes

root

  • height 48px spacing/size/medium-large
  • border-width 1px spacing/outline/small
  • border-color #282828 table-row/divider

positionrelative · border-sidesbottom

Changes by variant

5 variants. Each table is what one thing changes with: a column per state, a row per property. Where every row starts with the same token path, it's written once, under the property.

Follows state and selected

Selected

PropertyDefaultHoverPressed
root.backgroundtable-row/selected/… default/background #004c19 hover/background #006f27·

Not selected

PropertyDefaultHoverPressed
root.backgroundtable-row/unselected/… · hover/background #171717 pressed/background #3a3a3a

Only in some variants

These don't change: they're just set in some variants and not others.

Focus

  • root.outline-color #999999 table-row/focus/focus-ring
  • root.outline-offset -2px on purpose: Inside the row, the ring's own width, so it isn't cut by the rows around it.
  • root.outline-style solid Figma frame size
  • root.outline-width 2px spacing/outline/medium