A button that fills while the work runs, loops its icon until the work stops, and shows a receipt. As a download and as an upload.
Take it with you
This demo also exists as a standalone project —
npm install && npm run dev, no changes needed.
npx giget@latest gh:lordicondev/ui-components/button-progress#standalone button-progress
Copies the button-progress folder of the
standalone branch — where every demo lives
on its own — into ./button-progress.
How it works
Define the element, put the icon in the markup, set the control's state. Then the parts that make this demo different.
Define the element Built-in triggers only. What each icon follows is written in its markup.
import { defineElement } from '@lordicon/element';
// Registers <lord-icon> with its built-in triggers. The markup says what each icon follows.
defineElement();
import { defineElement } from '@lordicon/element';
// Registers <lord-icon> with its built-in triggers. The markup says what each icon follows.
defineElement();
The button data-stage for what it is doing, data-progress for how far. The icon maps each stage to a state.
<!-- data-stage is the state: the icon, the fill, the label and the toast read
it. data-progress is 0 to 100 and the bar follows it. -->
<button
class="task__button"
type="button"
data-stage="idle"
data-progress="0"
aria-label="Download file"
>
<span class="task__fill" aria-hidden="true"></span>
<lord-icon
class="task__mark"
current-color
src="icons/download.json"
loading="interaction"
trigger="follow(data-stage, busy=loop-cycle, done=morph-check)"
target=".task__button"
state="morph-check"
aria-hidden="true"
>
<img alt="" src="icons/download.svg" />
</lord-icon>
<!-- … -->
</button>
Set progress and stage Two attributes. Everything on screen reads them.
/**
* Progress from 0 to 100. An attribute, so anything can drive it: this demo's pretend
* transfer, a real `onprogress`, or the element inspector. The stylesheet reads
* `--progress`, because CSS cannot take a number out of an attribute.
*/
function report(percent: number): void {
const bounded = Math.min(Math.max(percent, 0), 100);
button.dataset.progress = String(Math.round(bounded));
button.style.setProperty('--progress', String(bounded / 100));
}
/** Sets the stage: idle, busy or done. The icon, the bar, the label and the toast read it. */
function enter(stage: string): void {
button.dataset.stage = stage;
button.disabled = stage === 'busy';
button.setAttribute('aria-busy', String(stage === 'busy'));
say(STAGES.indexOf(stage));
}
/**
* Progress from 0 to 100. An attribute, so anything can drive it: this demo's pretend
* transfer, a real `onprogress`, or the element inspector. The stylesheet reads
* `--progress`, because CSS cannot take a number out of an attribute.
*/
function report(percent) {
const bounded = Math.min(Math.max(percent, 0), 100);
button.dataset.progress = String(Math.round(bounded));
button.style.setProperty('--progress', String(bounded / 100));
}
/** Sets the stage: idle, busy or done. The icon, the bar, the label and the toast read it. */
function enter(stage) {
button.dataset.stage = stage;
button.disabled = stage === 'busy';
button.setAttribute('aria-busy', String(stage === 'busy'));
say(STAGES.indexOf(stage));
}
One press, one cycle The pretend transfer. A real one would call report() from onprogress.
/** One press: busy with progress in steps, done, a receipt, then idle again. */
async function run(): Promise<void> {
enter('busy');
for (let percent = STEP; percent <= 100; percent += STEP) {
report(percent);
await wait(TRANSFER / (100 / STEP));
}
enter('done');
toast.dataset.shown = 'true'; // the tick plays on this
await wait(RECEIPT);
toast.dataset.shown = 'false';
await wait(200); // let the toast leave before the button resets
enter('idle');
report(0);
}
button.addEventListener('click', () => void run());
/** One press: busy with progress in steps, done, a receipt, then idle again. */
async function run() {
enter('busy');
for (let percent = STEP; percent <= 100; percent += STEP) {
report(percent);
await wait(TRANSFER / (100 / STEP));
}
enter('done');
toast.dataset.shown = 'true'; // the tick plays on this
await wait(RECEIPT);
toast.dataset.shown = 'false';
await wait(200); // let the toast leave before the button resets
enter('idle');
report(0);
}
button.addEventListener('click', () => void run());
Slide the label strip Always upwards. Wrapping uses a copy of the first label past the end.
/**
* Slides the label strip to line `at`. The strip only ever moves up. Going back to the
* first label, it slides on to the copy past the end, then jumps back to the real one
* with transitions off.
*/
function say(at: number): void {
const from = Number(strip.dataset.at ?? 0);
const to = at === 0 && from > 0 ? lines.length : at;
strip.dataset.at = String(at);
strip.style.setProperty('--line', String(to));
// The first text node only: the busy label ends in animated dots.
button.setAttribute('aria-label', lines[at].firstChild!.textContent!.trim());
if (to <= from) return;
strip.addEventListener(
'transitionend',
() => {
if (to !== lines.length) return;
strip.dataset.settling = '';
strip.style.setProperty('--line', '0');
void strip.offsetWidth; // apply the jump now, while transitions are off
delete strip.dataset.settling;
},
{ once: true },
);
}
/**
* Slides the label strip to line `at`. The strip only ever moves up. Going back to the
* first label, it slides on to the copy past the end, then jumps back to the real one
* with transitions off.
*/
function say(at) {
const from = Number(strip.dataset.at ?? 0);
const to = at === 0 && from > 0 ? lines.length : at;
strip.dataset.at = String(at);
strip.style.setProperty('--line', String(to));
// The first text node only: the busy label ends in animated dots.
button.setAttribute('aria-label', lines[at].firstChild.textContent.trim());
if (to <= from) return;
strip.addEventListener(
'transitionend',
() => {
if (to !== lines.length) return;
strip.dataset.settling = '';
strip.style.setProperty('--line', '0');
void strip.offsetWidth; // apply the jump now, while transitions are off
delete strip.dataset.settling;
},
{ once: true },
);
}
The progress bar Scaled, not widened. The transition smooths the steps; done fades it out.
/* The bar is the full width of the button, scaled by --progress. Scaling a solid colour
costs no layout. When done it fades rather than running back; the scale resets while
it is invisible. */
.task__fill {
position: absolute;
inset: 0;
transform-origin: left;
scale: var(--progress, 0) 1;
background: var(--accent-strong);
opacity: 0;
}
.task__button[data-stage='busy'] .task__fill {
opacity: 1;
transition: scale 220ms linear;
}
.task__button[data-stage='done'] .task__fill {
opacity: 0;
transition: opacity 300ms ease;
}
The receipt opening and leaving Opens from the middle to the edge. Leaves by fading; the box snaps back afterwards.
/* Opens from the button's middle (left 50%, width 0) to its left edge at full width.
--toast-width is measured by main.ts, because width cannot transition to auto. The
words are not animated; the box uncovers them. Leaving is a fade and a small drop;
`0s 150ms` snaps width and left back once the fade has finished. */
.toast {
left: 50%;
width: 0;
opacity: 0;
translate: 0 0;
transition:
opacity 150ms ease,
translate 150ms ease,
width 0s 150ms,
left 0s 150ms;
}
.toast[data-shown='true'] {
width: var(--toast-width, max-content);
left: 0;
opacity: 1;
transition:
width 500ms cubic-bezier(0.215, 0.61, 0.355, 1),
left 500ms cubic-bezier(0.215, 0.61, 0.355, 1),
opacity 150ms ease;
}
Every file
The demo's own files, whole, at the paths the export uses.
button-progress.css 221 lines
@import '@shared/styles/index.css';
@import '@shared/ui/pager.css';
.demo {
display: grid;
grid-template-rows: 1fr auto;
justify-items: center;
align-items: center;
gap: var(--space-96);
min-height: 100dvh;
padding: var(--space-64) var(--gutter) var(--space-32);
}
/* The box the toast is positioned against. */
.task {
position: relative;
display: grid;
justify-items: start;
}
.task__button {
position: relative;
display: flex;
align-items: center;
gap: var(--space-4);
overflow: hidden;
padding: var(--space-8) var(--space-16);
border: 0;
border-radius: var(--radius-md);
background: var(--accent);
box-shadow: var(--shadow-accent);
color: var(--ink-inverse);
--icon-filter: var(--filter-ink-inverse);
font-weight: 500;
cursor: pointer;
}
/* No transition on hover or press. The icon holds still through both. */
.task__button:hover:not(:disabled) {
background: var(--accent-strong);
}
.task__button:active:not(:disabled) {
background: var(--accent-ink);
}
.task__button:disabled {
cursor: default;
}
/* The bar is the full width of the button, scaled by --progress. Scaling a solid colour
costs no layout. When done it fades rather than running back; the scale resets while
it is invisible. */
.task__fill {
position: absolute;
inset: 0;
transform-origin: left;
scale: var(--progress, 0) 1;
background: var(--accent-strong);
opacity: 0;
}
.task__button[data-stage='busy'] .task__fill {
opacity: 1;
transition: scale 220ms linear;
}
.task__button[data-stage='done'] .task__fill {
opacity: 0;
transition: opacity 300ms ease;
}
.task__mark {
flex: none;
width: var(--icon-size-24);
height: var(--icon-size-24);
}
/* A one-line window over a strip of labels. The window is as wide as the widest label,
so the button keeps its width while the words change. */
.task__says {
display: block;
overflow: hidden;
height: var(--leading-base);
}
.task__lines {
display: grid;
justify-items: start;
translate: 0 calc(var(--line, 0) * var(--leading-base) * -1);
transition: translate 250ms ease-out;
}
.task__line {
line-height: var(--leading-base);
white-space: nowrap;
}
/* The three dots after "Downloading" appear one at a time and vanish together, on a
667ms cycle from the reference recording. They only change opacity, so nothing moves. */
.task__dots {
font-style: normal;
}
.task__dots > i::before {
content: '.';
font-style: normal;
}
/* Longhands, not the `animation` shorthand: a shorthand without a name minifies to
`animation: none` and drops the timings. */
.task__dots > i {
opacity: 0;
animation-duration: 667ms;
animation-timing-function: step-end;
animation-iteration-count: infinite;
}
.task__dots > i:nth-child(1) {
animation-name: dot-one;
}
.task__dots > i:nth-child(2) {
animation-name: dot-two;
}
.task__dots > i:nth-child(3) {
animation-name: dot-three;
}
@keyframes dot-one {
22.5% {
opacity: 1;
}
}
@keyframes dot-two {
45% {
opacity: 1;
}
}
@keyframes dot-three {
67.5% {
opacity: 1;
}
}
/* The jump back to the first label, taken with transitions off. */
.task__lines[data-settling] {
transition: none;
}
/* The receipt under the button. Absolute, so nothing below moves to make room. */
.toast {
position: absolute;
top: calc(100% + var(--space-16) + var(--space-4));
z-index: 1;
display: flex;
align-items: center;
gap: var(--space-8);
margin: 0;
overflow: hidden;
padding: var(--space-8);
border: 1px solid var(--border-soft);
border-radius: var(--radius-lg);
background: var(--surface);
}
/* Opens from the button's middle (left 50%, width 0) to its left edge at full width.
--toast-width is measured by main.ts, because width cannot transition to auto. The
words are not animated; the box uncovers them. Leaving is a fade and a small drop;
`0s 150ms` snaps width and left back once the fade has finished. */
.toast {
left: 50%;
width: 0;
opacity: 0;
translate: 0 0;
transition:
opacity 150ms ease,
translate 150ms ease,
width 0s 150ms,
left 0s 150ms;
}
.toast[data-shown='true'] {
width: var(--toast-width, max-content);
left: 0;
opacity: 1;
transition:
width 500ms cubic-bezier(0.215, 0.61, 0.355, 1),
left 500ms cubic-bezier(0.215, 0.61, 0.355, 1),
opacity 150ms ease;
}
.toast[data-shown='false'] {
translate: 0 var(--space-8);
}
.toast__mark {
flex: none;
width: var(--icon-size-20);
height: var(--icon-size-20);
color: var(--accent);
}
.toast__text {
color: var(--ink);
font-size: var(--text-sm);
font-weight: 500;
line-height: var(--leading-base);
white-space: nowrap;
}
@media (prefers-reduced-motion: reduce) {
.task__lines,
.task__fill,
.toast {
transition: none;
}
}
index.html 131 lines
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Button progress</title>
<link rel="stylesheet" href="./button-progress.css" />
<script type="module" src="./main.ts"></script>
</head>
<body>
<main class="demo">
<div class="task" id="kind-download" data-page>
<!-- data-stage is the state: the icon, the fill, the label and the toast read
it. data-progress is 0 to 100 and the bar follows it. -->
<button
class="task__button"
type="button"
data-stage="idle"
data-progress="0"
aria-label="Download file"
>
<span class="task__fill" aria-hidden="true"></span>
<lord-icon
class="task__mark"
current-color
src="icons/download.json"
loading="interaction"
trigger="follow(data-stage, busy=loop-cycle, done=morph-check)"
target=".task__button"
state="morph-check"
aria-hidden="true"
>
<img alt="" src="icons/download.svg" />
</lord-icon>
<!-- Three labels on a strip that slides up one line per stage change.
aria-label on the button is copied from whichever is showing. -->
<span class="task__says" aria-hidden="true">
<span class="task__lines">
<span class="task__line">Download file</span>
<span class="task__line"
>Downloading<i class="task__dots"><i></i><i></i><i></i></i
></span>
<span class="task__line">Downloaded</span>
</span>
</span>
</button>
<!-- Absolutely placed, so nothing below moves to make room. -->
<p class="toast" role="status" data-shown="false">
<lord-icon
class="toast__mark"
current-color
src="icons/check-circle.json"
trigger="follow(data-shown)"
target=".toast"
state="in-reveal"
aria-hidden="true"
></lord-icon>
<span class="toast__text">File downloaded – lordicon-icons.zip</span>
</p>
</div>
<div class="task" id="kind-upload" data-page hidden>
<button
class="task__button"
type="button"
data-stage="idle"
data-progress="0"
aria-label="Upload file"
>
<span class="task__fill" aria-hidden="true"></span>
<!-- The second page: a different icon and three different words. -->
<lord-icon
class="task__mark"
current-color
src="icons/upload.json"
trigger="follow(data-stage, busy=loop-cycle, done=morph-check)"
target=".task__button"
state="morph-check"
aria-hidden="true"
></lord-icon>
<span class="task__says" aria-hidden="true">
<span class="task__lines">
<span class="task__line">Upload file</span>
<span class="task__line"
>Uploading<i class="task__dots"><i></i><i></i><i></i></i
></span>
<span class="task__line">Uploaded</span>
</span>
</span>
</button>
<p class="toast" role="status" data-shown="false">
<lord-icon
class="toast__mark"
current-color
src="icons/check-circle.json"
trigger="follow(data-shown)"
target=".toast"
state="in-reveal"
aria-hidden="true"
></lord-icon>
<span class="toast__text">File uploaded – icon-heart.json</span>
</p>
</div>
<div class="pager">
<button
class="pager__dot"
type="button"
aria-pressed="true"
aria-controls="kind-download"
aria-label="Download"
></button>
<button
class="pager__dot"
type="button"
aria-pressed="false"
aria-controls="kind-upload"
aria-label="Upload"
></button>
</div>
</main>
</body>
</html>
main.ts 124 lines
import { defineElement } from '@lordicon/element';
// Registers <lord-icon> with its built-in triggers. The markup says what each icon follows.
defineElement();
import { pager } from '@shared/ui/pager.ts';
const STAGES = ['idle', 'busy', 'done'];
/** How long the pretend transfer takes, how much lands per step, and how long the receipt stays. */
const TRANSFER = 2200;
const STEP = 10;
const RECEIPT = 2000;
const wait = (ms: number) => new Promise((done) => setTimeout(done, ms));
/**
* Wires one `.task`: the button, its label strip and its toast. Called for each task on
* the page; the download and the upload differ only in markup.
*/
function wire(task: HTMLElement): void {
const button = task.querySelector<HTMLButtonElement>('.task__button')!;
const strip = task.querySelector<HTMLElement>('.task__lines')!;
const lines = [...task.querySelectorAll<HTMLElement>('.task__line')];
const toast = task.querySelector<HTMLElement>('.toast')!;
// A copy of the first label after the last one, so the strip can wrap forwards.
strip.append(lines[0].cloneNode(true));
/**
* Progress from 0 to 100. An attribute, so anything can drive it: this demo's pretend
* transfer, a real `onprogress`, or the element inspector. The stylesheet reads
* `--progress`, because CSS cannot take a number out of an attribute.
*/
function report(percent: number): void {
const bounded = Math.min(Math.max(percent, 0), 100);
button.dataset.progress = String(Math.round(bounded));
button.style.setProperty('--progress', String(bounded / 100));
}
/** Sets the stage: idle, busy or done. The icon, the bar, the label and the toast read it. */
function enter(stage: string): void {
button.dataset.stage = stage;
button.disabled = stage === 'busy';
button.setAttribute('aria-busy', String(stage === 'busy'));
say(STAGES.indexOf(stage));
}
/**
* Slides the label strip to line `at`. The strip only ever moves up. Going back to the
* first label, it slides on to the copy past the end, then jumps back to the real one
* with transitions off.
*/
function say(at: number): void {
const from = Number(strip.dataset.at ?? 0);
const to = at === 0 && from > 0 ? lines.length : at;
strip.dataset.at = String(at);
strip.style.setProperty('--line', String(to));
// The first text node only: the busy label ends in animated dots.
button.setAttribute('aria-label', lines[at].firstChild!.textContent!.trim());
if (to <= from) return;
strip.addEventListener(
'transitionend',
() => {
if (to !== lines.length) return;
strip.dataset.settling = '';
strip.style.setProperty('--line', '0');
void strip.offsetWidth; // apply the jump now, while transitions are off
delete strip.dataset.settling;
},
{ once: true },
);
}
/** One press: busy with progress in steps, done, a receipt, then idle again. */
async function run(): Promise<void> {
enter('busy');
for (let percent = STEP; percent <= 100; percent += STEP) {
report(percent);
await wait(TRANSFER / (100 / STEP));
}
enter('done');
toast.dataset.shown = 'true'; // the tick plays on this
await wait(RECEIPT);
toast.dataset.shown = 'false';
await wait(200); // let the toast leave before the button resets
enter('idle');
report(0);
}
button.addEventListener('click', () => void run());
}
/**
* Measures each toast's open width once the font has loaded, because CSS cannot
* transition width to `auto`. A hidden page has no widths, so it is shown for the
* measurement; nothing paints in between.
*/
async function measure(): Promise<void> {
await document.fonts.ready;
for (const toast of document.querySelectorAll<HTMLElement>('.toast')) {
const page = toast.closest<HTMLElement>('[data-page]')!;
const away = page.hidden;
page.hidden = false;
toast.style.setProperty('--toast-width', `${toast.scrollWidth}px`);
page.hidden = away;
}
}
for (const task of document.querySelectorAll<HTMLElement>('.task')) wire(task);
pager();
void measure();
import { defineElement } from '@lordicon/element';
// Registers <lord-icon> with its built-in triggers. The markup says what each icon follows.
defineElement();
import { pager } from '@shared/ui/pager.js';
const STAGES = ['idle', 'busy', 'done'];
/** How long the pretend transfer takes, how much lands per step, and how long the receipt stays. */
const TRANSFER = 2200;
const STEP = 10;
const RECEIPT = 2000;
const wait = (ms) => new Promise((done) => setTimeout(done, ms));
/**
* Wires one `.task`: the button, its label strip and its toast. Called for each task on
* the page; the download and the upload differ only in markup.
*/
function wire(task) {
const button = task.querySelector('.task__button');
const strip = task.querySelector('.task__lines');
const lines = [...task.querySelectorAll('.task__line')];
const toast = task.querySelector('.toast');
// A copy of the first label after the last one, so the strip can wrap forwards.
strip.append(lines[0].cloneNode(true));
/**
* Progress from 0 to 100. An attribute, so anything can drive it: this demo's pretend
* transfer, a real `onprogress`, or the element inspector. The stylesheet reads
* `--progress`, because CSS cannot take a number out of an attribute.
*/
function report(percent) {
const bounded = Math.min(Math.max(percent, 0), 100);
button.dataset.progress = String(Math.round(bounded));
button.style.setProperty('--progress', String(bounded / 100));
}
/** Sets the stage: idle, busy or done. The icon, the bar, the label and the toast read it. */
function enter(stage) {
button.dataset.stage = stage;
button.disabled = stage === 'busy';
button.setAttribute('aria-busy', String(stage === 'busy'));
say(STAGES.indexOf(stage));
}
/**
* Slides the label strip to line `at`. The strip only ever moves up. Going back to the
* first label, it slides on to the copy past the end, then jumps back to the real one
* with transitions off.
*/
function say(at) {
const from = Number(strip.dataset.at ?? 0);
const to = at === 0 && from > 0 ? lines.length : at;
strip.dataset.at = String(at);
strip.style.setProperty('--line', String(to));
// The first text node only: the busy label ends in animated dots.
button.setAttribute('aria-label', lines[at].firstChild.textContent.trim());
if (to <= from) return;
strip.addEventListener(
'transitionend',
() => {
if (to !== lines.length) return;
strip.dataset.settling = '';
strip.style.setProperty('--line', '0');
void strip.offsetWidth; // apply the jump now, while transitions are off
delete strip.dataset.settling;
},
{ once: true },
);
}
/** One press: busy with progress in steps, done, a receipt, then idle again. */
async function run() {
enter('busy');
for (let percent = STEP; percent <= 100; percent += STEP) {
report(percent);
await wait(TRANSFER / (100 / STEP));
}
enter('done');
toast.dataset.shown = 'true'; // the tick plays on this
await wait(RECEIPT);
toast.dataset.shown = 'false';
await wait(200); // let the toast leave before the button resets
enter('idle');
report(0);
}
button.addEventListener('click', () => void run());
}
/**
* Measures each toast's open width once the font has loaded, because CSS cannot
* transition width to `auto`. A hidden page has no widths, so it is shown for the
* measurement; nothing paints in between.
*/
async function measure() {
await document.fonts.ready;
for (const toast of document.querySelectorAll('.toast')) {
const page = toast.closest('[data-page]');
const away = page.hidden;
page.hidden = false;
toast.style.setProperty('--toast-width', `${toast.scrollWidth}px`);
page.hidden = away;
}
}
for (const task of document.querySelectorAll('.task')) wire(task);
pager();
void measure();
What it imports 6 shared files
shared/styles/base.css 115 lines
/*
* Fonts, reset and default typography. Nothing control-specific: every demo styles its
* own control. Only the UI face is here; the mono face is the portal's.
*/
@font-face {
font-family: 'Figtree';
font-style: normal;
font-weight: 300 900;
font-display: swap;
src: url('../fonts/figtree-latin.woff2') format('woff2');
unicode-range:
U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308,
U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
font-family: 'Figtree';
font-style: normal;
font-weight: 300 900;
font-display: swap;
src: url('../fonts/figtree-latin-ext.woff2') format('woff2');
unicode-range:
U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113,
U+2C60-2C7F, U+A720-A7FF;
}
/* Arial with Figtree's measurements, for the moment before Figtree arrives, so the text does
not move when it does. Measured on Figtree at 400 and 500. */
@font-face {
font-family: 'Figtree fallback';
src: local('Arial'), local('Liberation Sans');
size-adjust: 100.3%;
ascent-override: 94.7%;
descent-override: 24.9%;
line-gap-override: 0%;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
/* An author `display` on a component would beat the UA rule for [hidden], and then
`el.hidden = true` would stop working. Settled once here. */
[hidden] {
display: none !important;
}
body {
margin: 0;
background: var(--surface);
color: var(--ink);
--icon-filter: var(--filter-ink);
font-family: var(--font-ui);
font-size: var(--text-base);
line-height: var(--leading-base);
-webkit-font-smoothing: antialiased;
}
button,
input,
textarea,
select {
font: inherit;
color: inherit;
}
/* A second click on a button would otherwise select its label. */
button {
-webkit-user-select: none;
user-select: none;
}
:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
/*
* In the accessibility tree but not on screen: labels and legends that the visual design
* has no room for. Clipped rather than `display: none`, which would remove it from the
* tree too, and it also hides live radio inputs that must stay reachable by keyboard.
*/
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
/*
* Until the script defines <lord-icon> it is an unknown inline element with no size. These
* rules give it the box it will have, so nothing moves when it is defined.
*/
lord-icon {
display: inline-block;
width: var(--icon-size-32);
height: var(--icon-size-32);
}
/* A placeholder inside the icon fills it until the icon is ready. */
lord-icon:not(:defined) > img {
display: block;
width: 100%;
height: 100%;
}
/* Placeholders are black. Set --icon-filter wherever an icon's colour is set. */
lord-icon > img {
filter: var(--icon-filter);
}
shared/styles/index.css 4 lines
/* The one stylesheet a demo imports. */
@import './palette.css';
@import './tokens.css';
@import './base.css';
shared/styles/palette.css 87 lines
/*
* Generated from the Figma token export.
* Raw values only — roles live in tokens.css. Edit the Figma variables, not this file.
*/
:root {
/* color/ink */
--gray-0: #FFFFFF;
--gray-50: #F7F8FA;
--gray-100: #EEF0F3;
--gray-200: #DEE1E6;
--gray-300: #C3C7D0;
--gray-400: #9BA1AD;
--gray-500: #767C89;
--gray-600: #565C68;
--gray-700: #3D414B;
--gray-800: #282B33;
--gray-900: #16181D;
--gray-950: #0A0B0E;
/* color/signal */
--brand-100: #FFEEE9;
--brand-200: #FFD7CA;
--brand-300: #FFB199;
--brand-400: #FF7D5C;
--brand-500: #FF5A36;
--brand-600: #E8431F;
--brand-700: #C2340F;
/* color/success */
--green-100: #EDF9F1;
--green-300: #A7D9BC;
--green-700: #15803D;
/* color/error */
--red-100: #FDECEC;
--red-300: #F5B5B5;
--red-700: #DC2626;
/* typography/font */
--font-ui-name: 'Figtree';
--font-mono-name: 'JetBrains Mono';
/* typography/size */
--text-xs: 12px;
--text-sm: 14px;
--text-base: 16px;
--text-lg: 20px;
--text-xl: 24px;
--text-2xl: 32px;
--text-3xl: 40px;
/* typography/lineHeight */
--leading-xs: 16px;
--leading-sm: 20px;
--leading-base: 24px;
--leading-lg: 28px;
--leading-xl: 32px;
--leading-2xl: 40px;
--leading-3xl: 48px;
/* spacing (named after the value, the Figma scale is non-linear) */
--space-4: 4px;
--space-8: 8px;
--space-12: 12px;
--space-16: 16px;
--space-24: 24px;
--space-32: 32px;
--space-48: 48px;
--space-64: 64px;
--space-96: 96px;
/* size/icon */
--icon-size-16: 16px;
--icon-size-20: 20px;
--icon-size-24: 24px;
--icon-size-32: 32px;
--icon-size-40: 40px;
--icon-size-48: 48px;
--icon-size-64: 64px;
--icon-size-96: 96px;
/* radius */
--radius-sm: 4px;
--radius-md: 8px;
--radius-lg: 12px;
--radius-pill: 9999px;
}
shared/styles/tokens.css 93 lines
/*
* Design tokens by role. Raw values come from palette.css (generated); which grey is a
* border and which is muted text is decided here, and so would a dark mode be.
*/
:root {
/* Text. `--ink*` is always a colour; `--text-*` is always a size. */
--ink: var(--gray-950);
/* Text that reads as done or in progress, a step lighter than a heading. */
--ink-strong: var(--gray-800);
/* Body copy: a step down from --ink. */
--ink-soft: var(--gray-600);
--ink-muted: var(--gray-500);
--ink-subtle: var(--gray-400);
/* What has not started yet. */
--ink-faint: var(--gray-300);
--ink-inverse: var(--gray-0);
/* Backgrounds */
--surface: var(--gray-0);
--surface-muted: var(--gray-50);
/* A well inside a surface: the filled shape a single icon sits in. */
--surface-sunken: var(--gray-100);
/* Outlines */
--border: var(--gray-200);
/* The edge of a box that already has a fill, such as an input. */
--border-soft: var(--gray-100);
--border-strong: var(--gray-300);
--border-accent: var(--brand-400);
/* Brand accent */
--accent: var(--brand-500);
--accent-strong: var(--brand-600);
--accent-surface: var(--brand-100);
/* The outline of a tinted box, or a small shape on one. */
--accent-border: var(--brand-300);
/* Text or a mark on either of the above. */
--accent-ink: var(--brand-700);
/* Status. Warning rides the brand ramp — that is what the designs use. */
--success: var(--green-700);
--success-surface: var(--green-100);
--success-border: var(--green-300);
--warning: var(--brand-500);
--warning-surface: var(--brand-100);
--warning-border: var(--brand-300);
--danger: var(--red-700);
--danger-surface: var(--red-100);
--danger-border: var(--red-300);
/* Icons. Fed straight into --lord-icon-* by the demos. */
--icon-color: var(--gray-950);
--icon-accent: var(--brand-500);
/* Icon placeholders are black SVGs. Each filter turns black into the colour of the same
name. Made with a CSS filter generator: make a new one when its colour changes. */
--filter-ink: invert(2%) sepia(4%) saturate(4817%) hue-rotate(193deg) brightness(114%)
contrast(96%);
--filter-ink-soft: invert(33%) sepia(18%) saturate(323%) hue-rotate(182deg) brightness(100%)
contrast(90%);
--filter-ink-muted: invert(55%) sepia(23%) saturate(191%) hue-rotate(181deg) brightness(84%)
contrast(89%);
--filter-ink-subtle: invert(70%) sepia(11%) saturate(284%) hue-rotate(181deg) brightness(91%)
contrast(86%);
--filter-ink-faint: invert(76%) sepia(17%) saturate(99%) hue-rotate(184deg) brightness(99%)
contrast(100%);
--filter-ink-inverse: invert(100%);
--filter-accent: invert(49%) sepia(65%) saturate(3508%) hue-rotate(337deg) brightness(106%)
contrast(113%);
--filter-accent-strong: invert(29%) sepia(85%) saturate(1790%) hue-rotate(350deg)
brightness(94%) contrast(93%);
--filter-success: invert(38%) sepia(22%) saturate(2045%) hue-rotate(94deg) brightness(92%)
contrast(84%);
--filter-warning: var(--filter-accent);
--filter-danger: invert(48%) sepia(74%) saturate(7139%) hue-rotate(343deg) brightness(84%)
contrast(105%);
/* Type stacks. The families themselves are in palette.css. */
--font-ui:
var(--font-ui-name), 'Figtree fallback', -apple-system, BlinkMacSystemFont, 'Segoe UI',
Roboto, sans-serif;
--font-mono: var(--font-mono-name), ui-monospace, SFMono-Regular, Menlo, monospace;
/* Side padding of a page. The portal uses the same value, so demo and text line up. */
--gutter: clamp(var(--space-16), 5vw, var(--space-48));
/* A card's halo: no offset, so it reads as lift rather than as a light source. */
--shadow-sm: 0 0 7.5px color-mix(in srgb, var(--gray-400) 20%, transparent);
/* The same halo under a brand-coloured element. */
--shadow-accent: 0 0 7.5px color-mix(in srgb, var(--accent-strong) 40%, transparent);
}
shared/ui/pager.css 40 lines
/* The dots that page between the parts of a demo. Where they sit is the demo's business. */
.pager {
display: flex;
gap: var(--space-4);
}
/* A small dot inside a button big enough to hit. */
.pager__dot {
display: grid;
place-items: center;
width: var(--space-24);
height: var(--space-24);
padding: 0;
border: 0;
background: none;
cursor: pointer;
}
.pager__dot::before {
content: '';
width: var(--space-8);
height: var(--space-8);
border-radius: var(--radius-pill);
background: var(--border-strong);
transition: background 150ms ease;
}
.pager__dot:hover::before {
background: var(--ink-subtle);
}
.pager__dot[aria-pressed='true']::before {
background: var(--accent);
}
@media (prefers-reduced-motion: reduce) {
.pager__dot::before {
transition: none;
}
}
shared/ui/pager.ts 21 lines
/**
* Dots that switch between the parts of one demo. Demo scaffolding, not a control: it
* exists so a demo can show three variants of a component without stacking them.
*
* Parts carry `data-page`, dots carry `.pager__dot`, both in source order. A hidden page is
* out of the tab order and the accessibility tree.
*/
export function pager(root: ParentNode = document): (shown: number) => void {
const pages = [...root.querySelectorAll<HTMLElement>('[data-page]')];
const dots = [...root.querySelectorAll<HTMLButtonElement>('.pager__dot')];
const show = (shown: number) => {
pages.forEach((page, at) => (page.hidden = at !== shown));
dots.forEach((dot, at) => dot.setAttribute('aria-pressed', String(at === shown)));
};
dots.forEach((dot, at) => dot.addEventListener('click', () => show(at)));
show(0);
return show;
}
/**
* Dots that switch between the parts of one demo. Demo scaffolding, not a control: it
* exists so a demo can show three variants of a component without stacking them.
*
* Parts carry `data-page`, dots carry `.pager__dot`, both in source order. A hidden page is
* out of the tab order and the accessibility tree.
*/
export function pager(root = document) {
const pages = [...root.querySelectorAll('[data-page]')];
const dots = [...root.querySelectorAll('.pager__dot')];
const show = (shown) => {
pages.forEach((page, at) => (page.hidden = at !== shown));
dots.forEach((dot, at) => dot.setAttribute('aria-pressed', String(at === shown)));
};
dots.forEach((dot, at) => dot.addEventListener('click', () => show(at)));
show(0);
return show;
}
Icons
Hover a preview to play it. The icons are under the Lordicon License Terms, not the MIT licence of the code.
| Preview | Used as | Lordicon icon |
|---|---|---|
download |
system-outline-199-download (edited by hand) | |
upload |
system-outline-200-upload (edited by hand) | |
check-circle |
system-outline-24-check-circle (edited by hand) |