Skip to content
flyingsalmon

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/spinner

Usage

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.

In a button

Press the button. A button’s loading prop places the spinner in its leading slot and keeps the label, so you rarely render a spinner for a button yourself.

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

  • Use Skeleton for a region that is loading, such as a list, a card, or a page. The placeholder holds the shape of what is coming.
  • Use Progress for a long job with a known end, where the traveller wants to see how far along it is.

Do and don’t

  • Do
    Place 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.
  • Do
    On 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.
  • Do
    Pick 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’t
    Replace 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.

PropTypeDefaultDescription
sizeSpinnerSizeSpinnerSize.DefaultDefault or Small.
labelstring"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.

  • Button

    Shows this spinner in its leading slot while loading.
  • Skeleton

    The placeholder for a region that is loading.
  • Progress

    A bar for work with a known end.
  • Motion

    The motion language and the continuous indicators.