PageSkeletons
A whole screen while it loads, made of the skeletons of the pieces it will show. Nothing moves when the data arrives, because each skeleton has the box of its piece.
import { AppShellSkeleton, SkeletonWords, Stat, Table } from '@sypnia/ui/react'
A console screen
The shell's skeleton around the real page: its header, the stats' names, the toolbar, the table's columns and the panel are there, and only the values wait, as long as theirs. Press «Load again».
Code
import { useEffect, useState } from 'react';
import {
AppShell, AppShellSkeleton, Button, Logo, Page, PageHeader, Panel, SkeletonWords, Stat, StatGroup,
Table, Toolbar, ToolbarGroup,
} from '@sypnia/ui/react';
// A whole console screen while it loads, then the screen itself: the shell's skeleton (before the session is there)
// around the real page, whose values wait as skeletons of their own size. Nothing moves when the data arrives.
const nav = [
{ href: '#overview', label: 'Overview', icon: 'home' }, { href: '#tables', label: 'Tables', icon: 'table' }, { href: '#logs', label: 'Logs', icon: 'logs' },
{ href: '#team', label: 'Team', icon: 'users' }, { href: '#settings', label: 'Settings', icon: 'settings' },
] as const;
const rows = [
{ id: 1, name: 'orders', rows: '1,240', size: '2.1 MB' }, { id: 2, name: 'customers', rows: '312', size: '220 KB' },
{ id: 3, name: 'invoices', rows: '988', size: '1.4 MB' }, { id: 4, name: 'events', rows: '48,120', size: '31 MB' },
];
function Body({ loading }: { loading: boolean }) {
// The page is drawn at once with its title, its regions and their names; only what comes from the server is a
// skeleton, as long as the last values (here the same ones), so nothing moves when it comes.
return (
<Page>
<PageHeader title="Tables" lead="Everything your project keeps, as tables." actions={<Button variant="primary" icon="plus">New table</Button>} />
<StatGroup><Stat loading={loading} label="Tables" value="4" /><Stat loading={loading} label="Rows" value="50.6K" delta="+1.2K today" trend="good" /><Stat loading={loading} label="Size" value="34.7" unit="MB" /></StatGroup>
<Toolbar label="Tables" start><ToolbarGroup><Button size="sm" icon="upload">Import CSV</Button><Button size="sm" icon="download">Export</Button></ToolbarGroup></Toolbar>
<Table label="Tables" rows={loading ? undefined : rows} loading={loading} loadingRows={rows.length} rowKey={(r) => r.id} columns={[
{ id: 'name', header: 'Name', cell: (r) => r.name, skeleton: (i) => <SkeletonWords>{rows[i].name}</SkeletonWords> },
{ id: 'rows', header: 'Rows', cell: (r) => r.rows, numeric: true, skeleton: (i) => <SkeletonWords>{rows[i].rows}</SkeletonWords> },
{ id: 'size', header: 'Size', cell: (r) => r.size, numeric: true, skeleton: (i) => <SkeletonWords>{rows[i].size}</SkeletonWords> },
]} />
<Panel title="Keep in mind">Tables over 1 GB import in parts.</Panel>
</Page>
);
}
export default function Console() {
const [loading, setLoading] = useState(true);
const [run, setRun] = useState(0);
useEffect(() => { setLoading(true); const t = setTimeout(() => setLoading(false), 1800); return () => clearTimeout(t); }, [run]);
return (
<div className="sy-stack" style={{ '--gap': 'var(--s-3)' } as React.CSSProperties}>
<div><Button icon="refresh" onClick={() => setRun((n) => n + 1)}>Load again</Button></div>
<div style={{ '--sy-shell-h': '40rem', border: '1px solid var(--line)', borderRadius: 'var(--r-3)', overflow: 'hidden' } as React.CSSProperties} aria-busy={loading}>
{loading
? <AppShellSkeleton items={5}><Body loading /></AppShellSkeleton>
: <AppShell brand={<Logo product="Data" />} where="Checkout" nav={[...nav]} current="#tables"><Body loading={false} /></AppShell>}
</div>
</div>
);
} A docs page
What DocsShell shows the moment a link is pressed: the navigation stays, the article becomes its skeleton.
Code
---
// A docs page while it loads: what DocsShell shows the moment a link is pressed.
import SideNavSkeleton from '@sypnia/ui/astro/SideNavSkeleton.astro';
import DocsArticleSkeleton from '@sypnia/ui/astro/DocsArticleSkeleton.astro';
import TableOfContentsSkeleton from '@sypnia/ui/astro/TableOfContentsSkeleton.astro';
---
<div class="sy-docs" style="min-height:0;background:none">
<div class="sy-dshell" style="padding:0">
<div class="sy-dside" style="position:static;height:auto"><SideNavSkeleton sections={2} items={4} /></div>
<div class="sy-dmain" style="padding-top:var(--s-4)">
<DocsArticleSkeleton toc={false} paragraphs={2} />
<TableOfContentsSkeleton items={4} />
</div>
</div>
</div> A static page, in Astro
The same skeletons with no JavaScript, for docs and landings: every Astro piece that shows content has its Skeleton twin with the same name and props.
Code
---
// A static page while it loads, with no JavaScript: the Astro twins of the skeletons, in the same boxes as their pieces.
import PageHeaderSkeleton from '@sypnia/ui/astro/PageHeaderSkeleton.astro';
import StatGroupSkeleton from '@sypnia/ui/astro/StatGroupSkeleton.astro';
import TabsSkeleton from '@sypnia/ui/astro/TabsSkeleton.astro';
import PanelSkeleton from '@sypnia/ui/astro/PanelSkeleton.astro';
import CardSkeleton from '@sypnia/ui/astro/CardSkeleton.astro';
import KeyValueSkeleton from '@sypnia/ui/astro/KeyValueSkeleton.astro';
import IdentitySkeleton from '@sypnia/ui/astro/IdentitySkeleton.astro';
import CalloutSkeleton from '@sypnia/ui/astro/CalloutSkeleton.astro';
import ProgressSkeleton from '@sypnia/ui/astro/ProgressSkeleton.astro';
import SectionSkeleton from '@sypnia/ui/astro/SectionSkeleton.astro';
import FeatureGridSkeleton from '@sypnia/ui/astro/FeatureGridSkeleton.astro';
import TextSkeleton from '@sypnia/ui/astro/TextSkeleton.astro';
import BadgeSkeleton from '@sypnia/ui/astro/BadgeSkeleton.astro';
import ChipSkeleton from '@sypnia/ui/astro/ChipSkeleton.astro';
import CountSkeleton from '@sypnia/ui/astro/CountSkeleton.astro';
import StatusSkeleton from '@sypnia/ui/astro/StatusSkeleton.astro';
import AvatarSkeleton from '@sypnia/ui/astro/AvatarSkeleton.astro';
import Page from '@sypnia/ui/astro/Page.astro';
import Grid from '@sypnia/ui/astro/Grid.astro';
import Row from '@sypnia/ui/astro/Row.astro';
---
<div aria-busy="true">
<Page>
<PageHeaderSkeleton actions={2} />
<StatGroupSkeleton items={3} />
<TabsSkeleton items={4} />
<Grid min="16rem">
<PanelSkeleton lines={3} actions />
<CardSkeleton lines={2} />
<KeyValueSkeleton rows={3} />
</Grid>
<Row><IdentitySkeleton /><AvatarSkeleton size="lg" /><BadgeSkeleton dot /><ChipSkeleton /><CountSkeleton /><StatusSkeleton /></Row>
<CalloutSkeleton />
<ProgressSkeleton />
<SectionSkeleton><FeatureGridSkeleton items={3} /></SectionSkeleton>
<TextSkeleton title lines={3} />
</Page>
</div> A console page, in Astro
PageSkeleton is the header, a row of numbers and the table with its pagination, in the page's own boxes.
Code
---
// A console page while it loads, with no JavaScript: PageSkeleton is the header, the numbers and the table at once.
import PageSkeleton from '@sypnia/ui/astro/PageSkeleton.astro';
---
<div aria-busy="true">
<PageSkeleton stats={3} rows={4} columns={4} />
</div> Data and site pieces, in Astro
Cards, facts, checklists, plans, quotes, figures and tables have their Astro twins too, with the markup of the React skeletons.
Code
---
// The Astro twins of the data and site pieces, each in the box of its piece: cards, facts, lists, plans, quotes.
import CardGridSkeleton from '@sypnia/ui/astro/CardGridSkeleton.astro';
import ActionCardSkeleton from '@sypnia/ui/astro/ActionCardSkeleton.astro';
import DescriptionListSkeleton from '@sypnia/ui/astro/DescriptionListSkeleton.astro';
import ChecklistSkeleton from '@sypnia/ui/astro/ChecklistSkeleton.astro';
import FeatureListSkeleton from '@sypnia/ui/astro/FeatureListSkeleton.astro';
import AvatarGroupSkeleton from '@sypnia/ui/astro/AvatarGroupSkeleton.astro';
import DeltaSkeleton from '@sypnia/ui/astro/DeltaSkeleton.astro';
import FigureSkeleton from '@sypnia/ui/astro/FigureSkeleton.astro';
import QuoteSkeleton from '@sypnia/ui/astro/QuoteSkeleton.astro';
import PricingTableSkeleton from '@sypnia/ui/astro/PricingTableSkeleton.astro';
import CompareTableSkeleton from '@sypnia/ui/astro/CompareTableSkeleton.astro';
import TableSkeleton from '@sypnia/ui/astro/TableSkeleton.astro';
import Page from '@sypnia/ui/astro/Page.astro';
import Grid from '@sypnia/ui/astro/Grid.astro';
import Row from '@sypnia/ui/astro/Row.astro';
---
<div aria-busy="true">
<Page>
<CardGridSkeleton items={3} />
<Grid min="18rem">
<ActionCardSkeleton />
<DescriptionListSkeleton items={4} columns={2} />
</Grid>
<Grid min="18rem">
<ChecklistSkeleton items={3} />
<FeatureListSkeleton items={4} />
</Grid>
<Row><AvatarGroupSkeleton items={4} /><DeltaSkeleton /></Row>
<Grid min="18rem">
<FigureSkeleton />
<QuoteSkeleton />
</Grid>
<PricingTableSkeleton plans={3} rows={4} />
<CompareTableSkeleton columns={3} rows={4} />
<TableSkeleton columns={4} rows={3} pagination />
</Page>
</div> When to use it
Use it when
- The first load of any screen whose data comes from the network.
- Composing it from the skeletons of the very pieces the screen uses, with the same counts (rows, stats, items).
Do not use it when
- A spinner, a «Loading…» text or an empty screen.
- A generic grey block: the skeleton should have the shape of what is coming.
For everyone
- The region that waits is marked
aria-busy="true"; every skeleton is hidden from screen readers. - When the content arrives, focus stays where it was.
Props
| AppShellSkeleton | Type | Default |
|---|---|---|
childrenThe skeleton of the page that will load inside. | ReactNode | |
itemsHow many items the navigation will have. | number | 6 |
| Stat | Type | Default |
|---|---|---|
labelrequired | ReactNode | |
delta | ReactNode | |
loadingThe name stays; the number is a skeleton until it comes, as long as `value` when one is given (the last known, or a typical one), and so is how it moved when the Stat has one: pass `delta` while loading to keep its line (a typical one, or `true` for a bar). | boolean | |
trend | "flat" | "good" | "bad" | |
unit | ReactNode | |
value | ReactNode |
| Table | Type | Default |
|---|---|---|
columnsrequired | Column<Row>[] | |
labelrequiredA name for screen readers. | string | |
rowKeyrequired | (row: Row) => string | number | |
rowsrequired | Row[] | undefined | |
dense | boolean | |
emptyWhat to show when there are no rows: an EmptyState with the next step. | ReactNode | |
errorSomething failed: the region says so. Say what happened in plain words. | ReactNode | |
loadingData is on its way: rows are drawn as skeletons of the right shape. | boolean | |
loadingRowsHow many skeleton rows to draw while loading: as many as will come (the count of the last visit, a known total). Default 6, never more than a page. | number | |
onRetryWith `error`: shows a «Try again» button that calls it. | (() => void) | |
onRowClick | ((row: Row) => void) | |
pageSizeRows per page, 25 by default: every table paginates by itself. For server-side pages pass `pagination` instead. | number | |
paginationServer-side pagination: the table shows `rows` as they are and this bar under them. | { page: number; pageSize: number; total: number; onPage: (p: number) => void; onPageSize?: ((s: number) => void); } | |
toolbar | ReactNode |