← Components

Communication · Material 3: Loading indicator

Loading indicator

A short, unknown wait. Buoyant dots or a ring; when done they gather and pop into a check.

Examples and variants

Sizes and done

Press Finish.

LoadingLoadingLoading
Example
function LoadingIndicator() {
  const [done, setDone] = useState(false)
  return (
    <div className="flex items-center gap-6">
      <Spinner size="sm" done={done} />
      <Spinner size="md" done={done} />
      <Spinner size="lg" variant="ring" done={done} />
      <Button size="sm" variant="secondary" onClick={() => setDone((value) => !value)}>
        {done ? "Load again" : "Finish"}
      </Button>
    </div>
  )
}

Loader family

dots, ring, wave, orbit, morph, typing.

dotsringwaveorbitmorphtyping
Example
function LoaderVariants() {
  return (
    <div className="flex items-center gap-6">
      {(["dots", "ring", "wave", "orbit", "morph", "typing"] as const).map((variant) => (
        <Spinner key={variant} size="lg" variant={variant} label={variant} />
      ))}
    </div>
  )
}

Spec drawing

Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.

Install

With the CLI

The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.

Terminal
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/spinner.json

By hand

No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.

  1. Install the packages it uses.

    Terminal
    npm install cn lucide-react
  2. Copy this file to the same paths in your project. Imports use the @/ alias for your project root.

    • components/ui/spinner.tsxspinner
      components/ui/spinner.tsx
      import * as React from "react"
      import { CheckIcon } from "lucide-react"
      import { cn } from "cn"
      
      /*
        Spinner: a short, unknown wait. Three buoyant dots (or a ring). When the
        work succeeds, set done: the dots gather into the centre and pop into a
        check. Sizes follow the icon tokens.
      */
      const sizes = { sm: "h-icon-sm", md: "h-icon-md", lg: "h-icon-lg" }
      
      function Spinner({
        className,
        size = "md",
        variant = "dots",
        done = false,
        label = "Loading",
        ...props
      }: React.ComponentProps<"span"> & {
        size?: keyof typeof sizes
        /** dots (default), ring, wave, orbit, morph, typing. All resolve into the same check. */
        variant?: "dots" | "ring" | "wave" | "orbit" | "morph" | "typing"
        done?: boolean
        label?: string
      }) {
        return (
          <span
            role="status"
            data-slot="spinner"
            data-done={done || undefined}
            className={cn("spinner relative inline-flex items-center justify-center", sizes[size], className)}
            {...props}
          >
            <span className="sr-only">{done ? "Done" : label}</span>
            {variant === "dots" || variant === "typing" ? (
              <span aria-hidden data-variant={variant} className="spinner-dots inline-flex h-full items-center gap-[0.2em]">
                {[0, 1, 2].map((dot) => (
                  <span key={dot} className="spinner-dot aspect-square h-[28%] rounded-full bg-current" style={{ "--dot": dot } as React.CSSProperties} />
                ))}
              </span>
            ) : variant === "wave" ? (
              <span aria-hidden className="spinner-dots inline-flex h-full items-center gap-[0.15em]">
                {[0, 1, 2, 3].map((bar) => (
                  <span key={bar} className="spinner-bar h-full w-[0.18em] rounded-full bg-current" style={{ "--dot": bar } as React.CSSProperties} />
                ))}
              </span>
            ) : variant === "orbit" ? (
              <span aria-hidden className="spinner-dots spinner-orbit relative aspect-square h-full">
                <span className="absolute top-0 left-1/2 aspect-square h-[30%] -translate-x-1/2 rounded-full bg-current" />
              </span>
            ) : variant === "morph" ? (
              <span aria-hidden className="spinner-dots spinner-morph aspect-square h-[70%] bg-current" />
            ) : (
              <span aria-hidden className="spinner-ring aspect-square h-full rounded-full" />
            )}
            <CheckIcon aria-hidden className="spinner-check absolute aspect-square h-full w-auto" strokeWidth={2.5} />
          </span>
        )
      }
      
      export { Spinner }
      

Imports

What the examples on this page import:

Imports
import { Button } from "@/components/ui/button"
import { Spinner } from "@/components/ui/spinner"

Anatomy

  1. 1Dots or ring · Sized by the icon tokens; --loading-dot-size.
  2. 2Check · Pops in when done.

Props

PropTypeDefaultDescription
variant"dots" | "ring" | "wave" | "orbit" | "morph" | "typing""dots"Shape. All resolve into the same check.
size"sm" | "md" | "lg""md"Icon-token size.
doneboolean—Gather and pop into a check.
labelstring"Loading"Screen reader text.

Tokens

Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.

TokenPoints toLightDark
--loading-dot-size28%28%same

Motion

TriggerWhat happensTokens
Loop / doneDots bob in sequence; done gathers them into a check.--duration-pulse, --spring-bouncy

Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.

Accessibility

  • role=status with a hidden label.

Usage

Do

  • Use for waits under a few seconds.

Don’t

  • Don't use for long tasks (use Progress).

Code

components/ui/spinner.tsx
import * as React from "react"
import { CheckIcon } from "lucide-react"
import { cn } from "cn"

/*
  Spinner: a short, unknown wait. Three buoyant dots (or a ring). When the
  work succeeds, set done: the dots gather into the centre and pop into a
  check. Sizes follow the icon tokens.
*/
const sizes = { sm: "h-icon-sm", md: "h-icon-md", lg: "h-icon-lg" }

function Spinner({
  className,
  size = "md",
  variant = "dots",
  done = false,
  label = "Loading",
  ...props
}: React.ComponentProps<"span"> & {
  size?: keyof typeof sizes
  /** dots (default), ring, wave, orbit, morph, typing. All resolve into the same check. */
  variant?: "dots" | "ring" | "wave" | "orbit" | "morph" | "typing"
  done?: boolean
  label?: string
}) {
  return (
    <span
      role="status"
      data-slot="spinner"
      data-done={done || undefined}
      className={cn("spinner relative inline-flex items-center justify-center", sizes[size], className)}
      {...props}
    >
      <span className="sr-only">{done ? "Done" : label}</span>
      {variant === "dots" || variant === "typing" ? (
        <span aria-hidden data-variant={variant} className="spinner-dots inline-flex h-full items-center gap-[0.2em]">
          {[0, 1, 2].map((dot) => (
            <span key={dot} className="spinner-dot aspect-square h-[28%] rounded-full bg-current" style={{ "--dot": dot } as React.CSSProperties} />
          ))}
        </span>
      ) : variant === "wave" ? (
        <span aria-hidden className="spinner-dots inline-flex h-full items-center gap-[0.15em]">
          {[0, 1, 2, 3].map((bar) => (
            <span key={bar} className="spinner-bar h-full w-[0.18em] rounded-full bg-current" style={{ "--dot": bar } as React.CSSProperties} />
          ))}
        </span>
      ) : variant === "orbit" ? (
        <span aria-hidden className="spinner-dots spinner-orbit relative aspect-square h-full">
          <span className="absolute top-0 left-1/2 aspect-square h-[30%] -translate-x-1/2 rounded-full bg-current" />
        </span>
      ) : variant === "morph" ? (
        <span aria-hidden className="spinner-dots spinner-morph aspect-square h-[70%] bg-current" />
      ) : (
        <span aria-hidden className="spinner-ring aspect-square h-full rounded-full" />
      )}
      <CheckIcon aria-hidden className="spinner-check absolute aspect-square h-full w-auto" strokeWidth={2.5} />
    </span>
  )
}

export { Spinner }