Spinner

A small purple spinner with a screen reader label.

Loading Rendering northwind.io

Install

$ npx shadcn@latest add @nudgekit/spinner

Or with no config: npx shadcn@latest add https://ui.nudgekit.app/r/spinner.json

Usage

usage.tsx
import { Spinner } from "@/components/ui/spinner"

<Spinner label="Rendering northwind.io" />

Do

  • Give it a label that says what is loading.

Don't

  • Use it for loads that take more than a few seconds; show progress.

Code

What the CLI writes into your project. It is yours to change.

components/ui/spinner.tsx
import * as React from "react";

import { cn } from "@/lib/utils";

function Spinner({ className, label = "Loading", ...props }: React.HTMLAttributes<HTMLSpanElement> & { label?: string }) {
  return (
    <span role="status" data-slot="spinner" className={cn("inline-flex size-4 text-brand", className)} {...props}>
      <svg viewBox="0 0 16 16" fill="none" className="size-full animate-spin motion-reduce:animate-none" aria-hidden>
        <circle cx="8" cy="8" r="6.5" stroke="currentColor" strokeOpacity=".2" strokeWidth="2" />
        <path d="M14.5 8A6.5 6.5 0 0 0 8 1.5" stroke="currentColor" strokeWidth="2" strokeLinecap="round" />
      </svg>
      <span className="sr-only">{label}</span>
    </span>
  );
}

export { Spinner };