Drape

An orb for an assistant's states: a cloth of 1-bit dots wrapped over an unseen ball; it lifts and settles while it thinks.

Searching the release notes…

Read 12 pages

Installation

Terminal
npx shadcn@latest add https://fabrickit.org/r/drape.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/drape.tsx
"use client";

import * as React from "react";
import { mount } from "@/lib/fabricui/mount";
import { Drape as DrapeEngine } from "@/lib/fabricui/drape-engine";
import "./drape.css";

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

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

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

/* light: a soft grey ink rather than black */
[data-theme="light"] .drape:where(.fui-drape, .fui-drape *) { color: #737373; }   /* a step under the moon's: its dots are sparser and smaller, so this reads the same */
lib/fabricui/drape-engine.js
/*
 * drape-engine.js — Drape (drape.css). An orb for showing what an assistant is
 * doing: a round cloth of 1-bit dots wrapped over an unseen ball. Over the top
 * it lies smooth; past the widest point there's more cloth than ball, so it
 * gathers into soft folds that deepen toward an uneven hem, tucked under. From
 * the front it reads as an orb in a cloth. Every dot is the same small round dot, on or off: the light is how
 * many are on, through an 8×8 ordered pattern laid on the sheet's own grid,
 * so it reads as dithered cloth. Drawn on a 2D canvas (no WebGL).
 *
 *   const d = new Drape(rootEl, { state: "thinking", size: 64 });
 *   d.set({ state: "done" });
 *
 *   idle       draped, a slow ripple through the cloth
 *   listening  the cloth trembles with the voice (`level`, 0–1; made up if not given)
 *   thinking   it lifts and settles, lifts and settles, turning as it goes
 *   searching  a wave runs round the hem and up through the sheet

Usage

Usage
"use client";

import { Drape } from "@/components/fabricui/drape";

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

// beside a line of text
export function Status() {
  return <p><Drape 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—