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>- As Markdown
- progress.md
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
<script type="module">
import 'slab-elements/progress.js';
</script>
<slab-progress label="Uploading" max="100" value="40"></slab-progress>
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.
Style it through its parts and through :state(indeterminate).
API
<slab-progress>
| Name | Type | Default | Description |
|---|---|---|---|
label
Required
|
string |
||
hide-label
|
boolean |
false |
|
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>. |
|
version
|
string |
| Name | Description |
|---|---|
label
|
The label |
progress
|
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. Under the
hood, it's just the headless element, subclassed, with
styles set. That's it. 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.
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;
}
}
@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);
}
`;