Skeleton
Skeleton is a placeholder for content that is still loading. Use it where the layout is known but the data is not, so the page keeps its shape instead of jumping when content arrives. Available from Click UI 0.16.0.
Example
Props
Skeleton has two shapes. text (the default) draws lines of text and takes size and lines. rectangle draws a box and takes height. The props of one shape are not accepted by the other.
Prop | Type | Default value | Description |
|---|---|---|---|
Prop shape | Type "text" | "rectangle" | Default value "text" | Description Whether to draw lines of text or a box |
Prop width | Type string | Default value fills the parent | Description Any CSS width, for example 60% or 6rem |
Prop size | Type "sm" | "md" | Default value "md" | Description Text shape only. Each line is as tall as a line of Text at the same size |
Prop lines | Type number | Default value 1 | Description Text shape only. Number of lines. The last of several lines is 75% wide |
Prop height | Type string | Default value fills the parent | Description Rectangle shape only. Any CSS height, for example 4rem |
Quick start
import { Skeleton, Text } from '@clickhouse/click-ui'
function Description({ loading, text }: { loading: boolean; text: string }) {
if (loading) {
return <Skeleton lines={2} />
}
return <Text>{text}</Text>
}Accessibility
A skeleton is decorative. Tell assistive technology that the region is loading yourself, for example with aria-busy="true" on the container that will receive the content. Skeletons on screen together share one shimmer sweep, and the fill is static when the user prefers reduced motion.
Related components
- Table: Shows skeleton rows itself with
loadingVariant="skeleton". - Text: A text skeleton matches the line height of Text at the same size.
- ProgressBar: Use when you can report how far a task has progressed.
Common use cases
Card placeholder
import { Skeleton, Container } from '@clickhouse/click-ui'
function CardPlaceholder() {
return (
<Container orientation='horizontal' gap='md' fillWidth alignItems='start'>
<Skeleton shape='rectangle' width='4rem' height='4rem' />
<Container orientation='vertical' gap='sm' fillWidth>
<Skeleton width='40%' />
<Skeleton size='sm' lines={2} />
</Container>
</Container>
)
}