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.
Installation
Terminal
npx shadcn@latest add https://fabrickit.org/r/drape.jsonTerminal
pnpm dlx shadcn@latest add https://fabrickit.org/r/drape.jsonTerminal
yarn shadcn@latest add https://fabrickit.org/r/drape.jsonTerminal
bunx --bun shadcn@latest add https://fabrickit.org/r/drape.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 Drape files
The component itself. Create each one at the same path in your project. It's your code from here on.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 sheetStep 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/drape. The Usage example below shows it in a page.
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 sheetUsage
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
| 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 | — |