Skip to documentation content

Loading State

Show that long-running work is in progress, with a label and the time elapsed.

loading-state-demo

Overview

Loading State is one line: a small animated mark, a label that says what is in progress, and how long it has been running. Use it when work takes long enough that a person may wonder whether anything is happening.

Render it while the work runs and remove it when the work ends. Loading State does not know when your work finishes and reports no progress of its own. The elapsed time is real: it counts from startedAt, or from when the component mounted.

Use Thinking State instead when you have steps to show.

Anatomy

LoadingState
  • MarkA compact decorative pattern of pulsing cells
  • LabelWhat is in progress
  • ElapsedSeconds, then minutes and seconds, since the work began

Installing loading-state brings Text Shimmer along as a registry dependency.

Behavior

Patterns

All patterns occupy the same space and use the same foreground color. The pattern is decorative and reports no progress.

Pick one or two patterns for a product and use them consistently, so the same kind of work always looks the same:

  • drive for general work, such as building, writing, or running a tool. It is the default.
  • orbit for waiting on something outside the product, such as a connection, a queue, or another service.
  • pulse where space is tight, such as inline in a row or a button.

The other patterns are alternatives to these for interfaces that need a different form.

PatternForm and motion
driveNine rounded squares with a wave across the grid.
dotsThe same wave, with round cells.
orbitA pulse around the grid's edge, with a dim center.
diagonalNine rounded squares with a diagonal brightness sweep.
diamondFive rounded squares: a pulse around four points and through the center.
squareEight rounded squares around an empty center, with a traveling pulse.
pulseThree rounded squares that brighten and gently scale in sequence.

Elapsed time

The time updates once a second and reads as 42s, then 1m 12s. Pass startedAt when the work began before the component mounted, for example after a page reload. Set showElapsed to false to leave it out.

Accessibility

The label is a polite status, so it is announced when the component appears and when the label changes. The elapsed time is hidden from screen readers, because a status that changes every second would be read every second. The mark is decorative.

With reduced motion, the cells stay dim and the label stops shimmering. The elapsed time still updates.

Installation

npx honestui@latest add loading-state

Usage

import { LoadingState } from "@/components/ai/loading-state"

{run.isPending && <LoadingState label="Building the export" startedAt={run.startedAt} />}

Write the label as the work, not as "Loading". "Building the export" tells the person what they are waiting for.

Examples

Patterns

The seven patterns, without the elapsed time.

loading-state-patterns

API reference

LoadingState

Accepts native div props beyond those listed.

PropTypeDefaultDescription
labelstringRequiredWhat is in progress.
pattern"drive" | "dots" | "orbit" | "diagonal" | "diamond" | "square" | "pulse""drive"The mark's form and animation.
showElapsedbooleantrueShows the time since startedAt.
startedAtnumber | DateMount timeWhen the work began.