Spinner
The loading mark for a running action, embedded in the button and standing alone for an inline working moment.
Checking availability for 12 October
Installation
npx shadcn@latest add @flyingsalmon/spinnerUsage
import { Spinner } from '@/components/ui/spinner'
export function SpinnerUsage() {
return <Spinner label="Saving trip" />
}Examples
Sizes
Default and small match the two button sizes. Standalone use takes the default.
Colour
The arc draws in the current text colour and has no track, so the spinner takes the colour of whatever contains it.
Guidelines
When to use
- For an action that is running: a form submits, a setting saves, a check is under way.
- Inline beside the text that says what is being waited for.
When not to use
Do and don’t
- DoPlace a spinner inline, directly before the words that say what is happening.The spinner says something is running and only the words say what, so they belong together.
- DoOn a long wait, pair the spinner with a written count, such as “3 of 7 days written”.A count tells the traveller how far along the work is in their own terms, with no bar beside the heading.
- DoPick a spinner or a skeleton for a given wait, never both.They answer different questions: a spinner says an action is running, a skeleton says a region is loading. Both together say it twice.
- Don’tReplace a control the traveller just pressed with a spinner.The control should show its own busyness and keep its place, as the loading button does.
Accessibility
A standalone spinner has role="status" and reads out its label, which defaults to “Loading”. It never takes focus and has no tab stop.
A component that announces its own busyness, such as the button, embeds the spinner as aria-hidden so the wait is announced once.
API
Spinner
Also takes every <svg> attribute.
| Prop | Type | Default | Description |
|---|---|---|---|
| size | SpinnerSize | SpinnerSize.Default | Default or Small. |
| label | string | "Loading" | What a screen reader reads for the standalone spinner. Name the work, such as “Checking availability”, when the spinner stands alone. When the text beside it already names the work, a short label such as “In progress” is enough. |