Data
Table
Rows and columns, laid out and announced like a native table, that components can render into. Column headers can be buttons that sort.
- Element
<slab-table>- Built on
[role=table] + rowgroups, rows and cells
Example
Here's a styled version, <slab-styled-table>. It's not
in the package — it's an example of what you can build with the
headless element. Copy it and make it yours at the
bottom of this page. Switch to "As it ships" to see the same markup
with the headless element and no CSS at all. That's your starting
point.
<slab-styled-table aria-label="Pours">
<slab-styled-table-head>
<slab-styled-table-row>
<slab-styled-table-column-header sortable sort="ascending">Slab</slab-styled-table-column-header>
<slab-styled-table-column-header sortable>Yards</slab-styled-table-column-header>
<slab-styled-table-column-header sortable>Poured</slab-styled-table-column-header>
</slab-styled-table-row>
</slab-styled-table-head>
<slab-styled-table-body>
<slab-styled-table-row>
<slab-styled-table-cell row-header>Driveway</slab-styled-table-cell>
<slab-styled-table-cell>12</slab-styled-table-cell>
<slab-styled-table-cell>2026-09-14</slab-styled-table-cell>
</slab-styled-table-row>
<slab-styled-table-row>
<slab-styled-table-cell row-header>Garage</slab-styled-table-cell>
<slab-styled-table-cell>18</slab-styled-table-cell>
<slab-styled-table-cell>2026-08-30</slab-styled-table-cell>
</slab-styled-table-row>
<slab-styled-table-row>
<slab-styled-table-cell row-header>Patio</slab-styled-table-cell>
<slab-styled-table-cell>8</slab-styled-table-cell>
<slab-styled-table-cell>2026-10-02</slab-styled-table-cell>
</slab-styled-table-row>
</slab-styled-table-body>
<slab-styled-table-foot>
<slab-styled-table-row>
<slab-styled-table-cell row-header>Total</slab-styled-table-cell>
<slab-styled-table-cell>38</slab-styled-table-cell>
<slab-styled-table-cell></slab-styled-table-cell>
</slab-styled-table-row>
</slab-styled-table-foot>
</slab-styled-table>
<slab-table aria-label="Pours">
<slab-table-head>
<slab-table-row>
<slab-table-column-header sortable sort="ascending">Slab</slab-table-column-header>
<slab-table-column-header sortable>Yards</slab-table-column-header>
<slab-table-column-header sortable>Poured</slab-table-column-header>
</slab-table-row>
</slab-table-head>
<slab-table-body>
<slab-table-row>
<slab-table-cell row-header>Driveway</slab-table-cell>
<slab-table-cell>12</slab-table-cell>
<slab-table-cell>2026-09-14</slab-table-cell>
</slab-table-row>
<slab-table-row>
<slab-table-cell row-header>Garage</slab-table-cell>
<slab-table-cell>18</slab-table-cell>
<slab-table-cell>2026-08-30</slab-table-cell>
</slab-table-row>
<slab-table-row>
<slab-table-cell row-header>Patio</slab-table-cell>
<slab-table-cell>8</slab-table-cell>
<slab-table-cell>2026-10-02</slab-table-cell>
</slab-table-row>
</slab-table-body>
<slab-table-foot>
<slab-table-row>
<slab-table-cell row-header>Total</slab-table-cell>
<slab-table-cell>38</slab-table-cell>
<slab-table-cell></slab-table-cell>
</slab-table-row>
</slab-table-foot>
</slab-table>
Usage
pnpm add slab-elements lit
import 'slab-elements/table.js';
import 'slab-elements/table.head.js';
import 'slab-elements/table.body.js';
import 'slab-elements/table.foot.js';
import 'slab-elements/table.row.js';
import 'slab-elements/table.column-header.js';
import 'slab-elements/table.cell.js';
export function MyTable() {
return (
<h2 id="caption">Pours</h2>
<slab-table aria-labelledby="caption">
<slab-table-head>
<slab-table-row>
<slab-table-column-header sortable sort="ascending">Slab</slab-table-column-header>
<slab-table-column-header sortable>Yards</slab-table-column-header>
</slab-table-row>
</slab-table-head>
<slab-table-body>
<slab-table-row>
<slab-table-cell row-header>Driveway</slab-table-cell>
<slab-table-cell>12</slab-table-cell>
</slab-table-row>
<slab-table-row>
<slab-table-cell row-header>Patio</slab-table-cell>
<slab-table-cell>8</slab-table-cell>
</slab-table-row>
</slab-table-body>
</slab-table>
);
}
MyTable.jsx React 19 or later, which sets props on custom elements as properties.
import 'slab-elements/table.js';
import 'slab-elements/table.head.js';
import 'slab-elements/table.body.js';
import 'slab-elements/table.foot.js';
import 'slab-elements/table.row.js';
import 'slab-elements/table.column-header.js';
import 'slab-elements/table.cell.js';
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
@customElement('my-table')
export class MyTable extends LitElement {
render() {
return html`
<h2 id="caption">Pours</h2>
<slab-table aria-labelledby="caption">
<slab-table-head>
<slab-table-row>
<slab-table-column-header sortable sort="ascending">Slab</slab-table-column-header>
<slab-table-column-header sortable>Yards</slab-table-column-header>
</slab-table-row>
</slab-table-head>
<slab-table-body>
<slab-table-row>
<slab-table-cell row-header>Driveway</slab-table-cell>
<slab-table-cell>12</slab-table-cell>
</slab-table-row>
<slab-table-row>
<slab-table-cell row-header>Patio</slab-table-cell>
<slab-table-cell>8</slab-table-cell>
</slab-table-row>
</slab-table-body>
</slab-table>
`;
}
}
my-table.ts Slab is built on Lit, so its elements are at home in Lit's templates.
<script setup>
import 'slab-elements/table.js';
import 'slab-elements/table.head.js';
import 'slab-elements/table.body.js';
import 'slab-elements/table.foot.js';
import 'slab-elements/table.row.js';
import 'slab-elements/table.column-header.js';
import 'slab-elements/table.cell.js';
</script>
<template>
<h2 id="caption">Pours</h2>
<slab-table aria-labelledby="caption">
<slab-table-head>
<slab-table-row>
<slab-table-column-header sortable sort="ascending">Slab</slab-table-column-header>
<slab-table-column-header sortable>Yards</slab-table-column-header>
</slab-table-row>
</slab-table-head>
<slab-table-body>
<slab-table-row>
<slab-table-cell row-header>Driveway</slab-table-cell>
<slab-table-cell>12</slab-table-cell>
</slab-table-row>
<slab-table-row>
<slab-table-cell row-header>Patio</slab-table-cell>
<slab-table-cell>8</slab-table-cell>
</slab-table-row>
</slab-table-body>
</slab-table>
</template>
MyTable.vue Let Vue's compiler know slab- tags are custom elements with isCustomElement.
<script>
import 'slab-elements/table.js';
import 'slab-elements/table.head.js';
import 'slab-elements/table.body.js';
import 'slab-elements/table.foot.js';
import 'slab-elements/table.row.js';
import 'slab-elements/table.column-header.js';
import 'slab-elements/table.cell.js';
</script>
<h2 id="caption">Pours</h2>
<slab-table aria-labelledby="caption">
<slab-table-head>
<slab-table-row>
<slab-table-column-header sortable sort="ascending">Slab</slab-table-column-header>
<slab-table-column-header sortable>Yards</slab-table-column-header>
</slab-table-row>
</slab-table-head>
<slab-table-body>
<slab-table-row>
<slab-table-cell row-header>Driveway</slab-table-cell>
<slab-table-cell>12</slab-table-cell>
</slab-table-row>
<slab-table-row>
<slab-table-cell row-header>Patio</slab-table-cell>
<slab-table-cell>8</slab-table-cell>
</slab-table-row>
</slab-table-body>
</slab-table>
MyTable.svelte Svelte binds properties and events to custom elements like any other element.
import 'slab-elements/table.js';
import 'slab-elements/table.head.js';
import 'slab-elements/table.body.js';
import 'slab-elements/table.foot.js';
import 'slab-elements/table.row.js';
import 'slab-elements/table.column-header.js';
import 'slab-elements/table.cell.js';
export const MyTable = <template>
<h2 id="caption">Pours</h2>
<slab-table aria-labelledby="caption">
<slab-table-head>
<slab-table-row>
<slab-table-column-header sortable sort="ascending">Slab</slab-table-column-header>
<slab-table-column-header sortable>Yards</slab-table-column-header>
</slab-table-row>
</slab-table-head>
<slab-table-body>
<slab-table-row>
<slab-table-cell row-header>Driveway</slab-table-cell>
<slab-table-cell>12</slab-table-cell>
</slab-table-row>
<slab-table-row>
<slab-table-cell row-header>Patio</slab-table-cell>
<slab-table-cell>8</slab-table-cell>
</slab-table-row>
</slab-table-body>
</slab-table>
</template>;
MyTable.gjs Ember sets attributes, and a dynamic value like {{this.max}} sets the property when the element has one. {{on}} listens for any event by its name.
<script type="module">
import 'slab-elements/table.js';
import 'slab-elements/table.head.js';
import 'slab-elements/table.body.js';
import 'slab-elements/table.foot.js';
import 'slab-elements/table.row.js';
import 'slab-elements/table.column-header.js';
import 'slab-elements/table.cell.js';
</script>
<h2 id="caption">Pours</h2>
<slab-table aria-labelledby="caption">
<slab-table-head>
<slab-table-row>
<slab-table-column-header sortable sort="ascending">Slab</slab-table-column-header>
<slab-table-column-header sortable>Yards</slab-table-column-header>
</slab-table-row>
</slab-table-head>
<slab-table-body>
<slab-table-row>
<slab-table-cell row-header>Driveway</slab-table-cell>
<slab-table-cell>12</slab-table-cell>
</slab-table-row>
<slab-table-row>
<slab-table-cell row-header>Patio</slab-table-cell>
<slab-table-cell>8</slab-table-cell>
</slab-table-row>
</slab-table-body>
</slab-table>
index.html Any bundler (or an import map) takes care of the imports.
A native <table> can only hold its own elements, so a component that renders a row or a cell can’t go in one. Table and its parts can. Each is laid out as the element it stands for, display: table-row for a Table Row and so on, so columns size to fit their content and line up across the head, body and foot, and each has that element’s role. Table Head goes first and Table Foot last, wherever they are in the markup.
Name the Table as you would a native one, with aria-labelledby pointing at a heading or caption near it, or with aria-label. Give the Cell that says what a row is about, such as a name, row-header, and it becomes the row’s header, like a <th scope="row">, so a screenreader moving down a column reads each Cell with it.
A sortable Column Header is a <button>. Clicking it sorts its column ascending, or descending when it’s already ascending, sets sort, and dispatches “sort” from the Column Header. Every other Column Header in its Table goes back to sort="none" first, so only one column is sorted, and only it has aria-sort. Screenreaders are told how it’s sorted, “Sorted by Yards, descending”, which you can word with sortedLabel or tableSorted in registerStrings(). Put an arrow in its sort-indicator slot, or draw one on :state(ascending) and :state(descending).
Sorting the rows is yours, since Table doesn’t move them: on “sort”, put the Table Body’s rows in the order the Column Header’s sort says, as the example above does, or sort your data and let your framework render it. Set sort yourself for a Table that starts out sorted.
It’s a table, not a grid. It’s read, not moved through with the arrow keys, and only a sortable Column Header’s button and what you put in a Cell take focus. Cells can’t span columns or rows.
Keyboard
| Key | What it does |
|---|---|
| Tab | Moves to each sortable Column Header, then to what’s in the Cells. |
| Enter, Space | On a sortable Column Header, sorts its column. |
Behavior
<slab-table>
A Table with no visual styles: a [role=table] of rows and columns, laid out like a native <table>, with Column Headers that can sort.
A native <table> can only hold its own elements, so a component that renders rows or cells can't go in one. Table and its parts can: a Table Head, Body and Foot, each with Table Rows, which hold Column Headers or Cells. Each is laid out as the element it stands for, so columns size to fit their content, and each has that element's role.
Name the Table with aria-labelledby, pointing at a heading or caption near it, or with aria-label.
Clicking a sortable Column Header sorts its column and dispatches "sort" from it. Table makes every other Column Header unsorted first, so only one column is sorted at a time. Sorting the rows is yours.
It's a table, not a grid: it's read rather than moved through with the arrow keys, and the only things in it that take focus are a sortable Column Header's button and whatever you put in a Cell.
<slab-table-head>
A Table Head with no visual styles: a [role=rowgroup] around the header rows, such as the row of Column Headers. It goes first in its Table, wherever it is in the markup, as a <thead> does.
<slab-table-body>
A Table Body with no visual styles: a [role=rowgroup] around the body rows, holding the data.
<slab-table-foot>
A Table Foot with no visual styles: a [role=rowgroup] around the footer rows, such as totals. It goes last in its Table, wherever it is in the markup, as a <tfoot> does.
<slab-table-row>
A Table Row with no visual styles: a [role=row] of Column Headers or Cells, in a Table Head, Body or Foot.
<slab-table-column-header>
A Table Column Header with no visual styles: a [role=columnheader] that names its column, in a Table Head's row.
With sortable, its content is a <button>. Clicking it sorts the column ascending, or descending when it's already ascending, sets sort and dispatches "sort". Its Table sets every other Column Header's sort to "none", so only one column is sorted at a time, and screenreaders are told how it's sorted now.
Sorting the rows is yours: on "sort", put the Table Body's rows in the order sort says. Slab doesn't move them, so a framework that renders the rows stays in charge of them.
aria-sort follows sort, and is left off while it's "none", since only the sorted column should have it. Set sort yourself for a Table that starts out sorted.
Style it through its parts and :state(ascending), :state(descending) and :state(sortable).
<slab-table-cell>
A Table Cell with no visual styles: a [role=cell] in a Table Row, or a [role=rowheader] with row-header.
A row header names its row, as a Column Header names its column, so a screenreader moving down a column reads each Cell with its row's header. Make the Cell that says what the row is about, such as a name, the row header.
API
<slab-table>
| Name | Type | Description |
|---|---|---|
columnHeaders
Read-only
|
TableColumnHeader[] |
Its Column Headers, in order. |
| Name | Type | Description |
|---|---|---|
(default)
|
TableBody | TableFoot | TableHead |
The Table Head, Body and Foot |
<slab-table-head>
| Name | Type | Description |
|---|---|---|
(default)
|
TableRow |
The header rows |
<slab-table-body>
| Name | Type | Description |
|---|---|---|
(default)
|
TableRow |
The body rows |
<slab-table-foot>
| Name | Type | Description |
|---|---|---|
(default)
|
TableRow |
The footer rows |
<slab-table-row>
| Name | Type | Description |
|---|---|---|
(default)
|
TableCell | TableColumnHeader |
The row's Cells, or its Column Headers |
<slab-table-column-header>
| Name | Type | Default | Description |
|---|---|---|---|
sort
|
'ascending' | 'descending' | 'none' |
'none' |
How the column is sorted. Sets aria-sort. |
sortable
|
boolean |
false |
Makes the Column Header a button that sorts the column. |
| Name | Type | Description |
|---|---|---|
sortedLabel
|
(column: string, sort: 'ascending' | 'descending') => string |
What screenreaders are told when the user sorts the column, from its name and sort. "Sorted by", the name and the direction in English when unset. |
| Name | Type | Description |
|---|---|---|
sort
|
Event |
When the user presses the button to sort by its column. Set sort in your handler. |
| Name | Type | Description |
|---|---|---|
(default)
|
Element | string |
The column's name |
sort-indicator
|
Element | string |
Shown after the name in a sortable Column Header, such as an arrow, and hidden from screenreaders |
| Name | Description |
|---|---|
label
|
Holds the name in a sortable Column Header |
sort-button
|
The button in a sortable Column Header |
sort-indicator
|
Holds the sort indicator in a sortable Column Header, hidden from screenreaders |
| Name | Description |
|---|---|
:state(ascending)
|
While the table is sorted by it, ascending. |
:state(descending)
|
While the table is sorted by it, descending. |
:state(sortable)
|
While it's sortable. |
<slab-table-cell>
| Name | Type | Default | Description |
|---|---|---|---|
row-header
|
boolean |
false |
Makes the Cell its row's header, like a <th scope="row">. |
| Name | Type | Description |
|---|---|---|
(default)
|
Element | string |
The Cell's content |
Copy and own it
<slab-styled-table> isn't in the package. It's an example —
copy it into your project and change whatever you want. Keyboard,
focus, ARIA, forms, and events all come from the headless element,
and the styles only reach in through ::part() and
:state(), same as yours would.
The same styles, written from outside the element, so
there's nothing to subclass. The CSS styles every
<slab-table> on the page. Import
tokens.css, the colors and fonts every styled
example shares, once, wherever your global styles go.
Each component registers its headless element and imports its CSS. Use it like the element: its props are the element's attributes and properties.
Table.jsx
import 'slab-elements/table.js';
import './table.css';
import 'slab-elements/table.head.js';
import './table.head.css';
import 'slab-elements/table.body.js';
import './table.body.css';
import 'slab-elements/table.foot.js';
import './table.foot.css';
import 'slab-elements/table.row.js';
import './table.row.css';
import 'slab-elements/table.column-header.js';
import './table.column-header.css';
import 'slab-elements/table.cell.js';
import './table.cell.css';
export function Table(props) {
return <slab-table {...props} />;
}
export function TableHead(props) {
return <slab-table-head {...props} />;
}
export function TableBody(props) {
return <slab-table-body {...props} />;
}
export function TableFoot(props) {
return <slab-table-foot {...props} />;
}
export function TableRow(props) {
return <slab-table-row {...props} />;
}
export function TableColumnHeader(props) {
return <slab-table-column-header {...props} />;
}
export function TableCell(props) {
return <slab-table-cell {...props} />;
}
table.css
slab-table {
background-color: var(--paper);
border: var(--border);
border-collapse: collapse;
box-shadow: var(--shadow);
color: var(--ink);
font-family: var(--font-body);
font-size: 0.9375rem;
font-variant-numeric: tabular-nums;
inline-size: 100%;
line-height: 1.4;
}
table.head.css
slab-table-head {
background-color: var(--chalk);
border-block-end: var(--border);
}
table.body.css
slab-table-body > :hover {
background-color: var(--chalk);
}
table.foot.css
slab-table-foot {
border-block-start: var(--border);
font-weight: 600;
}
table.row.css
slab-table-row {
border-block-end: 1px solid var(--ash);
}
slab-table-row:last-child {
border-block-end: none;
}
table.column-header.css
slab-table-column-header {
font-family: var(--font-display);
font-weight: 700;
letter-spacing: 0.04em;
padding: 0.625rem 0.75rem;
text-align: start;
text-transform: uppercase;
vertical-align: bottom;
white-space: nowrap;
}
slab-table-column-header::part(sort-button) {
align-items: center;
background: none;
border: none;
color: inherit;
cursor: pointer;
display: inline-flex;
font: inherit;
gap: 0.375rem;
letter-spacing: inherit;
margin: 0;
padding: 0;
text-align: inherit;
text-transform: inherit;
}
slab-table-column-header::part(sort-button):hover {
text-decoration-color: var(--ember);
text-decoration-line: underline;
text-decoration-thickness: 2px;
text-underline-offset: 0.3em;
}
slab-table-column-header::part(sort-button):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 3px;
}
slab-table-column-header::part(sort-indicator) {
color: var(--ash);
}
slab-table-column-header::part(sort-indicator)::before {
content: '↕';
}
slab-table-column-header:state(ascending)::part(sort-indicator),
slab-table-column-header:state(descending)::part(sort-indicator) {
color: var(--ember-deep);
}
slab-table-column-header:state(ascending)::part(sort-indicator)::before {
content: '↑';
}
slab-table-column-header:state(descending)::part(sort-indicator)::before {
content: '↓';
}
table.cell.css
slab-table-cell {
padding: 0.625rem 0.75rem;
text-align: start;
vertical-align: top;
}
slab-table-cell[row-header] {
font-weight: 600;
}
tokens.css
:root {
/* Secondary text. 6.8:1 and 6.9:1 on paper. */
--ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
--border: 2px solid var(--ink);
/* Behind disabled and read-only controls, and hovered rows. */
--chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));
/*
The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
enough for borders, fills and large text, but not always for small text,
which takes "--ember-deep".
*/
--ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));
/*
Orange for small text on paper, and for paper text on it. 5.7:1 and
7.4:1.
*/
--ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
--font-body: var(
--slab-styled-font-body,
'IBM Plex Sans',
system-ui,
sans-serif
);
--font-display: var(
--slab-styled-font-display,
'Zilla Slab',
rockwell,
'Roboto Slab',
serif
);
--font-mono: var(
--slab-styled-font-mono,
'IBM Plex Mono',
ui-monospace,
monospace
);
--ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
--paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));
/* The hard, offset shadow a raised surface casts. */
--shadow: 4px 4px 0 var(--ink);
}
/*
Forced colors, such as Windows' contrast themes, replace every color that
isn't a system color, so ember fills and paper marks all become the same
background, and a checked Checkbox looks like an unchecked one. The palette
becomes the user's system colors instead, which are kept. Ember is the
highlight, the color of what's selected, and ember-deep, being for text and
for paper text on it, is the text color.
*/
@media (forced-colors: active) {
:host {
--ash: GrayText;
--chalk: Canvas;
--ember: Highlight;
--ember-deep: CanvasText;
--ink: CanvasText;
--paper: Canvas;
}
}
Under the hood, it's just the headless element, subclassed,
with styles set. That's it. To use it, copy
these files, swap the tag in @customElement()
for one of your own, and import it.
tokens.styles.ts holds the colors and fonts
every styled example shares, so you only need it once.
table.ts
import { customElement } from 'lit/decorators.js';
import Table from 'slab-elements/table.js';
import styles from './table.styles.js';
import tokens from './tokens.styles.js';
declare global {
interface HTMLElementTagNameMap {
'slab-styled-table': StyledTable;
}
}
/**
* Table, styled: ink-ruled rows in a bordered, raised box, with figures that line up in their columns.
*/
@customElement('slab-styled-table')
export default class StyledTable extends Table {
static override styles = [tokens, styles];
}
table.styles.ts
import { css } from 'lit';
/*
Collapsed borders, so each row's rule and the box's border meet rather than
doubling up. Figures are tabular, so numbers line up down a column.
*/
export default css`
:host {
background-color: var(--paper);
border: var(--border);
border-collapse: collapse;
box-shadow: var(--shadow);
color: var(--ink);
font-family: var(--font-body);
font-size: 0.9375rem;
font-variant-numeric: tabular-nums;
inline-size: 100%;
line-height: 1.4;
}
`;
table.head.ts
import { customElement } from 'lit/decorators.js';
import TableHead from 'slab-elements/table.head.js';
import styles from './table.head.styles.js';
import tokens from './tokens.styles.js';
declare global {
interface HTMLElementTagNameMap {
'slab-styled-table-head': StyledTableHead;
}
}
/**
* Table Head, styled: chalk behind the Column Headers, with a heavy rule below them.
*/
@customElement('slab-styled-table-head')
export default class StyledTableHead extends TableHead {
static override styles = [tokens, styles];
}
table.head.styles.ts
import { css } from 'lit';
export default css`
:host {
background-color: var(--chalk);
border-block-end: var(--border);
}
`;
table.body.ts
import { customElement } from 'lit/decorators.js';
import TableBody from 'slab-elements/table.body.js';
import styles from './table.body.styles.js';
import tokens from './tokens.styles.js';
declare global {
interface HTMLElementTagNameMap {
'slab-styled-table-body': StyledTableBody;
}
}
/**
* Table Body, styled: chalk behind the row under the pointer.
*/
@customElement('slab-styled-table-body')
export default class StyledTableBody extends TableBody {
static override styles = [tokens, styles];
}
table.body.styles.ts
import { css } from 'lit';
export default css`
::slotted(:hover) {
background-color: var(--chalk);
}
`;
table.foot.ts
import { customElement } from 'lit/decorators.js';
import TableFoot from 'slab-elements/table.foot.js';
import styles from './table.foot.styles.js';
import tokens from './tokens.styles.js';
declare global {
interface HTMLElementTagNameMap {
'slab-styled-table-foot': StyledTableFoot;
}
}
/**
* Table Foot, styled: a heavy rule above semibold rows, for totals.
*/
@customElement('slab-styled-table-foot')
export default class StyledTableFoot extends TableFoot {
static override styles = [tokens, styles];
}
table.foot.styles.ts
import { css } from 'lit';
export default css`
:host {
border-block-start: var(--border);
font-weight: 600;
}
`;
table.row.ts
import { customElement } from 'lit/decorators.js';
import TableRow from 'slab-elements/table.row.js';
import styles from './table.row.styles.js';
import tokens from './tokens.styles.js';
declare global {
interface HTMLElementTagNameMap {
'slab-styled-table-row': StyledTableRow;
}
}
/**
* Table Row, styled: a thin ash rule below each row but the last.
*/
@customElement('slab-styled-table-row')
export default class StyledTableRow extends TableRow {
static override styles = [tokens, styles];
}
table.row.styles.ts
import { css } from 'lit';
export default css`
:host {
border-block-end: 1px solid var(--ash);
}
:host(:last-child) {
border-block-end: none;
}
`;
table.column-header.ts
import { customElement } from 'lit/decorators.js';
import TableColumnHeader from 'slab-elements/table.column-header.js';
import styles from './table.column-header.styles.js';
import tokens from './tokens.styles.js';
declare global {
interface HTMLElementTagNameMap {
'slab-styled-table-column-header': StyledTableColumnHeader;
}
}
/**
* Table Column Header, styled: slab-serif capitals. A sortable one has an arrow after its name, ash while unsorted and ember once it sorts the column.
*/
@customElement('slab-styled-table-column-header')
export default class StyledTableColumnHeader extends TableColumnHeader {
static override styles = [tokens, styles];
}
table.column-header.styles.ts
import { css } from 'lit';
/*
"::part(sort-button)" is reset to look like the plain text of a Column
Header that can't sort, and the arrow is drawn here rather than slotted.
*/
export default css`
:host {
font-family: var(--font-display);
font-weight: 700;
letter-spacing: 0.04em;
padding: 0.625rem 0.75rem;
text-align: start;
text-transform: uppercase;
vertical-align: bottom;
white-space: nowrap;
}
[part~='sort-button'] {
align-items: center;
background: none;
border: none;
color: inherit;
cursor: pointer;
display: inline-flex;
font: inherit;
gap: 0.375rem;
letter-spacing: inherit;
margin: 0;
padding: 0;
text-align: inherit;
text-transform: inherit;
&:hover {
text-decoration-color: var(--ember);
text-decoration-line: underline;
text-decoration-thickness: 2px;
text-underline-offset: 0.3em;
}
&:focus-visible {
outline: 3px solid var(--ember);
outline-offset: 3px;
}
}
[part~='sort-indicator'] {
color: var(--ash);
&::before {
content: '↕';
}
}
:host(:state(ascending)) [part~='sort-indicator'],
:host(:state(descending)) [part~='sort-indicator'] {
color: var(--ember-deep);
}
:host(:state(ascending)) [part~='sort-indicator']::before {
content: '↑';
}
:host(:state(descending)) [part~='sort-indicator']::before {
content: '↓';
}
`;
table.cell.ts
import { customElement } from 'lit/decorators.js';
import TableCell from 'slab-elements/table.cell.js';
import styles from './table.cell.styles.js';
import tokens from './tokens.styles.js';
declare global {
interface HTMLElementTagNameMap {
'slab-styled-table-cell': StyledTableCell;
}
}
/**
* Table Cell, styled: roomy padding, and semibold as a row header.
*/
@customElement('slab-styled-table-cell')
export default class StyledTableCell extends TableCell {
static override styles = [tokens, styles];
}
table.cell.styles.ts
import { css } from 'lit';
export default css`
:host {
padding: 0.625rem 0.75rem;
text-align: start;
vertical-align: top;
}
:host([row-header]) {
font-weight: 600;
}
`;
tokens.styles.ts
import { css } from 'lit';
/*
The styled components' palette and type, taken from the logo: ink for the
courses, ember for the base, paper behind them.
Each is a short alias for a "--slab-styled-*" property, with the default as
its fallback. Retheming is "--slab-styled-ember" and the rest on ":root",
which every shadow root inherits. Were the defaults declared under those
names here instead, each host's own declaration would shadow the page's.
Each default is "light-dark()", so the components follow the page's
"color-scheme": "dark" for dark, "light" for light, and "light dark" to
follow the operating system. Ink and paper trade places in the dark, so
ink is always the text and paper always what's behind it. Contrast is given
as light, then dark.
*/
export default css`
:host {
/* Secondary text. 6.8:1 and 6.9:1 on paper. */
--ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
--border: 2px solid var(--ink);
/* Behind disabled and read-only controls, and hovered rows. */
--chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));
/*
The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
enough for borders, fills and large text, but not always for small text,
which takes "--ember-deep".
*/
--ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));
/*
Orange for small text on paper, and for paper text on it. 5.7:1 and
7.4:1.
*/
--ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
--font-body: var(
--slab-styled-font-body,
'IBM Plex Sans',
system-ui,
sans-serif
);
--font-display: var(
--slab-styled-font-display,
'Zilla Slab',
rockwell,
'Roboto Slab',
serif
);
--font-mono: var(
--slab-styled-font-mono,
'IBM Plex Mono',
ui-monospace,
monospace
);
--ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
--paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));
/* The hard, offset shadow a raised surface casts. */
--shadow: 4px 4px 0 var(--ink);
}
/*
Forced colors, such as Windows' contrast themes, replace every color that
isn't a system color, so ember fills and paper marks all become the same
background, and a checked Checkbox looks like an unchecked one. The palette
becomes the user's system colors instead, which are kept. Ember is the
highlight, the color of what's selected, and ember-deep, being for text and
for paper text on it, is the text color.
*/
@media (forced-colors: active) {
:host {
--ash: GrayText;
--chalk: Canvas;
--ember: Highlight;
--ember-deep: CanvasText;
--ink: CanvasText;
--paper: Canvas;
}
}
`;
The same styles, written from outside the element, so
there's nothing to subclass. The CSS styles every
<slab-table> on the page. Import
tokens.css, the colors and fonts every styled
example shares, once, wherever your global styles go.
Each component registers its headless element and imports its CSS. Use it like the element: its props are the element's attributes and properties.
Table.vue
<script setup>
import 'slab-elements/table.js';
import './table.css';
</script>
<template>
<slab-table><slot /></slab-table>
</template>
TableHead.vue
<script setup>
import 'slab-elements/table.head.js';
import './table.head.css';
</script>
<template>
<slab-table-head><slot /></slab-table-head>
</template>
TableBody.vue
<script setup>
import 'slab-elements/table.body.js';
import './table.body.css';
</script>
<template>
<slab-table-body><slot /></slab-table-body>
</template>
TableFoot.vue
<script setup>
import 'slab-elements/table.foot.js';
import './table.foot.css';
</script>
<template>
<slab-table-foot><slot /></slab-table-foot>
</template>
TableRow.vue
<script setup>
import 'slab-elements/table.row.js';
import './table.row.css';
</script>
<template>
<slab-table-row><slot /></slab-table-row>
</template>
TableColumnHeader.vue
<script setup>
import 'slab-elements/table.column-header.js';
import './table.column-header.css';
</script>
<template>
<slab-table-column-header><slot /></slab-table-column-header>
</template>
TableCell.vue
<script setup>
import 'slab-elements/table.cell.js';
import './table.cell.css';
</script>
<template>
<slab-table-cell><slot /></slab-table-cell>
</template>
table.css
slab-table {
background-color: var(--paper);
border: var(--border);
border-collapse: collapse;
box-shadow: var(--shadow);
color: var(--ink);
font-family: var(--font-body);
font-size: 0.9375rem;
font-variant-numeric: tabular-nums;
inline-size: 100%;
line-height: 1.4;
}
table.head.css
slab-table-head {
background-color: var(--chalk);
border-block-end: var(--border);
}
table.body.css
slab-table-body > :hover {
background-color: var(--chalk);
}
table.foot.css
slab-table-foot {
border-block-start: var(--border);
font-weight: 600;
}
table.row.css
slab-table-row {
border-block-end: 1px solid var(--ash);
}
slab-table-row:last-child {
border-block-end: none;
}
table.column-header.css
slab-table-column-header {
font-family: var(--font-display);
font-weight: 700;
letter-spacing: 0.04em;
padding: 0.625rem 0.75rem;
text-align: start;
text-transform: uppercase;
vertical-align: bottom;
white-space: nowrap;
}
slab-table-column-header::part(sort-button) {
align-items: center;
background: none;
border: none;
color: inherit;
cursor: pointer;
display: inline-flex;
font: inherit;
gap: 0.375rem;
letter-spacing: inherit;
margin: 0;
padding: 0;
text-align: inherit;
text-transform: inherit;
}
slab-table-column-header::part(sort-button):hover {
text-decoration-color: var(--ember);
text-decoration-line: underline;
text-decoration-thickness: 2px;
text-underline-offset: 0.3em;
}
slab-table-column-header::part(sort-button):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 3px;
}
slab-table-column-header::part(sort-indicator) {
color: var(--ash);
}
slab-table-column-header::part(sort-indicator)::before {
content: '↕';
}
slab-table-column-header:state(ascending)::part(sort-indicator),
slab-table-column-header:state(descending)::part(sort-indicator) {
color: var(--ember-deep);
}
slab-table-column-header:state(ascending)::part(sort-indicator)::before {
content: '↑';
}
slab-table-column-header:state(descending)::part(sort-indicator)::before {
content: '↓';
}
table.cell.css
slab-table-cell {
padding: 0.625rem 0.75rem;
text-align: start;
vertical-align: top;
}
slab-table-cell[row-header] {
font-weight: 600;
}
tokens.css
:root {
/* Secondary text. 6.8:1 and 6.9:1 on paper. */
--ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
--border: 2px solid var(--ink);
/* Behind disabled and read-only controls, and hovered rows. */
--chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));
/*
The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
enough for borders, fills and large text, but not always for small text,
which takes "--ember-deep".
*/
--ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));
/*
Orange for small text on paper, and for paper text on it. 5.7:1 and
7.4:1.
*/
--ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
--font-body: var(
--slab-styled-font-body,
'IBM Plex Sans',
system-ui,
sans-serif
);
--font-display: var(
--slab-styled-font-display,
'Zilla Slab',
rockwell,
'Roboto Slab',
serif
);
--font-mono: var(
--slab-styled-font-mono,
'IBM Plex Mono',
ui-monospace,
monospace
);
--ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
--paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));
/* The hard, offset shadow a raised surface casts. */
--shadow: 4px 4px 0 var(--ink);
}
/*
Forced colors, such as Windows' contrast themes, replace every color that
isn't a system color, so ember fills and paper marks all become the same
background, and a checked Checkbox looks like an unchecked one. The palette
becomes the user's system colors instead, which are kept. Ember is the
highlight, the color of what's selected, and ember-deep, being for text and
for paper text on it, is the text color.
*/
@media (forced-colors: active) {
:host {
--ash: GrayText;
--chalk: Canvas;
--ember: Highlight;
--ember-deep: CanvasText;
--ink: CanvasText;
--paper: Canvas;
}
}
The same styles, written from outside the element, so
there's nothing to subclass. The CSS styles every
<slab-table> on the page. Import
tokens.css, the colors and fonts every styled
example shares, once, wherever your global styles go.
Import table.js once, such
as in your root layout, and use
<slab-table> as is. A Svelte component
around it would take slot="…" content as its
own slot and drop it.
table.js
import 'slab-elements/table.js';
import './table.css';
import 'slab-elements/table.head.js';
import './table.head.css';
import 'slab-elements/table.body.js';
import './table.body.css';
import 'slab-elements/table.foot.js';
import './table.foot.css';
import 'slab-elements/table.row.js';
import './table.row.css';
import 'slab-elements/table.column-header.js';
import './table.column-header.css';
import 'slab-elements/table.cell.js';
import './table.cell.css';
table.css
slab-table {
background-color: var(--paper);
border: var(--border);
border-collapse: collapse;
box-shadow: var(--shadow);
color: var(--ink);
font-family: var(--font-body);
font-size: 0.9375rem;
font-variant-numeric: tabular-nums;
inline-size: 100%;
line-height: 1.4;
}
table.head.css
slab-table-head {
background-color: var(--chalk);
border-block-end: var(--border);
}
table.body.css
slab-table-body > :hover {
background-color: var(--chalk);
}
table.foot.css
slab-table-foot {
border-block-start: var(--border);
font-weight: 600;
}
table.row.css
slab-table-row {
border-block-end: 1px solid var(--ash);
}
slab-table-row:last-child {
border-block-end: none;
}
table.column-header.css
slab-table-column-header {
font-family: var(--font-display);
font-weight: 700;
letter-spacing: 0.04em;
padding: 0.625rem 0.75rem;
text-align: start;
text-transform: uppercase;
vertical-align: bottom;
white-space: nowrap;
}
slab-table-column-header::part(sort-button) {
align-items: center;
background: none;
border: none;
color: inherit;
cursor: pointer;
display: inline-flex;
font: inherit;
gap: 0.375rem;
letter-spacing: inherit;
margin: 0;
padding: 0;
text-align: inherit;
text-transform: inherit;
}
slab-table-column-header::part(sort-button):hover {
text-decoration-color: var(--ember);
text-decoration-line: underline;
text-decoration-thickness: 2px;
text-underline-offset: 0.3em;
}
slab-table-column-header::part(sort-button):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 3px;
}
slab-table-column-header::part(sort-indicator) {
color: var(--ash);
}
slab-table-column-header::part(sort-indicator)::before {
content: '↕';
}
slab-table-column-header:state(ascending)::part(sort-indicator),
slab-table-column-header:state(descending)::part(sort-indicator) {
color: var(--ember-deep);
}
slab-table-column-header:state(ascending)::part(sort-indicator)::before {
content: '↑';
}
slab-table-column-header:state(descending)::part(sort-indicator)::before {
content: '↓';
}
table.cell.css
slab-table-cell {
padding: 0.625rem 0.75rem;
text-align: start;
vertical-align: top;
}
slab-table-cell[row-header] {
font-weight: 600;
}
tokens.css
:root {
/* Secondary text. 6.8:1 and 6.9:1 on paper. */
--ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
--border: 2px solid var(--ink);
/* Behind disabled and read-only controls, and hovered rows. */
--chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));
/*
The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
enough for borders, fills and large text, but not always for small text,
which takes "--ember-deep".
*/
--ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));
/*
Orange for small text on paper, and for paper text on it. 5.7:1 and
7.4:1.
*/
--ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
--font-body: var(
--slab-styled-font-body,
'IBM Plex Sans',
system-ui,
sans-serif
);
--font-display: var(
--slab-styled-font-display,
'Zilla Slab',
rockwell,
'Roboto Slab',
serif
);
--font-mono: var(
--slab-styled-font-mono,
'IBM Plex Mono',
ui-monospace,
monospace
);
--ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
--paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));
/* The hard, offset shadow a raised surface casts. */
--shadow: 4px 4px 0 var(--ink);
}
/*
Forced colors, such as Windows' contrast themes, replace every color that
isn't a system color, so ember fills and paper marks all become the same
background, and a checked Checkbox looks like an unchecked one. The palette
becomes the user's system colors instead, which are kept. Ember is the
highlight, the color of what's selected, and ember-deep, being for text and
for paper text on it, is the text color.
*/
@media (forced-colors: active) {
:host {
--ash: GrayText;
--chalk: Canvas;
--ember: Highlight;
--ember-deep: CanvasText;
--ink: CanvasText;
--paper: Canvas;
}
}
The same styles, written from outside the element, so
there's nothing to subclass. The CSS styles every
<slab-table> on the page. Import
tokens.css, the colors and fonts every styled
example shares, once, wherever your global styles go.
Each component registers its headless element and imports its CSS. Use it like the element: its attributes and its content go to the element.
Table.gjs
import 'slab-elements/table.js';
import './table.css';
export const Table = <template>
<slab-table ...attributes>{{yield}}</slab-table>
</template>;
TableHead.gjs
import 'slab-elements/table.head.js';
import './table.head.css';
export const TableHead = <template>
<slab-table-head ...attributes>{{yield}}</slab-table-head>
</template>;
TableBody.gjs
import 'slab-elements/table.body.js';
import './table.body.css';
export const TableBody = <template>
<slab-table-body ...attributes>{{yield}}</slab-table-body>
</template>;
TableFoot.gjs
import 'slab-elements/table.foot.js';
import './table.foot.css';
export const TableFoot = <template>
<slab-table-foot ...attributes>{{yield}}</slab-table-foot>
</template>;
TableRow.gjs
import 'slab-elements/table.row.js';
import './table.row.css';
export const TableRow = <template>
<slab-table-row ...attributes>{{yield}}</slab-table-row>
</template>;
TableColumnHeader.gjs
import 'slab-elements/table.column-header.js';
import './table.column-header.css';
export const TableColumnHeader = <template>
<slab-table-column-header ...attributes>{{yield}}</slab-table-column-header>
</template>;
TableCell.gjs
import 'slab-elements/table.cell.js';
import './table.cell.css';
export const TableCell = <template>
<slab-table-cell ...attributes>{{yield}}</slab-table-cell>
</template>;
table.css
slab-table {
background-color: var(--paper);
border: var(--border);
border-collapse: collapse;
box-shadow: var(--shadow);
color: var(--ink);
font-family: var(--font-body);
font-size: 0.9375rem;
font-variant-numeric: tabular-nums;
inline-size: 100%;
line-height: 1.4;
}
table.head.css
slab-table-head {
background-color: var(--chalk);
border-block-end: var(--border);
}
table.body.css
slab-table-body > :hover {
background-color: var(--chalk);
}
table.foot.css
slab-table-foot {
border-block-start: var(--border);
font-weight: 600;
}
table.row.css
slab-table-row {
border-block-end: 1px solid var(--ash);
}
slab-table-row:last-child {
border-block-end: none;
}
table.column-header.css
slab-table-column-header {
font-family: var(--font-display);
font-weight: 700;
letter-spacing: 0.04em;
padding: 0.625rem 0.75rem;
text-align: start;
text-transform: uppercase;
vertical-align: bottom;
white-space: nowrap;
}
slab-table-column-header::part(sort-button) {
align-items: center;
background: none;
border: none;
color: inherit;
cursor: pointer;
display: inline-flex;
font: inherit;
gap: 0.375rem;
letter-spacing: inherit;
margin: 0;
padding: 0;
text-align: inherit;
text-transform: inherit;
}
slab-table-column-header::part(sort-button):hover {
text-decoration-color: var(--ember);
text-decoration-line: underline;
text-decoration-thickness: 2px;
text-underline-offset: 0.3em;
}
slab-table-column-header::part(sort-button):focus-visible {
outline: 3px solid var(--ember);
outline-offset: 3px;
}
slab-table-column-header::part(sort-indicator) {
color: var(--ash);
}
slab-table-column-header::part(sort-indicator)::before {
content: '↕';
}
slab-table-column-header:state(ascending)::part(sort-indicator),
slab-table-column-header:state(descending)::part(sort-indicator) {
color: var(--ember-deep);
}
slab-table-column-header:state(ascending)::part(sort-indicator)::before {
content: '↑';
}
slab-table-column-header:state(descending)::part(sort-indicator)::before {
content: '↓';
}
table.cell.css
slab-table-cell {
padding: 0.625rem 0.75rem;
text-align: start;
vertical-align: top;
}
slab-table-cell[row-header] {
font-weight: 600;
}
tokens.css
:root {
/* Secondary text. 6.8:1 and 6.9:1 on paper. */
--ash: var(--slab-styled-ash, light-dark(#5e5a55, #a8a19a));
--border: 2px solid var(--ink);
/* Behind disabled and read-only controls, and hovered rows. */
--chalk: var(--slab-styled-chalk, light-dark(#f4f1ec, #2b2926));
/*
The logo's orange, brighter in the dark. 4.25:1 and 5.2:1 on paper is
enough for borders, fills and large text, but not always for small text,
which takes "--ember-deep".
*/
--ember: var(--slab-styled-ember, light-dark(#d9492a, #ec5f3b));
/*
Orange for small text on paper, and for paper text on it. 5.7:1 and
7.4:1.
*/
--ember-deep: var(--slab-styled-ember-deep, light-dark(#b3381a, #ff8566));
--font-body: var(
--slab-styled-font-body,
'IBM Plex Sans',
system-ui,
sans-serif
);
--font-display: var(
--slab-styled-font-display,
'Zilla Slab',
rockwell,
'Roboto Slab',
serif
);
--font-mono: var(
--slab-styled-font-mono,
'IBM Plex Mono',
ui-monospace,
monospace
);
--ink: var(--slab-styled-ink, light-dark(#1c1c1c, #f4f1ec));
--paper: var(--slab-styled-paper, light-dark(#fff, #1a1918));
/* The hard, offset shadow a raised surface casts. */
--shadow: 4px 4px 0 var(--ink);
}
/*
Forced colors, such as Windows' contrast themes, replace every color that
isn't a system color, so ember fills and paper marks all become the same
background, and a checked Checkbox looks like an unchecked one. The palette
becomes the user's system colors instead, which are kept. Ember is the
highlight, the color of what's selected, and ember-deep, being for text and
for paper text on it, is the text color.
*/
@media (forced-colors: active) {
:host {
--ash: GrayText;
--chalk: Canvas;
--ember: Highlight;
--ember-deep: CanvasText;
--ink: CanvasText;
--paper: Canvas;
}
}