Progress
How far along something is, with a dithered edge on the fill.
Installation
npx shadcn@latest add https://fabrickit.org/r/progress.jsonpnpm dlx shadcn@latest add https://fabrickit.org/r/progress.jsonyarn shadcn@latest add https://fabrickit.org/r/progress.jsonbunx --bun shadcn@latest add https://fabrickit.org/r/progress.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();lib/fabricui/dither.js/* * dither.js — Fabric Kit's dither, in one place. Every dithered thing (cloth * fold shade, shimmer, weaves, chart fills) uses this 4×4 ordered (Bayer) * pattern, so dots line up and read as one texture across components. * * Dither.B4 the 4×4 matrix, 0–15 * Dither.T4 its thresholds, centred: (v + 0.5) / 16 * Dither.at(x, y) the threshold for cell (x, y) * Dither.GLSL the same pattern for shaders: bayer4(cell) → 0–1 */ const B4 = [0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5]; const T4 = B4.map(v => v / 16 + 1 / 32); export const Dither = { B4, T4,Step 3: Copy the Progress files
The component itself. Create each one at the same path in your project. It's your code from here on.components/fabricui/progress.tsx"use client"; import * as React from "react"; import { mount } from "@/lib/fabricui/mount"; import { Progress as Engine } from "@/lib/fabricui/progress-engine"; import "./progress.css"; const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect; const cx = (...c: (string | false | undefined)[]) => c.filter(Boolean).join(" "); type Drawn = { set: (v: number, o?: { instant?: boolean }) => unknown; indeterminate: (on: boolean) => unknown; destroy: () => void }; /** What a ref gives you: set the value from code (instant skips the glide), or switch to indeterminate. */ export type ProgressHandle = { set: (value: number, options?: { instant?: boolean }) => void; indeterminate: (on: boolean) => void;components/fabricui/progress.css/* * Progress — how far along something is. Shared by every page that waits. * * The library's dither does the work (progress.js draws it): the fill's * leading edge dissolves into 2px Bayer dots instead of ending in a hard * line, and it closes up solid as it completes; a progress without a known * end is a dithered band sweeping along the track. No wobble or overshoot: * a progress bar must never show more than has happened. * * <div class="progress" role="progressbar" aria-label="Upload" data-value="40"></div> * <div class="progress" role="progressbar" aria-label="Export" data-indeterminate></div> * <div class="progress-ring" role="progressbar" aria-label="Sync" data-value="40" style="--s:72px"> * <span class="progress-ring__label">40%</span> * </div> * <div class="progress-steps" role="progressbar" aria-label="Setup" data-steps="4" data-value="1"></div> *lib/fabricui/progress-engine.js/* * progress-engine.js — draws every .progress, .progress-ring and .progress-steps * (see progress.css). From progress.js. * * Each one is a canvas. The value moves on a critically damped spring (it * glides to where it's told and never past it), and the fill's leading edge * is a dithered fade: 2px dots through the same 4×4 Bayer matrix as the * cloth, thinning out toward the value, so the edge looks like it's still * being woven. Near 100% the fade closes up and the fill finishes solid. * Indeterminate: a dithered band sweeps along the track. Colour changes * (done, paused) blend over ~200ms. Only draws while something is moving. * * const bar = Progress.get(el); // made on first use * bar.set(64); // 0–100 (steps: the number of steps done) * bar.set(0, { instant: true }); * bar.indeterminate(true);Step 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/progress. The Usage example below shows it in a page.
Code
"use client";
import * as React from "react";
import { mount } from "@/lib/fabricui/mount";
import { Progress as Engine } from "@/lib/fabricui/progress-engine";
import "./progress.css";
const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
const cx = (...c: (string | false | undefined)[]) => c.filter(Boolean).join(" ");
type Drawn = { set: (v: number, o?: { instant?: boolean }) => unknown; indeterminate: (on: boolean) => unknown; destroy: () => void };
/** What a ref gives you: set the value from code (instant skips the glide), or switch to indeterminate. */
export type ProgressHandle = {
set: (value: number, options?: { instant?: boolean }) => void;
indeterminate: (on: boolean) => void;/*
* Progress — how far along something is. Shared by every page that waits.
*
* The library's dither does the work (progress.js draws it): the fill's
* leading edge dissolves into 2px Bayer dots instead of ending in a hard
* line, and it closes up solid as it completes; a progress without a known
* end is a dithered band sweeping along the track. No wobble or overshoot:
* a progress bar must never show more than has happened.
*
* <div class="progress" role="progressbar" aria-label="Upload" data-value="40"></div>
* <div class="progress" role="progressbar" aria-label="Export" data-indeterminate></div>
* <div class="progress-ring" role="progressbar" aria-label="Sync" data-value="40" style="--s:72px">
* <span class="progress-ring__label">40%</span>
* </div>
* <div class="progress-steps" role="progressbar" aria-label="Setup" data-steps="4" data-value="1"></div>
*/*
* progress-engine.js — draws every .progress, .progress-ring and .progress-steps
* (see progress.css). From progress.js.
*
* Each one is a canvas. The value moves on a critically damped spring (it
* glides to where it's told and never past it), and the fill's leading edge
* is a dithered fade: 2px dots through the same 4×4 Bayer matrix as the
* cloth, thinning out toward the value, so the edge looks like it's still
* being woven. Near 100% the fade closes up and the fill finishes solid.
* Indeterminate: a dithered band sweeps along the track. Colour changes
* (done, paused) blend over ~200ms. Only draws while something is moving.
*
* const bar = Progress.get(el); // made on first use
* bar.set(64); // 0–100 (steps: the number of steps done)
* bar.set(0, { instant: true });
* bar.indeterminate(true);Usage
import { Progress, ProgressRing, ProgressSteps } from "@/components/fabricui/progress";
export function Upload({ percent, done }: { percent: number; done: boolean }) {
return <Progress aria-label="Uploading brand-assets.zip" value={percent} state={done ? "done" : undefined} />;
}
export function Export({ known, percent }: { known: boolean; percent: number }) {
return <Progress aria-label="Export" indeterminate={!known} value={percent} />;
}
export function Sync({ percent }: { percent: number }) {
return (
<ProgressRing aria-label="Syncing" value={percent} size={104}>
<b>{Math.round(percent)}%</b>
</ProgressRing>
);
}
export function Setup({ step }: { step: number }) {
return <ProgressSteps aria-label="Workspace setup" steps={4} value={step} />;
}Props
| Prop | Type | Default |
|---|---|---|
| value 0–100 (ProgressSteps: how many steps are done). It glides there on a spring that never runs past the truth. | number | 0 |
| indeterminate Not known yet: a dithered band sweeps along the track. Turn it off and the band hands over to the fill. | boolean | false |
| state done turns the fill green; paused greys it. The colour blends over. | "done" | "paused" | — |
| size Progress: 4, 6 or 8px tall. ProgressRing: a number, its width in px (72 by default). | "sm" | "md" | "lg" | "md" |
| steps ProgressSteps: how many segments. | number | — |
| ref Set it from code; instant jumps without the glide (to reset to 0, say). | { set(value, { instant }), indeterminate(on) } | — |
| ProgressRing The same, round. Its children sit in the middle. | component | — |
| ProgressSteps One segment per step: done ones fill; the one you're on is half-lit in dots. | component | — |