KitFeedback
Skeleton
Grey blocks shaped like what is coming (no spinner-only blocks): a line, a row, a tile, the hero.
import { Skeleton } from '@ergasti/bricks';Examples
Four states
AsyncBlock takes a resource state (useResource returns one): a skeleton while loading, an error with Retry, the empty text, then your render function.
Code
import { AsyncBlock, Skeleton, type ResourceState } from '@ergasti/bricks';
interface Totals { sales: string }
function States() {
const reload = () => {};
const loading: ResourceState<Totals> = { status: 'loading', reload };
const failed: ResourceState<Totals> = { status: 'error', error: { status: 500, message: '' }, reload };
const empty: ResourceState<Totals | null> = { status: 'ready', data: null, reload };
const ready: ResourceState<Totals> = { status: 'ready', data: { sales: 'EGP 184,300' }, reload };
const skeleton = <Skeleton shape="rows" count={2} />;
return (
<div style={{ display: 'grid', gap: 16, maxWidth: 360 }}>
<AsyncBlock state={loading} skeleton={skeleton}>{() => null}</AsyncBlock>
<AsyncBlock state={failed} skeleton={skeleton}>{() => null}</AsyncBlock>
<AsyncBlock state={empty} skeleton={skeleton} empty="Nothing here yet" isEmpty={(data) => data === null}>{() => null}</AsyncBlock>
<AsyncBlock state={ready} skeleton={skeleton}>{(data) => <b>Sales: {data.sales}</b>}</AsyncBlock>
</div>
);
}Skeleton shapes
line, rows, tile and hero match the shapes they stand in for, so the page does not jump when data arrives.
Code
import { Skeleton } from '@ergasti/bricks';
function Shapes() {
return (
<div style={{ display: 'grid', gap: 12, maxWidth: 420 }}>
<Skeleton shape="line" />
<Skeleton shape="rows" count={3} />
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
<Skeleton shape="tile" />
<Skeleton shape="hero" />
</div>
</div>
);
}Props
Prop
Type
Accessibility
- Roles in the markup:
alert. - ARIA attributes set:
aria-hidden,aria-busy.
Read from the component's source and tests. See Accessibility for the patterns the library follows.
Related
Button · AsyncBlock · Banner · ToastRegion
Source
src/kit/patterns/AsyncBlock.tsx (line 9) on GitHub.