Spinner
A turning circle that says something is loading. Same markup and props in every style: switch the style in the header to see it change.
Sizes and colour
On its own, a spinner has role="status" and a label. It takes the text colour, or the accent with primary.
<span class="vin-spinner vin-spinner--sm" role="status" aria-label="Loading"></span>
<span class="vin-spinner" role="status" aria-label="Loading"></span>
<span class="vin-spinner vin-spinner--lg" role="status" aria-label="Loading"></span>
<span class="vin-spinner vin-spinner--lg vin-spinner--primary" role="status" aria-label="Loading"></span>import { Spinner } from "@/components/vin/spinner";
export function SpinnerBasic() {
return (
<>
<Spinner size="sm" />
<Spinner />
<Spinner size="lg" />
<Spinner size="lg" variant="primary" />
</>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Spinner from "@/components/vin/spinner.vue";
</script>
<template>
<Spinner size="sm" />
<Spinner />
<Spinner size="lg" />
<Spinner size="lg" variant="primary" />
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Spinner from "$lib/components/vin/spinner.svelte";
</script>
<Spinner size="sm" />
<Spinner />
<Spinner size="lg" />
<Spinner size="lg" variant="primary" />In a button
Put a small spinner before the label and say what's happening ("Saving…"). Disable the button while it works.
With a message
Loading shows a spinner with text, on the page or inside a card.
<div style="display: grid; gap: 20px; justify-items: center; width: 100%; max-width: 300px">
<div class="vin-loading" role="status">
<span class="vin-spinner" aria-hidden="true"></span>
Loading results…
</div>
<div class="vin-card" style="width: 100%">
<div class="vin-card__body" style="display: grid; place-items: center; min-height: 120px">
<div class="vin-loading" role="status">
<span class="vin-spinner vin-spinner--primary" aria-hidden="true"></span>
Fetching invoices…
</div>
</div>
</div>
</div>import { Card, CardBody } from "@/components/vin/card";
import { Loading } from "@/components/vin/spinner";
export function SpinnerWithText() {
return (
<div style={{ display: "grid", gap: 20, justifyItems: "center", width: "100%", maxWidth: 300 }}>
<Loading>Loading results…</Loading>
<Card style={{ width: "100%" }}>
<CardBody style={{ display: "grid", placeItems: "center", minHeight: 120 }}>
<Loading variant="primary">Fetching invoices…</Loading>
</CardBody>
</Card>
</div>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import { Loading } from "@/components/vin/spinner.vue";
import Card, { CardBody } from "@/components/vin/card.vue";
</script>
<template>
<div style="display: grid; gap: 20px; justify-items: center; width: 100%; max-width: 300px">
<Loading>Loading results…</Loading>
<Card style="width: 100%">
<CardBody style="display: grid; place-items: center; min-height: 120px">
<Loading variant="primary">Fetching invoices…</Loading>
</CardBody>
</Card>
</div>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Card from "$lib/components/vin/card.svelte";
import CardBody from "$lib/components/vin/card-body.svelte";
import Loading from "$lib/components/vin/spinner-loading.svelte";
</script>
<div style="display: grid; gap: 20px; justify-items: center; width: 100%; max-width: 300px">
<Loading>Loading results…</Loading>
<Card style="width: 100%">
<CardBody style="display: grid; place-items: center; min-height: 120px">
<Loading variant="primary">Fetching invoices…</Loading>
</CardBody>
</Card>
</div>Installation
React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:
npx @vinish/ui add spinnerimport { Spinner, Loading } from "@/components/vin/spinner";import Spinner, { Loading } from "@/components/vin/spinner.vue";import Spinner from "$lib/components/vin/spinner.svelte";
import Loading from "$lib/components/vin/spinner-loading.svelte";The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.
Plain HTML: the classes come with the style's stylesheet. It needs no JavaScript.
API
From spec/spinner.json, which every framework version is tested against.
| Prop | Values | Default | In HTML |
|---|---|---|---|
size | smmdlg | md | vin-spinner--{value} |
variantText colour, or the accent colour. | currentprimary | current | vin-spinner--primary |
labelWhat screen readers hear. Leave it out (decorative) when text next to the spinner says it. | string | Loading | role="status" aria-label="…", or aria-hidden="true" |
LoadingA spinner with a message, announced politely. | children | — | <div class="vin-loading" role="status"> |
Parts
| React, Vue, Svelte | HTML classes |
|---|---|
<Spinner><Loading> | .vin-spinner.vin-spinner--sm.vin-spinner--lg.vin-spinner--primary.vin-loading |
Accessibility
- A spinner on its own has role="status" and a label, so screen readers say "Loading".
- Next to text that already says it, the spinner is hidden (aria-hidden) so nothing is said twice.
- With reduced motion the spinner turns slowly; with motion off it stops (still shown as an arc).
Customize
Saved in this browser. Style and accent are in the header.