Spinner

Shows that something is loading when you cannot tell how long it will take. For a known amount of progress, use Progress instead. The root sets role="status" and is named "Loading" for screen readers.

+page.svelte
<script lang="ts">
	import { Spinner } from "#lib/components/ui/spinner/index.js";
</script>

<Spinner />

Installation

pnx remote0 add https://plainsv.com/r/spinner.json

Label

Set aria-label to describe what is loading, such as aria-label="Loading results". The spinning circle itself is hidden from screen readers.

+page.svelte
<Spinner aria-label="Loading results" />

Button

Place a spinner before the label of a disabled button while an action runs. The default variant follows the surrounding text color, so it matches every button variant. Use size="sm" in small buttons and size="xs" in extra small ones.

+page.svelte
<script lang="ts">
	import { Spinner } from "#lib/components/ui/spinner/index.js";
	import { Button } from "#lib/components/ui/button/index.js";
</script>

<Button disabled><Spinner />Saving</Button>
<Button size="sm" variant="secondary" disabled><Spinner size="sm" />Processing</Button>

Variants

Set variant to default, primary, muted, or destructive. The default variant follows the surrounding text color, and muted uses the muted foreground color for quieter loading states. To use another color, set color on the spinner or its parent.

+page.svelte
<Spinner variant="primary" />
<Spinner variant="muted" />
<Spinner variant="destructive" />

Sizes

Set size to xs, sm, md, lg, xl, 2xl, or 3xl. The default is md. Use xl and larger for page and panel loaders.

+page.svelte
<Spinner size="lg" />
<Spinner size="3xl" />

API

The Spinner props extend the native span attributes, and extra attributes pass through to the root. When the user prefers reduced motion, the spinner turns more slowly instead of stopping.

index.ts
interface Props extends CompProps<"span"> {
	/** Color of the spinner; `default` follows the surrounding text color and `muted` uses the muted foreground */
	variant?: "default" | "primary" | "muted" | "destructive";
	/** Spinner size on the shared scale plus `xl`, `2xl`, and `3xl` for page and panel loaders; defaults to `md` */
	size?: UiSize | "xl" | "2xl" | "3xl";
}