Skip to content

LoadingPage

How a page waits: at once, the page itself with its title, regions and names, only its values as skeletons as long as the last ones, silent; after 8 seconds one line that says it is still working; after 20, it stops waiting and says what to do. Four shapes of console page.

import { SkeletonWords, SkeletonOf, Table, Stat, FormRow } from '@sypnia/ui/react'

On this page
  1. On a desktop
  2. On a phone
  3. When it never answers
  4. When to use it
  5. For everyone
  6. Props

On a desktop

Choose a shape and how the network behaves, then «Load again». The clock runs ten times faster here: 0.8 s stands for 8 s.

Tables

Everything this project keeps.

Tables
Rows
Size
NameRowsSizeChanged
Code
import { useEffect, useState, type ReactNode } from 'react';
import {
  Button, Columns, EmptyState, Field, FormRow, FormSection, Input, KeyValue, Notice, Page, PageHeader, Panel, RegionSelect, SegmentedControl,
  SkeletonOf, SkeletonWords, Stack, Stat, StatGroup, Switch, Table, Tabs, Text, Toolbar, ToolbarGroup, VerticalTabs, VisuallyHidden, useSypnia,
} from '@sypnia/ui/react';

// How a page waits. At once: the page itself, with its title, its regions and their names, and only what comes from
// the server as skeletons as long as the last values, silent. After 8 seconds a short line says it is still working, in
// a place kept for it from the first frame.
// After 20 seconds it stops waiting: what happened, and «Try again». Four shapes of console page: a list, a record, a
// form and settings. Choose one, and how the network behaves.
type Shape = 'list' | 'record' | 'form' | 'settings';
type Speed = 'fast' | 'slow' | 'fails';
const en = {
  shape: 'Shape of the page', list: 'List', record: 'Record', form: 'Form', settings: 'Settings',
  speed: 'The network', fast: 'Answers', slow: 'Is slow', fails: 'Never answers', again: 'Load again',
  still: 'Still loading. Large projects take a little longer.', failTitle: 'This page did not load',
  failBody: 'The server did not answer in 20 seconds. Your data is safe. Check your connection and try again.', retry: 'Try again',
  tables: 'Tables', tablesLead: 'Everything this project keeps.', newTable: 'New table', count: 'Tables', rows: 'Rows', size: 'Size', importCsv: 'Import CSV', exportCsv: 'Export',
  name: 'Name', updated: 'Changed',
  orders: 'orders', ordersLead: 'A table of northwind-shop.', addRow: 'Add a row', more: 'Options',
  overview: 'Overview', columns: 'Columns', indexes: 'Indexes', access: 'Access', facts: 'Facts', recent: 'Last changes',
  owner: 'Owner', created: 'Created', region: 'Region', api: 'API',
  newDb: 'New database', newDbLead: 'A Postgres database with its API, in the region you choose.', place: 'Name and place', placeLead: 'What it is called and where it lives.',
  dbName: 'Name', dbRegion: 'Region', backups: 'Backups', backupsLead: 'Copies to go back to.', daily: 'A copy every day', keep: 'Kept for', keepV: '30 days',
  settingsTitle: 'Settings', settingsLead: 'How northwind-shop works for everyone in it.', general: 'General', security: 'Security', apiTab: 'API', danger: 'Danger zone',
  project: 'Project name', projectD: 'Shown in the console and in emails.', tz: 'Time zone', tzD: 'Used for charts and reports.', lang: 'Language of emails', langD: 'For invitations and alerts.',
};
const es: typeof en = {
  shape: 'Forma de la página', list: 'Lista', record: 'Registro', form: 'Formulario', settings: 'Ajustes',
  speed: 'La red', fast: 'Responde', slow: 'Va lenta', fails: 'No responde', again: 'Cargar de nuevo',
  still: 'Sigue cargando. Los proyectos grandes tardan un poco más.', failTitle: 'Esta página no cargó',
  failBody: 'El servidor no respondió en 20 segundos. Tus datos están a salvo. Revisa tu conexión e intenta de nuevo.', retry: 'Intentar de nuevo',
  tables: 'Tablas', tablesLead: 'Todo lo que guarda este proyecto.', newTable: 'Nueva tabla', count: 'Tablas', rows: 'Filas', size: 'Tamaño', importCsv: 'Importar CSV', exportCsv: 'Exportar',
  name: 'Nombre', updated: 'Cambió',
  orders: 'orders', ordersLead: 'Una tabla de northwind-shop.', addRow: 'Agregar una fila', more: 'Opciones',
  overview: 'Resumen', columns: 'Columnas', indexes: 'Índices', access: 'Acceso', facts: 'Datos', recent: 'Últimos cambios',
  owner: 'Dueño', created: 'Creada', region: 'Región', api: 'API',
  newDb: 'Nueva base de datos', newDbLead: 'Una base Postgres con su API, en la región que elijas.', place: 'Nombre y lugar', placeLead: 'Cómo se llama y dónde vive.',
  dbName: 'Nombre', dbRegion: 'Región', backups: 'Copias', backupsLead: 'Copias a las que volver.', daily: 'Una copia cada día', keep: 'Se guardan', keepV: '30 días',
  settingsTitle: 'Ajustes', settingsLead: 'Cómo funciona northwind-shop para todos.', general: 'General', security: 'Seguridad', apiTab: 'API', danger: 'Zona de peligro',
  project: 'Nombre del proyecto', projectD: 'Se ve en la consola y en los correos.', tz: 'Zona horaria', tzD: 'Para gráficas e informes.', lang: 'Idioma de los correos', langD: 'Para invitaciones y alertas.',
};
const tables = [
  { name: 'orders', rows: '1,240', size: '2.1 MB', updated: '4 minutes ago' }, { name: 'customers', rows: '312', size: '220 KB', updated: '2 hours ago' },
  { name: 'invoices', rows: '988', size: '1.4 MB', updated: 'yesterday' }, { name: 'events', rows: '48,120', size: '31 MB', updated: '3 days ago' },
  { name: 'refunds', rows: '57', size: '48 KB', updated: 'last week' },
];
const regions = [{ value: 'sa-east', label: 'São Paulo', flag: 'BR' }, { value: 'us-east', label: 'Virginia', flag: 'US' }, { value: 'eu-west', label: 'Ireland', flag: 'IE' }];

/** One page of each shape. `loading`: the same page, with what comes from the server as skeletons of its own size. */
function Shape({ shape, loading }: { shape: Shape; loading: boolean }) {
  const { locale } = useSypnia();
  const c = locale.startsWith('es') ? es : en;
  const words = (n: ReactNode) => (loading ? <SkeletonWords>{n}</SkeletonWords> : n);
  const wait = (n: ReactNode) => (loading ? <SkeletonOf>{n}</SkeletonOf> : n);
  if (shape === 'record') {
    return (
      <>
        <PageHeader title={c.orders} lead={c.ordersLead} actions={<><Button icon="more">{c.more}</Button><Button variant="primary" icon="plus">{c.addRow}</Button></>} />
        <Tabs label={c.orders} items={[
          { id: 'overview', label: c.overview, content: (
            <Columns cols={2} stack>
              <KeyValue loading={loading} items={[[c.owner, 'Ana Ruiz'], [c.rows, '1,240'], [c.size, '2.1 MB'], [c.created, 'Mar 3, 2026'], [c.api, '/rest/v1/orders']]} />
              <Panel title={c.recent}><Stack gap={2}>{['Ana Ruiz added 12 rows', 'Luis Ortega changed the column total', 'Marta Gil added an index'].map((t) => <Text key={t} size="sm">{words(t)}</Text>)}</Stack></Panel>
            </Columns>
          ) },
          { id: 'columns', label: c.columns, content: null }, { id: 'indexes', label: c.indexes, content: null }, { id: 'access', label: c.access, content: null },
        ]} />
      </>
    );
  }
  if (shape === 'form') {
    return (
      <>
        <PageHeader title={c.newDb} lead={c.newDbLead} />
        <FormSection title={c.place} description={c.placeLead}>
          <Field label={c.dbName}><Input defaultValue="orders" /></Field>
          <Field label={c.dbRegion}>{wait(<RegionSelect regions={regions} />)}</Field>
        </FormSection>
        <FormSection title={c.backups} description={c.backupsLead}>
          {wait(<Switch label={c.daily} defaultChecked />)}
          <Field label={c.keep}>{wait(<Input defaultValue={c.keepV} />)}</Field>
        </FormSection>
      </>
    );
  }
  if (shape === 'settings') {
    const general = (
      <Stack gap={0}>
        <FormRow label={c.project} description={c.projectD} loading={loading}><Input aria-label={c.project} defaultValue="Northwind shop" /></FormRow>
        <FormRow label={c.tz} description={c.tzD} loading={loading}><Input aria-label={c.tz} defaultValue="America/Bogota (UTC-5)" /></FormRow>
        <FormRow label={c.lang} description={c.langD} loading={loading}><Input aria-label={c.lang} defaultValue="English" /></FormRow>
      </Stack>
    );
    return (
      <>
        <PageHeader title={c.settingsTitle} lead={c.settingsLead} />
        <VerticalTabs label={c.settingsTitle} items={[
          { id: 'general', label: c.general, icon: 'settings', content: general }, { id: 'security', label: c.security, icon: 'lock', content: null },
          { id: 'api', label: c.apiTab, icon: 'api', content: null }, { id: 'danger', label: c.danger, icon: 'warning', content: null },
        ]} />
      </>
    );
  }
  return (
    <>
      <PageHeader title={c.tables} lead={c.tablesLead} actions={<Button variant="primary" icon="plus">{c.newTable}</Button>} />
      <StatGroup>
        <Stat loading={loading} label={c.count} value="5" />
        <Stat loading={loading} label={c.rows} value="50.6K" />
        <Stat loading={loading} label={c.size} value="34.8" unit="MB" />
      </StatGroup>
      <Toolbar label={c.tables} start><ToolbarGroup><Button size="sm" icon="upload">{c.importCsv}</Button><Button size="sm" icon="download">{c.exportCsv}</Button></ToolbarGroup></Toolbar>
      <Table label={c.tables} rows={loading ? undefined : tables} loading={loading} loadingRows={tables.length} rowKey={(t) => t.name} columns={[
        { id: 'name', header: c.name, cell: (t) => t.name, skeleton: (i) => <SkeletonWords>{tables[i].name}</SkeletonWords> },
        { id: 'rows', header: c.rows, numeric: true, cell: (t) => t.rows, skeleton: (i) => <SkeletonWords>{tables[i].rows}</SkeletonWords> },
        { id: 'size', header: c.size, numeric: true, cell: (t) => t.size, skeleton: (i) => <SkeletonWords>{tables[i].size}</SkeletonWords> },
        { id: 'updated', header: c.updated, cell: (t) => t.updated, skeleton: (i) => <SkeletonWords>{tables[i].updated}</SkeletonWords> },
      ]} />
    </>
  );
}

export default function LoadingPage({ shape: initialShape = 'list', speed: initialSpeed = 'slow' }: { shape?: Shape; speed?: Speed }) {
  const { locale } = useSypnia();
  const c = locale.startsWith('es') ? es : en;
  const [shape, setShape] = useState<Shape>(initialShape);
  const [speed, setSpeed] = useState<Speed>(initialSpeed);
  const [run, setRun] = useState(0);
  const [phase, setPhase] = useState<'waiting' | 'still' | 'failed' | 'ready'>('waiting');
  // The gallery runs the clock ten times faster: 0.8 s stands for 8 s.
  const second = 100;
  useEffect(() => {
    setPhase('waiting');
    const timers = [setTimeout(() => setPhase((p) => (p === 'waiting' ? 'still' : p)), 8 * second)];
    if (speed === 'fast') timers.push(setTimeout(() => setPhase('ready'), 6 * second));
    if (speed === 'slow') timers.push(setTimeout(() => setPhase('ready'), 13 * second));
    if (speed === 'fails') timers.push(setTimeout(() => setPhase('failed'), 20 * second));
    return () => timers.forEach(clearTimeout);
  }, [shape, speed, run]);
  return (
    <Stack gap={0}>
      <Page>
        <Columns cols={3} stack>
          <SegmentedControl label={c.shape} value={shape} onChange={setShape} options={[{ value: 'list', label: c.list }, { value: 'record', label: c.record }, { value: 'form', label: c.form }, { value: 'settings', label: c.settings }]} />
          <SegmentedControl label={c.speed} value={speed} onChange={setSpeed} options={[{ value: 'fast', label: c.fast }, { value: 'slow', label: c.slow }, { value: 'fails', label: c.fails }]} />
          <div><Button icon="refresh" onClick={() => setRun((n) => n + 1)}>{c.again}</Button></div>
        </Columns>
      </Page>
      <div aria-busy={phase === 'waiting' || phase === 'still'}>
        {phase === 'failed' ? (
          <Page><EmptyState tone="fail" title={c.failTitle} actions={<Button variant="primary" icon="refresh" onClick={() => setRun((n) => n + 1)}>{c.retry}</Button>}>{c.failBody}</EmptyState></Page>
        ) : (
          <Page>
            {/* The line that says it is still working has its place from the first frame, so nothing moves when it fades
                in (and nothing moves when the page arrives): it is drawn hidden until then. Screen readers hear it once. */}
            <div aria-hidden="true" style={{ visibility: phase === 'still' ? 'visible' : 'hidden', opacity: phase === 'still' ? 1 : 0, transition: 'opacity 300ms ease-out' }}>
              <Notice tone="info" icon="hourglass">{c.still}</Notice>
            </div>
            <VisuallyHidden><span role="status">{phase === 'still' ? c.still : ''}</span></VisuallyHidden>
            <Shape shape={shape} loading={phase !== 'ready'} />
          </Page>
        )}
      </div>
    </Stack>
  );
}

On a phone

The same pages at 390 px: the columns stack while loading, as the pages will.

When it never answers

After 20 seconds the skeleton goes and the page says what happened.

orders

A table of northwind-shop.

Owner
Rows
Size
Created
API

Last changes

When to use it

Use it when

  • Every screen whose data comes from the network: the real pieces, with only the values that come as SkeletonWords and SkeletonOf.
  • The 8 and 20 second steps on every page, so slowness is never silent and waiting is never endless.
  • The «still loading» line has its place from the first frame and fades in there: nothing moves when it appears or when the page arrives.

Do not use it when

  • A spinner, a «Loading…» text, or a blank page.
  • A skeleton that does not match the page: when the content comes, nothing should move.
  • Waiting forever: after 20 seconds, say what happened and offer «Try again».

For everyone

  • The region that waits is aria-busy and the skeletons are hidden from screen readers.
  • The «still loading» line is a status: it is read once, politely.
  • When the page fails, the message is read at once and «Try again» is the next stop.

Props

TableTypeDefault
columnsrequired Column<Row>[]
labelrequired

A name for screen readers.

string
rowKeyrequired (row: Row) => string | number
rowsrequired Row[] | undefined
dense boolean
empty

What to show when there are no rows: an EmptyState with the next step.

ReactNode
error

Something failed: the region says so. Say what happened in plain words.

ReactNode
loading

Data is on its way: rows are drawn as skeletons of the right shape.

boolean
loadingRows

How 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
onRetry

With `error`: shows a «Try again» button that calls it.

(() => void)
onRowClick ((row: Row) => void)
pageSize

Rows per page, 25 by default: every table paginates by itself. For server-side pages pass `pagination` instead.

number
pagination

Server-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
StatTypeDefault
labelrequired ReactNode
delta ReactNode
loading

The 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
FormRowTypeDefault
labelrequired ReactNode
danger boolean
description ReactNode
htmlFor string
loading

The setting's value is on its way: the text stays and the control (`children`, when given) is drawn as a skeleton of its own box; without children, a skeleton of a control's height.

boolean
  1. On a desktop
  2. On a phone
  3. When it never answers
  4. When to use it
  5. For everyone
  6. Props

    Search pages, sections and terms