Dot matrix loader

A five by five grid of dots that lights up in patterns while an AI thinks: rings, a spiral, a scan, a wave, writing and sparks. CSS only.

Options

Size
Colour

Code

import "./dot-matrix.css";

/* Where a spiral from the top left corner reaches each dot of a 5 by 5 grid. */
const spiral = [0, 1, 2, 3, 4, 15, 16, 17, 18, 5, 14, 23, 24, 19, 6, 13, 22, 21, 20, 7, 12, 11, 10, 9, 8];

/* kind is "think", "spiral", "scan", "wave", "write" or "spark". Its size follows the
   font size around it, and its colour can be set with the --dh-matrix-colour variable. */
export function DotMatrix({ kind = "think", label = "Loading" }) {
  return (
    <span className="dh-matrix" data-kind={kind} role="status" aria-label={label}>
      {spiral.map((place, i) => (
        <i key={i} style={{ "--x": i % 5, "--y": Math.floor(i / 5), "--s": place }} />
      ))}
    </span>
  );
}