Skeleton
Placeholder shapes for content still loading.
Demo
Usage
import { Skeleton } from '@tuttn/slant'
// Lines of text; the last of several is shorter.
<Skeleton lines={3} />
<Skeleton width="40%" />
// A block for an image or a chart, a circle for an avatar.
<Skeleton variant="block" height={120} />
<Skeleton variant="circle" width={40} />
// Skeletons are aria-hidden: mark the region busy, and name it.
<section aria-label="Profile" aria-busy={loading}>
{loading ? <Skeleton lines={3} /> : <Profile />}
</section>
// Held still, with no sweep.
<Skeleton lines={2} animate={false} />Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'text' | 'block' | 'circle' | 'text' | The shape: lines of text, a rectangle (an image, a chart, a card), or a circle (an avatar). |
lines | number | 1 | For `text`: how many lines. With more than one, the last is shorter, as a paragraph's is. |
width | number | string | — | The width, in px for a number or any CSS length for a string (`'60%'`, `'12ch'`). Text and block fill their container by default; a circle is 32px. |
height | number | string | — | The height, in px or a CSS length. For a block it defaults to 64px; a circle matches its width; for text it sets each line's bar, which sits in a line box of 1.5em, so the lines take the room the text will. |
animate | boolean | true | A soft light sweeping across the shapes. False holds them still. |
…rest | HTMLAttributes<HTMLSpanElement> | — | className, style and other attributes go on the root span, which also takes the ref. aria-hidden is always set. |
Accessibility
A skeleton is always aria-hidden: a screen reader has nothing to gain from grey bars. Set aria-busy on the region that is loading and give it a name, so it is heard as "Profile, busy" rather than empty, and drop aria-busy when the content arrives. If the wait is long or the arrival matters, say so with a role="status" line as well.
Keyboard
None: nothing in a skeleton is focusable. Keep real controls out of the loading region until they work.
Layout
Every variant is block-level. Text and block fill their container unless given a width; a circle is 32px and keeps its width as its height. Each text line is a bar in a 1.5em line box, so a three-line skeleton takes the room of three lines of body text and the layout doesn't jump when the text arrives. In a flex Row, give the text a flex: 1 wrapper, as the demo does.
Motion and direction
A soft band sweeps across each shape from the inline start: left to right, and right to left under dir="rtl", where the short last line also sits at the right. Under prefers-reduced-motion, or with animate={false}, the shapes hold still. In forced-colours mode they are drawn as outlines.