Skeleton¶
A placeholder for content that is loading, as lines of text, a block, or a circle. The wrapper is marked busy and carries a hidden status label.
Decision¶
| When | Use |
|---|---|
| A place where a list or card will appear, so the page does not jump | Skeleton |
| A short wait with no known shape | Spinner |
Usage¶
import { createSkeleton } from './configurationpage?name=myplugin_stolon.js';
list.appendChild(createSkeleton({ lines: 4 }).element);
Classes: stolon-skeleton, stolon-skeleton-line, stolon-skeleton-block, stolon-skeleton-circle. The handle is { element, getValue, setValue, done, destroy }.
Parts: stolon-skeleton-small, stolon-skeleton-medium, stolon-skeleton-large.
States and Modifiers¶
typeislines(default),block, orcircle.linesis 3 by default, and the last of several lines is 60 percent wide.sizeissmall,medium, orlargefor a block or a circle.- The wrapper has
aria-busy, andlabel("Loading") is the hidden status text. - With reduced motion asked for, the pulse stops.
done(content)clearsaria-busyand swaps in the loaded node, when given.destroyalso clearsaria-busy.
Gotchas¶
- Call
doneor remove the skeleton when the content arrives.
Reference¶
Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.
createSkeleton¶
function createSkeleton(options?: SkeletonOptions): SkeletonHandle
A placeholder for content that is loading, as lines of text, a block, or a circle. The wrapper is marked busy until done or destroy, and it carries a hidden label in a live region.
| Option | Type | What it does |
|---|---|---|
type |
'lines' | 'block' | 'circle' | string |
'lines', 'block', or 'circle' (default 'lines') |
lines |
number |
number of lines for type lines (default 3) |
size |
'small' | 'medium' | 'large' | string |
'small', 'medium', or 'large' for a block or a circle (default 'medium') |
label |
string |
text a screen reader reads (default 'Loading') |
| Handle member | Type |
|---|---|
getValue |
(): string |
setValue |
(next: string): void |
done |
(content?: Node | null): void |
destroy |
(): void |
| Class | What it looks like |
|---|---|
stolon-skeleton |
Placeholder for loading content, made of pulsing lines, a block, or a circle |
stolon-skeleton-line |
One line of text, with the last line shorter |
stolon-skeleton-block |
A block or a circle in three sizes |
Example¶
Example Code¶
<!-- title: Skeleton -->
<div id="mount"></div>
<script type="module">
const base = await window.__baseReady;
const view = document.getElementById('view');
const mount = document.getElementById('mount');
mount.appendChild(base.createSkeleton({ lines: 3 }).element);
const row = document.createElement('div');
row.style.cssText = 'display:flex;align-items:center;gap:12px;margin-top:14px';
row.appendChild(base.createSkeleton({ type: 'circle' }).element);
const block = base.createSkeleton({ type: 'block', size: 'small' }).element;
block.style.flex = '1';
row.appendChild(block);
mount.appendChild(row);
</script>