Spinner
An indicator that shows a loading state.
Installation
Install the following dependencies:
Set up the token layer and the StyleX compiler, if you have not already. See Installation.
Copy and paste the following code into your project.
Update the import paths to match your project setup.
Usage
The spinner keeps turning under prefers-reduced-motion: reduce, because a
stopped spinner looks like a stalled one.
Variants
default turns a glyph. ring is a ring with one bright head and a tail that
fades behind it. dots lights three dots one after another. All three take the
same size and colour, and all keep moving under reduced motion.
Size
A spinner takes its size from --carbon-icon-size, the property a control sets
for its icons, so a spinner inside a small button or a badge shrinks with the
icons beside it. Give a standalone spinner a width and height through
xstyle.
Custom icon
Spread spinnerStyles.base onto any icon to give it the spinner's size and
rotation. Add role="status" and aria-label yourself; only Spinner sets
them for you.
Button
Place the spinner before the label with iconPosition="start", or after it
with iconPosition="end".
Badge
Place the spinner before the label with iconPosition="start", or after it
with iconPosition="end".
Input group
Put the spinner in an InputGroupAddon and position it with the addon's
align.
Spinner renders role="status" with aria-label="Loading", so a screen
reader announces it on its own. Pass aria-hidden when the text beside it
already says the same thing, such as a button labelled "Loading...".
API reference
Pass render to replace a part's element or compose it with another component.
Spinner renders an <svg> for default and a <span> for ring and
dots, and accepts every attribute of its element. Anything you pass overrides
its own defaults, including role and aria-label.
Spinner
| Prop | Type | Default |
|---|---|---|
variant | "default" | "ring" | "dots" | "default" |
xstyle | StyleXStyles | — |
className | string | — |
role | string | "status" |
aria-label | string | "Loading" |
spinnerStyles
The style map behind the component. Spread it onto any element.
| Key | What it is |
|---|---|
base | The inherited icon size and the rotation |
variants | The ring's mask and the dots' row, by name |
dot | One dot and its blink |
dotDelays | The second and third dots' offsets, in order |
Data attributes
| Attribute | On | Effect |
|---|---|---|
data-slot="spinner" | the spinner | Targets the glyph from a parent |
data-variant | the spinner | Mirrors the variant prop |