Moon
An orb for an assistant's states: a small moon in 1-bit dots; an eclipse slides across it while it thinks.
Installation
Terminal
npx shadcn@latest add https://fabrickit.org/r/moon.jsonTerminal
pnpm dlx shadcn@latest add https://fabrickit.org/r/moon.jsonTerminal
yarn shadcn@latest add https://fabrickit.org/r/moon.jsonTerminal
bunx --bun shadcn@latest add https://fabrickit.org/r/moon.jsonThis 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.
Step 1: Add the theme (once)
Every colour, radius and curve the components use, as --fabric-* variables. Save it as fabric.css next to your global CSS and import it there. If you've added another Fabric Kit component before, skip this.globals.css@import "./fabric.css";fabric.css/* * fabric.css — Fabric Kit's theme: every colour, radius, ring and curve the * components use, as --fabric-* variables (prefixed, so they never clash * with your own shadcn theme). Installed by `shadcn add @fabrickit/theme` * (it lands in your global CSS) — or import this file once, globally. * Dark by default. For light, put data-theme="light" on <html> (or on any * element: the tokens follow it down the tree; data-theme="dark" turns back). */ :root, [data-theme="dark"] { --fabric-page: #111111; --fabric-surface: #191919; /* triggers, recessed tiles */ --fabric-panel: #202020; /* open panels */ --fabric-raised: #2a2a2a; /* hover, range band */ --fabric-raised-hi: #343434; /* hover inside a band */ --fabric-preview: #252525; /* soft preview fills */ --fabric-text: #e0e0e0;Step 2: Copy the shared engines
Plain JavaScript that does the motion, shared between components. Create each file at the same path in your project; if a file is already there from another component, keep it.lib/fabricui/mount.js/* * mount.js — runs a Fabric Kit engine for a React component and cleans up * after it. The engines are plain JavaScript that wire themselves to the page * (listeners on the document, resize observers, a few elements of their own); * mount() records everything an engine attaches and changes while it's being * set up, and dispose() takes it all back, so a component can come and go (or * be set up twice in a row, as React's Strict Mode does) without leaving * anything behind. * * const m = mount(() => new Engine(root, options)); * m.instance; // the engine * m.dispose(); // on unmount: listeners and observers off, the DOM as it was, then instance.destroy() * // (and destroy() on anything it owns that registered itself, like each ClothDrop) */ export function mount(create) { const ac = new AbortController();Step 3: Copy the Moon files
The component itself. Create each one at the same path in your project. It's your code from here on.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 againStep 4: Check the import paths
The files import each other through the @/ alias (the shadcn default, there in a new Next.js app). If your project doesn't have it, add it to tsconfig.json, or change the imports to relative paths.tsconfig.json{ "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["./*"] } } }Step 5: Use it
Import it from @/components/fabricui/moon. The Usage example below shows it in a page.
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 againUsage
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
| Prop | Type | Default |
|---|---|---|
| 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. | number | 64 |
| speed Animation speed. | number | 1 |
| paused Hold it still. | boolean | false |
| 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 | — |