Components

Skeleton

A placeholder in the shape of content that is still loading, so the page keeps its layout when the content arrives.

Usage

import { Skeleton } from 'nyctoui/skeleton'

<div aria-busy="true" aria-label="Loading post">
  <Skeleton shape="circle" />
  <Skeleton shape="text" sx={styles.title} />
  <Skeleton />
</div>

A skeleton is a tinted shape that breathes slowly while the content it stands for loads. Draw it at the size of that content, so nothing moves when the real thing replaces it. For a task with a known end, such as an upload, use a Progress instead; for a button that is waiting, its own loading state.

ui-sdk has no skeleton, since it has no behavior to share. It’s built with renderElement, so it takes the render prop like other parts.

Good for

  • A feed or an inbox loading its first page of rows.
  • A profile header loading its avatar and name.
  • Dashboard cards waiting for their numbers.
  • A product grid in a shop while images load.

Examples

Shapes

block stands for a card, an image or a chart, with 8px corners. text is one line of 14px text and fills its line; set a width to vary the lines. pill matches a 32px button and circle an avatar. Size any of them with sx.

Swapping in content

Give each row the same height whether it holds text or a skeleton, and the list stays put when the data arrives. Press Reload to see it again.

Accessibility

Skeletons are hidden from assistive technology: a stack of empty shapes means nothing read aloud. Mark the region that is loading with aria-busy and a label instead, and clear it when the content is in. With reduced motion, skeletons hold still.

Best practices

Do
  • Match the size and shape of the content that’s coming, so nothing jumps when it arrives.
  • Show about as many rows as usually load, not one or fifty.
  • Swap in an error or an empty state if loading takes too long or fails.
Don’t
  • Use a skeleton when you don’t know the content’s size. Use a spinner or progress.
  • Put a spinner and skeletons in the same area. Pick one way to show loading.

API reference

Skeleton

A <div> by default, with aria-hidden. Other props go to the element.

PropTypeDefault
shape
A full-width 80px block, a full-width line of 14px text, a 32px pill or a 32px circle.
'block' | 'text' | 'pill' | 'circle''block'
render
Renders another element, such as a <span> inside text, with the skeleton’s props.
ReactElement | (props) => ReactElement—
sx
StyleX styles merged after the built-in ones. Set the size here.
StyleXStyles—