PageSkeletons
Una pantalla completa mientras carga, hecha con los skeletons de las piezas que va a mostrar. Nada se mueve cuando llegan los datos, porque cada skeleton tiene la caja de su pieza.
import { AppShellSkeleton, SkeletonWords, Stat, Table } from '@sypnia/ui/react'
Una pantalla de consola
El skeleton del armazón alrededor de la página real: su encabezado, los nombres de las cifras, la barra, las columnas de la tabla y el panel están ahí, y solo los valores esperan, tan largos como los suyos. Presiona «Load again».
Código
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>
);
} Una página de documentación
Lo que muestra DocsShell apenas se presiona un enlace: la navegación se queda y el artículo se vuelve su skeleton.
Código
---
// 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> Una página estática, en Astro
Los mismos skeletons sin JavaScript, para documentación y landings: cada pieza Astro que muestra contenido tiene su gemelo Skeleton con el mismo nombre y las mismas props.
Código
---
// 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> Una página de consola, en Astro
PageSkeleton es el encabezado, una fila de cifras y la tabla con su paginación, en las cajas de la página.
Código
---
// 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> Piezas de datos y de sitio, en Astro
Las tarjetas, los datos, las listas de pasos, los planes, las citas, las figuras y las tablas también tienen sus gemelos en Astro, con el mismo marcado que los skeletons de React.
Código
---
// 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> Cuándo usarlo
Úsalo cuando
- La primera carga de cualquier pantalla cuyos datos vienen de la red.
- Armarla con los skeletons de las mismas piezas que usa la pantalla, con las mismas cantidades (filas, cifras, elementos).
No lo uses cuando
- Una rueda de carga, un texto de «Cargando…» o una pantalla vacía.
- Un bloque gris genérico: el skeleton debe tener la forma de lo que viene.
Para todos
- La región que espera se marca con
aria-busy="true"; todos los skeletons están ocultos para los lectores de pantalla. - Cuando llega el contenido, el foco se queda donde estaba.
Props
| AppShellSkeleton | Tipo | Por defecto |
|---|---|---|
childrenThe skeleton of the page that will load inside. | ReactNode | |
itemsHow many items the navigation will have. | number | 6 |
| Stat | Tipo | Por defecto |
|---|---|---|
labelobligatorio | 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 | Tipo | Por defecto |
|---|---|---|
columnsobligatorio | Column<Row>[] | |
labelobligatorioA name for screen readers. | string | |
rowKeyobligatorio | (row: Row) => string | number | |
rowsobligatorio | 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 |