Skeleton

A gray placeholder in the shape of content that is still loading.

Usage

Code
import { Skeleton, SkeletonCircle, SkeletonText } from '@leverui/components';
Code
<Stack gap="6" style={{ 'max-width': 'var(--leverui-sizes-xs)' }}>
  <HStack style={{ width: '100%' }}>
    <SkeletonCircle size="10" />
    <SkeletonText noOfLines={2} />
  </HStack>
  <Skeleton style={{ height: '200px' }} />
</Stack>

Examples

Feed

Use the Skeleton component to create a feed skeleton.

Text

Use the SkeletonText component to create a skeleton for text.

With Children

Use the loading prop to show the skeleton while the content is loading.

Select
Select

Variants

Use the variant prop to change the visual style of the Skeleton.

pulse

shine

Content Loading

When loading is changed to false, the Skeleton component will fade in.

Your report is ready

Start and End Color

Use the --leverui-skeleton-start-color and --leverui-skeleton-end-color CSS variables to change the start and end color of the skeleton.

Guides

Skeleton keeps its children mounted but hidden until loading is false. SkeletonCircle is a round placeholder. SkeletonText shows lines in place of text.

Loading and composition

Keep the content inside Skeleton so the placeholder takes up the same space. When loading becomes false, the children fade in. No status role and nothing announced to screen readers: add your own accessible loading message if people need one.

SkeletonCircle: size sets both width and height. SkeletonText: three lines by default; with more than one, the last is 80% wide. Inline children stay mounted and hidden in each line, then show as one line once loaded. rootProps passes native props to the element that stacks the lines. gap sets the space between lines.

Pass a function to repeat your own content in every line.

Code
function renderTextLine() {
  return <span>Loading content</span>;
}

<SkeletonText noOfLines={3}>{renderTextLine}</SkeletonText>;

A JSX element is a single DOM node, so passed directly it shows in only one line.

Variants and motion

variant: pulse (default), shine (a moving gradient), or none. Animation stops under reduced motion. Pass an object for a different variant per breakpoint.

Code
<Skeleton variant="shine" style={{ width: '100%', height: 'var(--leverui-sizes-5)' }} />
<Skeleton variant={{ base: 'pulse', md: 'shine' }} />

Props

PropDefaultTypeDescription
loadingtruebooleanShow the placeholder. Set false to show the content.
variantpulse'pulse' | 'shine' | 'none' or responsive mapPlaceholder look and motion.
asdivNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the skeleton's props.
unstyledfalsebooleanTurn off the Lever UI styles.

SkeletonPropsProvider sets default props, which can be reactive, for the skeletons inside it. A prop on a skeleton wins. Skeleton also accepts native HTML attributes, a ref, class, and style.

Customize with CSS

Import @leverui/components/styles.css before your own stylesheet.

Classes: .leverui-skeleton, .leverui-skeleton-text (text wrapper), .leverui-skeleton-text__line (each line).

Root attributes: data-loading, data-variant, plus one per breakpoint, such as data-variant-md.

VariablePurpose
--leverui-skeleton-bgPulse placeholder background
--leverui-skeleton-start-colorShine gradient start color
--leverui-skeleton-end-colorShine gradient end color
--leverui-skeleton-durationPulse or shine animation duration
--leverui-skeleton-fade-durationFade duration when loading becomes false
--leverui-skeleton-text-widthWidth of the text stack
--leverui-skeleton-line-heightHeight of each loading text line
--leverui-skeleton-last-line-widthWidth of the final loading line
Code
.leverui-skeleton[data-brand-placeholder] {
  --leverui-skeleton-start-color: #f3c9d7;
  --leverui-skeleton-end-color: #d95f91;
}

To reuse a look, set the variables in a CSS class.