Skip to content
oxidaseSign in

Feedback and states

Loading shaped like its destination, empty results said plainly, and errors that say what to do next.

Region states

Every region that loads data has four states besides ready: loading, empty, error, and stale. AsyncRegion holds them in one place so they cannot be confused. Loading sets aria-busy, an error is announced with a way to try again, and stale content stays visible but dimmed while it refreshes.

  • Spatial holdToday, 6 trials
  • MachineYesterday, 4 puzzles
Code
"use client";

import { useEffect, useState } from "react";
import { AsyncRegion, EmptyState, ListRow, RowGroup, SegmentedControl, Skeleton, Stack } from "@oxidase/ui";

type Status = "loading" | "empty" | "error" | "ready" | "stale";

/**
 * One region in each of its states, starting ready. A failed request never
 * looks like an empty result, and trying again loads for a moment, then
 * settles, as a real request does.
 */
export function RegionDemo() {
  const [status, setStatus] = useState<Status>("ready");
  const [retrying, setRetrying] = useState(false);
  useEffect(() => {
    if (!retrying) return;
    const timer = window.setTimeout(() => {
      setRetrying(false);
      setStatus("ready");
    }, 1600);
    return () => window.clearTimeout(timer);
  }, [retrying]);
  return (
    <Stack gap="s16">
      <SegmentedControl<Status>
        label="Region state"
        size="small"
        value={status}
        onValueChange={(next) => {
          setRetrying(false);
          setStatus(next);
        }}
        options={[
          { value: "ready", label: "Ready" },
          { value: "loading", label: "Loading" },
          { value: "empty", label: "Empty" },
          { value: "error", label: "Error" },
          { value: "stale", label: "Stale" },
        ]}
      />
      <AsyncRegion
        label="Recent sessions"
        status={status === "stale" ? "ready" : status}
        stale={status === "stale"}
        onRetry={() => {
          setStatus("loading");
          setRetrying(true);
        }}
        error="Recent sessions could not load."
        skeleton={
          <Stack gap="s8">
            <Skeleton height="3.5rem" shape="block" />
            <Skeleton height="3.5rem" shape="block" />
          </Stack>
        }
        empty={<EmptyState title="No sessions yet">Your first session will appear here when it ends.</EmptyState>}
      >
        <RowGroup>
          <ListRow title="Spatial hold" detail="Today, 6 trials" />
          <ListRow title="Machine" detail="Yesterday, 4 puzzles" />
        </RowGroup>
      </AsyncRegion>
    </Stack>
  );
}
PropTypeDefaultDescription
status"loading" | "empty" | "error" | "ready"NoneThe region's state.
labelstringNoneNames the region, for its busy and error announcements.
skeletonReactNodeNonePlaceholders shaped like the content.
emptyReactNodeNoneUsually an EmptyState with the next step.
errorReactNodeNoneWhat failed. Defaults to a plain sentence.
onRetry() => voidNoneAdds a Try again action to the error.
stalebooleanfalseShows the last content dimmed while new content loads.

Loading

Loading belongs to its destination and is shaped like it: a skeleton of the rows, readings or plate that will appear, so nothing jumps when it arrives. Skeletons are ink at low strength, so they show on the canvas, on cards and on raised layers alike. A spinner is for a short action with no shape, such as a button that is saving. Skeletons are hidden from assistive technology; the region's busy state speaks for them.

Code
<Skeleton width="40%" height="1.5rem" />
<Skeleton width="70%" />
<Surface>
  <Stack gap="s12">
    <Skeleton width="2.5rem" height="2.5rem" shape="circle" />
    <Skeleton width="55%" height="1.25rem" />
    <Skeleton height="4rem" shape="block" />
  </Stack>
</Surface>
Code
<Spinner size="small" />
<Spinner />
<Spinner size="large" label="Loading sessions" />

With reduced motion, skeletons stop pulsing and hold at half strength, and a spinner becomes three still dots, so the state stays clear without movement.

Empty

Empty is not an error. Say plainly that there is nothing yet and, when there is one, offer the next step.

No sessions yet

Sessions appear here, grouped by day, after they end.
Code
<EmptyState
  title="No sessions yet"
  action={<Button variant="primary">Begin a session</Button>}
>
  Sessions appear here, grouped by day, after they end.
</EmptyState>

Notices

A notice speaks about a page or a section. Errors are announced at once; other tones are polite. A notice says what happened and what to do next.

Sessions are scored on the server.

Results appear when the session ends.

Not counted: the screen details weren't recorded

Code
<Notice title="Sessions are scored on the server.">
  Results appear when the session ends.
</Notice>
<Notice
  tone="warning"
  title="Not counted: the screen details weren't recorded"
/>
<Notice
  tone="danger"
  title="Export failed."
  action={<Button size="small">Try again</Button>}
>
  Nothing was downloaded. Your sessions are unchanged.
</Notice>

Rules

  • Exactly one error per region. Two messages about the same failure read as two failures.
  • An error says what happened and what to do next, in words a member would use.
  • Never show success in the danger tone, and never show an error as a toast.
  • Missing data stays visibly missing. Nothing is interpolated to fill a gap.

Do

A failure that says so and offers the next step.

No sessions yet

Avoid

A failed request shown as empty: the member believes their history is gone.