UI.MD

Spinner

The loading mark Button draws for loading, as a standalone part: sizes on the icon ramp and an optional label for screen readers.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/spinner.json

Usage

import { Spinner } from "@/components/ui/spinner"

Examples

Default

Pass label when the spinner stands alone, so a screen reader hears what is loading. It keeps spinning under reduced motion, because a frozen spinner reads as a hang.

Loading

Sizes

12, 14, 16, 20 and 24px, the same steps as Button's icon ramp. It takes the text colour of its parent.

In a loading pane

For a photo slot, a preview or a menu item that is working but is not a button. A Button with loading already draws this, so do not add a second.

Reading the image

API Reference

PropTypeDefaultDescription
size"xs" | "sm" | "default" | "lg" | "xl""default"12 / 14 / 16 / 20 / 24px. The wrapper owns the size, so a parent that sizes its icons cannot shrink it.
labelstring-What is loading, for screen readers. Adds role="status". Leave it off inside something that already says it is busy; the spinner is then hidden from them.
...propsReact.ComponentProps<"span">-Every <span> prop. Set the colour with a text colour class on the spinner or its parent.
size"xs" | "sm" | "default" | "lg" | "xl" = "default"12 / 14 / 16 / 20 / 24px. The wrapper owns the size, so a parent that sizes its icons cannot shrink it.
labelstringWhat is loading, for screen readers. Adds role="status". Leave it off inside something that already says it is busy; the spinner is then hidden from them.
...propsReact.ComponentProps<"span">Every <span> prop. Set the colour with a text colour class on the spinner or its parent.