Data
Progress
How far along a task is, or just that it's happening when you don't know yet. That's your spinner, too.
- Element
<slab-progress>- Built on
<progress>
Example
Here's a styled version, <slab-styled-progress>. 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.
<div class="stack">
<slab-styled-progress label="Curing" max="100" value="43"></slab-styled-progress>
<slab-styled-progress label="Waiting for the site sensor"></slab-styled-progress>
</div>
<div class="stack">
<slab-progress label="Curing" max="100" value="43"></slab-progress>
<slab-progress label="Waiting for the site sensor"></slab-progress>
</div>
Usage
pnpm add slab-elements lit
import 'slab-elements/progress.js';
export function MyProgress() {
return (
<slab-progress label="Uploading" max={100} value={40}></slab-progress>
);
}
MyProgress.jsx React 19 or later, which sets props on custom elements as properties.
import 'slab-elements/progress.js';
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
@customElement('my-progress')
export class MyProgress extends LitElement {
render() {
return html`
<slab-progress label="Uploading" max="100" value="40"></slab-progress>
`;
}
}
my-progress.ts Slab is built on Lit, so its elements are at home in Lit's templates.
<script setup>
import 'slab-elements/progress.js';
</script>
<template>
<slab-progress label="Uploading" :max="100" :value="40"></slab-progress>
</template>
MyProgress.vue Let Vue's compiler know slab- tags are custom elements with isCustomElement.
<script>
import 'slab-elements/progress.js';
</script>
<slab-progress label="Uploading" max={100} value={40}></slab-progress>
MyProgress.svelte Svelte binds properties and events to custom elements like any other element.
import 'slab-elements/progress.js';
export const MyProgress = <template>
<slab-progress label="Uploading" max="100" value="40"></slab-progress>
</template>;
MyProgress.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/progress.js';
</script>
<slab-progress label="Uploading" max="100" value="40"></slab-progress>
index.html Any bundler (or an import map) takes care of the imports.
Screenreaders read how far along it is as a percentage. To say it another way, set formatValue to a function of value, such as (value) => `${value} of 10 files`, and they’ll read what it returns instead. It isn’t called while the progress bar is indeterminate.
Behavior
A progress bar with no visual styles, around a native <progress>, so it's a progressbar to the platform with its value and maximum, as one is.
With no value, it's indeterminate: the task is under way, but how far along isn't known. That's what a spinner shows, so there's no Spinner.
The label and the <progress> are both in the shadow root, so a plain for reference names it.
Screenreaders read how far along it is as a percentage. Set formatValue to a function of value that says it another way, such as "3 of 10 files", which becomes the <progress>'s aria-valuetext. It isn't called while it's indeterminate.
Style it through its parts and through :state(indeterminate).
API
<slab-progress>
| Name | Type | Default | Description |
|---|---|---|---|
label
Required
|
string |
Names it. It's the accessible name, and the visible label where there is one. | |
hide-label
|
boolean |
false |
Hides the label visually and leaves it as the accessible name, for a design that shows the label some other way. |
max
|
number |
1 when unset, as on a native <progress>. |
|
value
|
number |
How much of the task is done, from 0 to max. Indeterminate when unset, as on a native <progress>. |
| Name | Type | Description |
|---|---|---|
formatValue
|
(value: number) => string | undefined |
What screenreaders read for the value, such as "3 of 10 files" rather than "30%". A percentage when unset. |
| Name | Description |
|---|---|
label
|
The label |
progress
|
The progress bar |
| Name | Description |
|---|---|
:state(indeterminate)
|
While it has no value, so how far along the task is isn't known. |
Copy and own it
<slab-styled-progress> 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.
This one styles its native control's own pieces, like a
range input's thumb or a meter's bar. Browsers only let
those be styled from inside the element's shadow root, not
through ::part(), so it can't be written as
plain CSS. Copy the Lit files instead. They're a custom
element like any other, so they work in React as they are.
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.
progress.ts
import { customElement } from 'lit/decorators.js';
import Progress from 'slab-elements/progress.js';
import styles from './progress.styles.js';
import tokens from './tokens.styles.js';
declare global {
interface HTMLElementTagNameMap {
'slab-styled-progress': StyledProgress;
}
}
/**
* Progress, styled: an ink-bordered bar laid with ember bricks as the task
* goes, and bricks that march across it while how far along isn't known.
*/
@customElement('slab-styled-progress')
export default class StyledProgress extends Progress {
static override styles = [tokens, styles];
}
progress.styles.ts
import { css } from 'lit';
/*
The bricks are a repeating gradient: 1.5rem of ember and a 0.25rem joint of
paper, the logo's proportions near enough.
*/
export default css`
:host {
color: var(--ink);
display: grid;
font-family: var(--font-body);
gap: 0.5rem;
}
[part~='label'] {
font-family: var(--font-display);
font-size: 1.0625rem;
font-weight: 600;
}
[part~='progress'] {
appearance: none;
background-color: var(--paper);
block-size: 1.375rem;
border: var(--border);
box-sizing: border-box;
inline-size: 100%;
padding: 2px;
&::-webkit-progress-bar {
background-color: transparent;
}
&::-webkit-progress-value {
background: repeating-linear-gradient(
to right,
var(--ember) 0 1.5rem,
transparent 1.5rem 1.75rem
);
transition: inline-size 200ms;
}
&::-moz-progress-bar {
background: repeating-linear-gradient(
to right,
var(--ember) 0 1.5rem,
transparent 1.5rem 1.75rem
);
}
}
/*
The bricks are one tile, a brick and its gap, repeated across. The march
moves them by exactly that tile, so each loop picks up where the last one
left off. A gradient as wide as the bar would wrap at the bar's width,
which isn't a multiple of the tile, and a brick would jump at the start.
*/
:host(:state(indeterminate)) [part~='progress'] {
animation: march 600ms linear infinite;
background:
linear-gradient(
to right,
var(--ember) 0 1.5rem,
transparent 1.5rem 3.5rem
)
0 0 / 3.5rem 100% repeat-x content-box,
var(--paper);
&::-moz-progress-bar {
background: transparent;
}
}
@keyframes march {
to {
background-position-x: 3.5rem, 0;
}
}
/*
Forced colors drop gradients, and the bricks are one. Their colors are
system colors there, so they can keep them.
*/
@media (forced-colors: active) {
[part~='progress'] {
forced-color-adjust: none;
}
}
@media (prefers-reduced-motion: reduce) {
:host(:state(indeterminate)) [part~='progress'] {
animation: none;
}
[part~='progress']::-webkit-progress-value {
transition: none;
}
}
`;
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;
}
}
`;
This one styles its native control's own pieces, like a
range input's thumb or a meter's bar. Browsers only let
those be styled from inside the element's shadow root, not
through ::part(), so it can't be written as
plain CSS. Copy the Lit files instead. They're a custom
element like any other, so they work in Vue as they are.
This one styles its native control's own pieces, like a
range input's thumb or a meter's bar. Browsers only let
those be styled from inside the element's shadow root, not
through ::part(), so it can't be written as
plain CSS. Copy the Lit files instead. They're a custom
element like any other, so they work in Svelte as they are.
This one styles its native control's own pieces, like a
range input's thumb or a meter's bar. Browsers only let
those be styled from inside the element's shadow root, not
through ::part(), so it can't be written as
plain CSS. Copy the Lit files instead. They're a custom
element like any other, so they work in Ember as they are.