Spinner
A spinning ring that shows something is happening.
import { Spinner, LoadingIndicator } from '@halo-ds/react';
When to use it
Use a spinner for short waits, like saving, sending or loading a small part of a page. Spinner is the ring on its own, in Brand, Neutral or On brand colours; Loading indicator adds a "Loading…" label next to it or under it.
Do
- Wait about 300 milliseconds before showing it, so quick actions don't flash.
- Keep a Button the same width while it shows a spinner.
- Change the label to say what is happening, like "Saving…".
- Show an error with a way to try again if it takes too long.
Don't
- Cover the whole page for a small action.
- Show several spinners at once; use one, or Skeletons.
- Use Brand on a purple surface; use On brand.
- Leave people waiting without a message for more than a few seconds.
Spinner or Skeleton?
Both show loading. Pick by whether you know the layout.
- Spinner: A short action, like saving, sending or signing in. Inside a Button, or a small part of a page. When you don't know the shape of what is coming.
- Skeleton: Loading a page, a list, a table or a card. You know the layout, so you can show it straight away. Waits longer than about a second.
Props
Spinner props
| Prop | Type | What it does | |
|---|---|---|---|
size | `SpinnerSize \ | undefined` | 12, 16, 24, 32 or 48px. Figma: Size. |
color | `SpinnerColor \ | undefined` | brand by default; onBrand on purple surfaces like a primary Button. Figma: Colour. |
label | `string \ | undefined` | Read by screen readers. Defaults to "Loading". Pass an empty string inside labelled parents. |
classNames | `Partial<Record<SpinnerPart, string>> \ | undefined` | Extra class names for the parts inside the component, by part name, like { header: 'my-header' }. |
styles | `Partial<Record<SpinnerPart, CSSProperties>> \ | undefined` | Inline styles for the parts inside the component, by part name, like { footer: { gap: 4 } }. |
It also takes the usual HTML attributes for its element.
LoadingIndicator props
| Prop | Type | What it does | ||
|---|---|---|---|---|
layout | `"stacked" \ | "inline" \ | undefined` | Spinner beside the label, or above it. Figma: Layout. |
children | ReactNode | What is happening, like "Uploading files…". Figma: Label. |
It also takes the usual HTML attributes for its element.
Examples
Overview
import { LoadingIndicator, Spinner } from '@halo-ds/react';
export default function Example() {
return (
<div style={{ display: 'grid', gap: 24, justifyItems: 'center' }}>
<Spinner />
<LoadingIndicator>Loading your projects</LoadingIndicator>
</div>
);
}
Sizes
Five sizes, from inside a small button to a whole page.
import { Spinner } from '@halo-ds/react';
export default function Demo() {
return (
<div className="demo-row">
{(['xs', 'sm', 'md', 'lg', 'xl'] as const).map((s) => <Spinner key={s} size={s} />)}
</div>
);
}
In buttons
onBrand on a primary button, neutral for quieter places.
import { Button, Spinner } from '@halo-ds/react';
export default function Demo() {
return (
<div className="demo-row">
<Button iconLeft={<Spinner size="sm" color="onBrand" label="" />}>Saving</Button>
<Button variant="secondary" iconLeft={<Spinner size="sm" color="neutral" label="" />}>Loading</Button>
</div>
);
}
More: https://halodesignsystem.dev/components/spinner