Spinner
A small busy indicator of slanted pixels.
Demo
Usage
import { Button, Row, Spinner, Text } from '@tuttn/slant'
// Decorative by default: put it beside the words that say what is happening.
<Row role="status"><Spinner size="sm" /><Text as="span">Syncing 12 files</Text></Row>
// On its own, name it: it becomes an image with that label.
<Spinner size="lg" label="Loading the preview" />
// It paints in the surrounding text colour; tone picks a semantic one.
<Spinner tone="accent" />
// A loading Button draws a small one before its label.
<Button variant="primary" loading={saving} onClick={save}>Save</Button>Props
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'sm' | 'md' | 'lg' | 'md' | About 12, 16 or 22px square: `sm` fits a small button or a line of text. |
tone | Tone | — | Semantic colour. Omitted, the spinner paints in the surrounding text colour (currentColor), so it suits any button, badge or line of text. |
label | string | — | Names the spinner for screen readers (`role="img"` with this label). Omitted, it is decorative and aria-hidden: name the busy region instead. |
…rest | HTMLAttributes<HTMLSpanElement> | — | className, style and other attributes go on the root span, which also takes the ref. |
Accessibility
Without a label the spinner is aria-hidden, which is right beside text that already says what is happening ("Syncing 12 files"), or inside a loading Button, whose label stays its name. With a label it is role="img" with that name. Either way it announces nothing itself: when a wait starts or ends, set aria-busy on the region that is loading, or put the words in a role="status" element.
Keyboard
None: the spinner is never focusable. A loading Button keeps its own focus while it spins.
Motion and colour
Four slanted pixels light in turn, about once a second, each fading as the light moves on. Under prefers-reduced-motion it rests on one frame of that trail, the lit pixel full and the others fading, so it still reads as busy. It paints in currentColor unless given a tone, so it matches any button or line of text it sits in; in forced-colours mode it keeps the system text colour.
Direction
The 2×2 grid is logical: under dir="rtl" the light starts at the inline start, on the right, and turns the other way.
Button's loading state used to show the typing dots; it now draws <Spinner size="sm" />. TypingDots remain for a chat partner who is typing.