@dax-ui/skeleton
v0.8.0
Published
dax-ui Skeleton: loading placeholders for text, avatars, cards and detail fields
Maintainers
Readme
@dax-ui/skeleton
Loading placeholders in the shape of the content to come: lines of text, circles, and (rounded) rectangles, with a pulse or wave animation. Ready-made compositions cover a paragraph, a read-only "label + value" field and an avatar beside text.
Installation
pnpm add @dax-ui/skeletonMUI and Emotion are included; the app only needs React 18 or 19.
One-time setup per app (skip if the app already uses dax-ui): install
@dax-ui/theme and wrap the app in its UIProvider.
pnpm add @dax-ui/themeUsage
import { Skeleton, SkeletonAvatarRow, SkeletonField, SkeletonText } from '@dax-ui/skeleton';
// One line of text, as tall as the surrounding font
<Skeleton width={160} />
// Shapes
<Skeleton variant="circle" width={40} />
<Skeleton variant="rounded" width="100%" height={120} radius={16} />
// A paragraph: four lines, the last one 40% wide
<Skeleton lines={4} lastLineWidth="40%" />
<SkeletonText lines={3} fontSize={14} />
// Placeholders for a detail field and a comment
<SkeletonField />
<SkeletonAvatarRow lines={2} />
// Animation: pulse (default), wave or none
<Skeleton animation="wave" />Skeletons are hidden from screen readers. Mark the region that is loading instead, e.g.
<div aria-busy="true"> plus a visually hidden "Loading…" message.
Colors
colors takes base (the shape's fill) and highlight (the band that sweeps across with
animation="wave"). The defaults follow light and dark mode. To recolor every skeleton
inside an area, set the CSS variables on any ancestor:
<Skeleton colors={{ base: 'rgba(255, 255, 255, 0.2)' }} />
<div style={{ '--dax-skeleton-base': 'rgba(255, 255, 255, 0.2)' }}>…</div>DEFAULT_SKELETON_COLORS and DEFAULT_SKELETON_DARK_COLORS hold the defaults.
Props
Skeleton
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| animation | "pulse" \| "wave" \| "none" | pulse | How the placeholder moves. Every animation stops for viewers who ask for reduced motion. |
| className | string | | Class name on the root element. |
| colors | Partial<SkeletonColors> | | Overrides the placeholder colors, e.g. { base: 'rgba(255, 255, 255, 0.2)' } on a dark background. Unset keys keep the defaults (which follow light and dark mode). |
| height | string \| number | | Height: a number in px or any CSS length. Text lines take the height of the surrounding font; a circle with only a width is as tall as it is wide. |
| lastLineWidth | string \| number | 60% | Width of the last of several lines. |
| lineGap | string \| number | 6 | Space between lines, in px or any CSS length. |
| lines | number | 1 | Number of text lines (with variant="text"). The last line is shorter (lastLineWidth), so the block reads as a paragraph. |
| radius | string \| number | | Corner radius of rect and rounded shapes, in px or any CSS length. |
| style | CSSProperties | | Inline styles on the root element. |
| sx | SxProps<Theme> | | Style overrides on the root element. |
| variant | "text" \| "circle" \| "rect" \| "rounded" | text | Shape of the placeholder. |
| width | string \| number | | Width: a number in px or any CSS length, e.g. '60%'. Text lines fill their container by default. |
SkeletonText
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| animation | "pulse" \| "wave" \| "none" | pulse | How the placeholder moves. Every animation stops for viewers who ask for reduced motion. |
| className | string | | Class name on the root element. |
| colors | Partial<SkeletonColors> | | Overrides the placeholder colors, e.g. { base: 'rgba(255, 255, 255, 0.2)' } on a dark background. Unset keys keep the defaults (which follow light and dark mode). |
| fontSize | string \| number | 16 | Font size the lines stand in for, which sets their height, in px or any CSS length. |
| lastLineWidth | string \| number | 60% | Width of the last line. |
| lineGap | string \| number | 6 | Space between lines, in px or any CSS length. |
| lines | number | 3 | Number of lines. The last one is shorter. |
| style | CSSProperties | | Inline styles on the root element. |
| sx | SxProps<Theme> | | Style overrides on the root element. |
| width | string \| number | 100% | Width of the whole block. |
SkeletonField
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| animation | "pulse" \| "wave" \| "none" | pulse | How the placeholder moves. Every animation stops for viewers who ask for reduced motion. |
| className | string | | Class name on the root element. |
| colors | Partial<SkeletonColors> | | Overrides the placeholder colors, e.g. { base: 'rgba(255, 255, 255, 0.2)' } on a dark background. Unset keys keep the defaults (which follow light and dark mode). |
| icon | boolean | true | Shows a small square where the field's icon goes. |
| labelWidth | string \| number | 88 | Width of the label line. |
| orientation | "stacked" \| "inline" | stacked | stacked puts the value under the label; inline puts them side by side. |
| size | "sm" \| "md" \| "lg" | md | Matches the sizes of @dax-ui/detail-field: sm, md or lg. |
| style | CSSProperties | | Inline styles on the root element. |
| sx | SxProps<Theme> | | Style overrides on the root element. |
| valueLines | number | 1 | Number of value lines, for long values such as descriptions. |
| valueWidth | string \| number | 65% | Width of the value line. |
SkeletonAvatarRow
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| animation | "pulse" \| "wave" \| "none" | pulse | How the placeholder moves. Every animation stops for viewers who ask for reduced motion. |
| avatarSize | number | 40 | Avatar size in px. |
| avatarVariant | "circle" \| "rounded" | circle | Avatar shape. |
| className | string | | Class name on the root element. |
| colors | Partial<SkeletonColors> | | Overrides the placeholder colors, e.g. { base: 'rgba(255, 255, 255, 0.2)' } on a dark background. Unset keys keep the defaults (which follow light and dark mode). |
| lines | number | 2 | Number of text lines beside the avatar: a name, then shorter details. |
| style | CSSProperties | | Inline styles on the root element. |
| sx | SxProps<Theme> | | Style overrides on the root element. |
| width | string \| number | 100% | Width of the text block. |
