Moon

An orb for an assistant's states: a small moon in 1-bit dots; an eclipse slides across it while it thinks.

Searching the release notes…

Read 12 pages

Installation

Terminal
npx shadcn@latest add https://fabrickit.org/r/moon.json

This copies the component into components/fabricui and its engine into lib/fabricui. It's your code from then on. First time? Add the theme once: see Installation.

Code

components/fabricui/moon.tsx
"use client";

import * as React from "react";
import { mount } from "@/lib/fabricui/mount";
import { Moon as MoonEngine } from "@/lib/fabricui/moon-engine";
import "./moon.css";

const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;

export type MoonState = "idle" | "listening" | "thinking" | "searching" | "speaking" | "done" | "error";

const SAYS: Record<MoonState, string> = {
  idle: "Ready", listening: "Listening", thinking: "Thinking", searching: "Searching",
  speaking: "Speaking", done: "Done", error: "Something went wrong",
};
components/fabricui/moon.css
/*
 * moon.css — Moon (moon-engine.js). The moon is drawn on its canvas in the
 * element's text colour; set `color` on it (or a parent) to tint it.
 */
.moon:where(.fui-moon, .fui-moon *) {
  display: inline-block;
  flex: none;
  vertical-align: middle;
  color: var(--fabric-text);
}
.moon > canvas:where(.fui-moon, .fui-moon *) { display: block; }

/* light: a soft grey ink rather than black */
[data-theme="light"] .moon:where(.fui-moon, .fui-moon *) { color: #8c8c8c; }
lib/fabricui/moon-engine.js
/*
 * moon-engine.js — Moon (moon.css). An orb for showing what an assistant is
 * doing: a small moon in 1-bit dots, and a shadow that passes across it like
 * an eclipse. Every dot is the same small round dot, either on or off: the light
 * is only how many are on, so the shadow's edge and the rim fall into a dither
 * stipple (an 8×8 ordered pattern laid over the surface). The dots sit on
 * the sphere and turn with it (so it has depth); the far side is hidden, so
 * it reads as a solid ball. Drawn on a 2D canvas (no WebGL), so a page can
 * hold many.
 *
 *   const m = new Moon(rootEl, { state: "thinking", size: 64 });
 *   m.set({ state: "done" });
 *
 *   idle       mostly in shadow: a bright crescent, turning slowly
 *   listening  the lit dots breathe with the voice (`level`, 0–1; made up if not given)
 *   thinking   an eclipse: the shadow slides across the moon, clears, and comes round again

Usage

Usage
"use client";

import { Moon } from "@/components/fabricui/moon";

export function Assistant({ busy, failed }: { busy: boolean; failed: boolean }) {
  return <Moon state={failed ? "error" : busy ? "thinking" : "done"} size={64} />;
}

// beside a line of text
export function Status() {
  return <p><Moon state="searching" size={20} /> Searching the docs…</p>;
}

Props

PropTypeDefault
state

What the assistant is doing (error turns it red). Changes blend; they never cut.

"idle" | "listening" | "thinking" | "searching" | "speaking" | "done" | "error""thinking"
size

px. Tuned for 20 (beside text) and 64 (an avatar); other sizes use the nearer tuning.

number64
speed

Animation speed.

number1
paused

Hold it still.

booleanfalse
level

Listening: the voice level, 0–1, from your audio. Left out, it makes one up.

number—
label

What screen readers hear. Default: the state in words ("Thinking").

string—