Spinner
Ring, dots, bars and orbit loaders.
Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/and the colour tokens go into your CSS.$ pnpm dlx asta-ui@latest add spinnerOr install the package
Don’t want the file? Import from
asta-ui/spinnerand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-uiimport { Spinner } from "asta-ui/spinner";Or copy it by hand
Copy this file. Keep the paths, or fix the
@/imports. Then add the tokens fromglobals.css."use client"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export type SpinnerVariant = "ring" | "dots" | "bars" | "orbit"; const KEYFRAMES = ` @keyframes kit-spin { to { transform: rotate(360deg) } } @keyframes kit-dot { 0%, 80%, 100% { transform: scale(.55); opacity: .35 } 40% { transform: scale(1); opacity: 1 } } @keyframes kit-bar { 0%, 100% { transform: scaleY(.35) } 50% { transform: scaleY(1) } } @keyframes kit-indet { 0% { transform: translateX(-100%) scaleX(.8) } 60% { transform: translateX(110%) scaleX(1.2) } 100% { transform: translateX(250%) scaleX(.8) } } @media (prefers-reduced-motion: reduce) { .kit-spinner * { animation-duration: 2.4s !important } } `; /** Loaders in currentColor, sized by font-size (1em) unless you pass a class. */ export function Spinner({ variant = "ring", label = "Loading", className }: { variant?: SpinnerVariant; label?: string; className?: string }) { return ( <span role="status" aria-label={label} className={cx("kit-spinner relative inline-flex h-[1em] w-[1em] shrink-0 items-center justify-center", className)}> <style href="asta-spinner" precedence="asta">{KEYFRAMES}</style> {variant === "ring" && ( <svg viewBox="0 0 24 24" className="h-full w-full animate-[kit-spin_.8s_linear_infinite]" fill="none" aria-hidden> <circle cx="12" cy="12" r="9.5" stroke="currentColor" strokeOpacity=".18" strokeWidth="2.5" /> <path d="M21.5 12A9.5 9.5 0 0 0 12 2.5" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" /> </svg> )} {variant === "dots" && ( <span className="flex h-full w-full items-center justify-between" aria-hidden> {[0, 1, 2].map((i) => ( <span key={i} className="h-[26%] w-[26%] rounded-full bg-current" style={{ animation: `kit-dot 1.1s ${i * 0.16}s cubic-bezier(.16,1,.3,1) infinite` }} /> ))} </span> )} {variant === "bars" && ( <span className="flex h-[80%] w-full items-center justify-between" aria-hidden> {[0, 1, 2, 3].map((i) => ( <span key={i} className="h-full w-[16%] rounded-full bg-current" style={{ animation: `kit-bar .9s ${i * 0.12}s ease-in-out infinite` }} /> ))} </span> )} {variant === "orbit" && ( <span className="relative h-full w-full" aria-hidden> <span className="absolute inset-[30%] rounded-full bg-current opacity-25" /> <span className="absolute inset-0 animate-[kit-spin_1.2s_cubic-bezier(.6,.1,.4,.9)_infinite]"> <span className="absolute left-1/2 top-0 h-[24%] w-[24%] -translate-x-1/2 rounded-full bg-current" /> </span> <span className="absolute inset-0 animate-[kit-spin_1.8s_linear_infinite_reverse]"> <span className="absolute bottom-[6%] left-1/2 h-[16%] w-[16%] -translate-x-1/2 rounded-full bg-current opacity-60" /> </span> </span> )} </span> ); } /** * A progress bar. Pass `value` (0–100) for determinate progress; leave it out for an indeterminate * sweep. */ export function Progress({ value, label, showValue, className }: { value?: number; label?: string; showValue?: boolean; className?: string }) { const v = value === undefined ? undefined : Math.max(0, Math.min(100, value)); return ( <div className={cx("w-full", className)}> {(label || showValue) && ( <div className="mb-2 flex items-center justify-between text-[13px]"> <span className="text-ink-2">{label}</span> {showValue && v !== undefined && <span className="tabular-nums text-mute">{Math.round(v)}%</span>} </div> )} <div role="progressbar" aria-label={label ?? "Progress"} aria-valuemin={0} aria-valuemax={100} aria-valuenow={v} className="kit-spinner relative h-1.5 w-full overflow-hidden rounded-full bg-[color-mix(in_srgb,var(--color-ink)_9%,transparent)]" > <style href="asta-spinner-2" precedence="asta">{KEYFRAMES}</style> {v === undefined ? ( <span className="absolute inset-y-0 left-0 w-[40%] rounded-full bg-brand" style={{ animation: "kit-indet 1.3s cubic-bezier(.65,0,.35,1) infinite" }} /> ) : ( // perf-ok: a thin progress bar, width updates only when the value changes. <span className="absolute inset-y-0 left-0 rounded-full bg-brand transition-[width] duration-700 ease-[cubic-bezier(.16,1,.3,1)]" style={{ width: `${v}%` }} /> )} </div> </div> ); } export default Spinner;Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI Spinner component to my project. Ring, dots, bars and orbit loaders. It includes: ring, dots, bars, orbit, Progress. Install it: ```sh pnpm dlx asta-ui@latest add spinner --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/spinner.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { Progress, Spinner, type SpinnerVariant } from "@/components/astabyte/spinner"; ``` Usage example and props: https://ui.astabyte.com/spinner Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Or use plain HTML + CSS
Not on React? Use it from Django, Rails, Laravel, Go
html/template, htmx or a static page. Loadasta.cssandasta.jsonce (thehead.htmltab), then paste the markup. Theui.astabyte.com/cdnlink is temporary: pin a version from jsDelivr for production. More in HTML + CSS.<div style="display:flex;align-items:center;gap:16px;font-size:24px"> <span class="asta-spinner" role="status" aria-label="Loading"><svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><circle cx="12" cy="12" r="9.5" stroke="currentColor" stroke-opacity=".18" stroke-width="2.5"/><path d="M21.5 12A9.5 9.5 0 0 0 12 2.5" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg></span> <span class="asta-spinner asta-spinner-dots" role="status" aria-label="Loading"><span></span><span></span><span></span></span> <span class="asta-spinner asta-spinner-bars" role="status" aria-label="Loading"><span></span><span></span><span></span><span></span></span> <span class="asta-spinner asta-spinner-orbit" role="status" aria-label="Loading"><span></span><span></span><span></span></span> </div>
Usage
The demo above, as code.
"use client";
import { useEffect, useState } from "react";
import { Progress, Spinner, type SpinnerVariant } from "@/components/astabyte/spinner";
const VARIANTS: SpinnerVariant[] = ["ring", "dots", "bars", "orbit"];
export default function SpinnerDemo() {
const [upload, setUpload] = useState(12);
// Fake an upload that restarts when it finishes.
useEffect(() => {
const id = setInterval(() => setUpload((v) => (v >= 100 ? 0 : Math.min(100, v + 4 + Math.random() * 10))), 600);
return () => clearInterval(id);
}, []);
return (
<div className="flex min-h-[420px] w-full items-center justify-center p-6 sm:p-10">
<div className="flex w-full max-w-md flex-col gap-10">
<div className="grid grid-cols-2 gap-3 sm:grid-cols-4">
{VARIANTS.map((v) => (
<div key={v} className="flex flex-col items-center gap-4 rounded-xl bg-paper px-4 py-6 shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_10%,transparent)]">
<Spinner variant={v} className="text-[28px] text-ink" />
<span className="font-mono text-[11px] uppercase tracking-wider text-mute">{v}</span>
</div>
))}
</div>
<div className="flex flex-wrap items-center gap-x-6 gap-y-3 text-[13px] text-ink-2">
<span className="flex items-center gap-2">
<Spinner className="text-brand" /> Syncing
</span>
<span className="flex items-center gap-2">
<Spinner variant="dots" className="w-[1.4em] text-mute" /> Typing
</span>
<span className="flex items-center gap-2">
<Spinner variant="bars" className="text-brand" /> Listening
</span>
</div>
<div className="flex flex-col gap-5">
<Progress value={upload} label="Uploading design.fig" showValue />
<Progress label="Preparing export" />
</div>
</div>
</div>
);
}