Dot Matrix
A dot-matrix loader. A light runs a 5×5 grid of dots in a spiral, from the edge into the center, trailing a fading tail, then around again. For a boot screen or a panel's first load, where a spinner would be too small to carry the wait.
Installation#
Usage#
import { DotMatrix } from "@/components/ui/dot-matrix"
export function Example() {
return <DotMatrix />
}Anatomy#
import { DotMatrix } from "@/components/ui/dot-matrix"
<DotMatrix />Sizes#
xl (the default) is 64px, for a whole screen: a boot, a first load. lg is 36px, for a panel or a block inside a page. Both draw a 5px dot; the size sets the spacing.
Color#
The dots paint currentColor, so the matrix takes the text color around it, or any text-* you give it. The tail is opacity on that one color, so it reads on every ground in every theme.
In a panel#
The matrix is a status named "Loading". When words beside it already say what is loading, make those words the status and pass aria-hidden to the matrix: its role and name are dropped, so the wait is announced once.
Speed#
A lap takes 1.1s. --dot-matrix-duration retimes it, on the matrix or on any container above it: slower for a calm, long wait, never so fast that the tail stops reading as a trail.
Reduced motion#
With prefers-reduced-motion, the light stops and the spiral stays drawn: each dot holds a still opacity that brightens along the path, faint at the edge and full at the center. It still reads as a loader, without moving. This is that state:
API reference#
DotMatrix
A <div> with role="status", holding 25 dots. Every div prop but children is forwarded; className is merged last and color comes from currentColor. The motion is the animate-dot-matrix token.
| Prop | Type | Default | Description |
|---|---|---|---|
| size | "lg" | "xl" | "xl" | lg (36px) sits in a panel or a block; xl (64px) holds a whole screen. |
| label | string | "Loading" | The accessible name while it is announced. Ignored under aria-hidden. |
| aria-hidden | boolean | - | Drops the role and the name, for a host that already says it is busy. |
| Data attribute | Description |
|---|---|
| data-slot | "dot-matrix" on the root, "dot-matrix-dot" on each dot. |
| CSS variable | Description |
|---|---|
| --dot-matrix-duration | Retimes the animate-dot-matrix loop (default 1.1s). |
| --dot-phase | Set on each dot: its place on the spiral, as the delay into the loop. |
| --dot-rest | Set on each dot: its still opacity under reduced motion, brighter along the spiral. |