59 — Feedback
Spinner
Something is loading: a turning circle, alone or with what it waits for in words.
Loading history
Installation
pnpm dlx @human-kit/design add spinnernpx @human-kit/design add spinneryarn dlx @human-kit/design add spinnerbunx @human-kit/design add spinnerThe command copies the files to src/lib/components/ui/spinner. It also
installs the packages that the files import.
Usage
<script lang="ts">
import * as Spinner from '$lib/components/ui/spinner';
</script>
<Spinner.Root label="Loading the patient's history" /> Guidelines
- Use a spinner for an area that waits on its data and has nothing to show until then.
- Say what is loading in
labelwhen the wait is long enough to read it, or the area is large. - Use
sminside a line of small text,defaultin a panel, andlgalone in the middle of an empty area, where the label goes under the circle. - For an action the user started, give
pendingto its button instead: the spinner then sits where the user is looking. - For a wait whose length you know, use a progress bar.
Accessibility
- It is a
role="status", so a screen reader reads its words once when it appears, without moving the focus. - With no
label, it still says "Loading" to a screen reader. Change it withsrLabel, as "Loading the agenda". - The circle is hidden from assistive technology, and it stops turning when the user asks the system for reduced motion.
API reference
| Prop | Type | Default |
|---|---|---|
size | 'sm' | 'default' | 'lg' The circle and the text beside it. The large one puts the label under. | 'default' |
label | string What is loading, shown beside the circle. | — |
srLabel | string Read aloud when there is no | 'Loading' |
Plus every attribute of a <span>.