Set the dot color, run a pattern through a palette of up to 8 colors, and tune the glow and the dark dots under the lit ones.
Engine · 3 min read
By default the dots take the text color of their parent, like an icon. So a loader fits light and dark pages with no work.
One color
color takes any CSS color. A theme token keeps the loader in step with your theme.
<DotMatrix pattern="pulse" color="var(--color-info)" />
<DotMatrix pattern="pulse" className="text-amber-500" />A palette
look.colors takes 2 to 8 colors. The first one is the dot color, unless you pass color. A pattern with a tint channel picks a color for each dot from the list: 0 is the first color, 1 the last. A dot between two places blends the two neighbor colors.
Of the built-in patterns, only spectrum has a tint channel. On other patterns the palette shows only its first color.
<DotMatrix pattern="spectrum" look={{ colors: ["#2BD4E0", "#9D7BFF", "#FF5C7A"] }} />Your own scene can tint too. This one sweeps the palette from left to right:
Glow and the dark dots
A lit dot has a bright core and a soft halo. Under the pattern, the dots that are off still show, dim, like a real LED panel.
| Look key | Default | What it does |
|---|---|---|
glow | 1 | The halo, from 0 to 1. Light pages show a third of it. |
floor | 1 | The dots that are off, from 0 (hidden) to 1. Use 0 for an effect over content. |
The core of a lit dot leans toward black on light pages and toward white on dark pages. So a dot reads as lit in both themes, with no color of its own for each.
Theme tokens
Every color you pass in code can be a CSS variable. So a loader follows your theme in light and dark mode.
<DotMatrix pattern="radar" color="var(--chart-2)" />
<DotMatrix pattern="spectrum" look={{ colors: ["var(--chart-1)", "var(--chart-3)", "var(--chart-5)"] }} />- Every shadcn theme defines
--chart-1to--chart-5. The example items use them. - A Tailwind v4 theme also has
--color-*names, such asvar(--color-primary). - The variable must be set on the loader or a parent of it.
- A
var()inside another color function, such ascolor-mix(), works too, but it is slower to read.
Theme switches
The DOM and SVG renderers draw with CSS, so they follow a theme switch at once. The canvas and WebGL renderers read the colors again when one of these changes:
- the
class,style,data-themeordata-color-schemeattribute of<html> - the system color scheme (
prefers-color-scheme)
If your theme switch changes something else, give the loader a new key after the switch.
Colors in a preset
A preset is a file that other people can share. So its colors take only plain colors: hex, a color name, or rgb(), hsl(), oklch(), oklab(), lab(), lch() or hwb() with numbers. A var() fails the check. Pass theme tokens in code, with the color prop.