Scrubber

A rail of threads that swell under the pointer; each item's card drops in as cloth.

Installation

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

import * as React from "react";
import { mount } from "@/lib/fabricui/mount";
import { Scrubber as ScrubberEngine } from "@/lib/fabricui/scrubber-engine";
import "./scrubber.css";

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

export type ScrubberItem = {
  id: string;
  /** The card's first line, and the tick's label for screen readers. */
  title: string;
  /** The card's second line (two lines at most). */
  detail?: string;
  /** 2 draws a longer tick: a landmark (a question in a thread, a chapter start). Default 1. */
components/fabricui/scrubber.css
/*
 * scrubber.css — Scrubber (scrubber-engine.js). A rail of ticks; each tick is
 * a thread the engine draws out by --pull (px) and lifts a touch by --lit (0–0.14);
 * only the tick whose card is showing (data-hot) is white.
 *
 *   <div class="scrub" data-orientation="vertical | horizontal">
 *     <ol class="scrub__rail"><li><button class="scrub__tick" data-weight="1|2"><span class="scrub__line"></span></button></li>…</ol>
 *     <div class="scrub-card">…</div>        (added by the engine; drops in as cloth)
 *   </div>
 */
.scrub:where(.fui-scrubber, .fui-scrubber *) { position: relative; }
.scrub__rail:where(.fui-scrubber, .fui-scrubber *) {
  display: flex;
  margin: 0;
  padding: 0;
  list-style: none;
lib/fabricui/scrubber-engine.js
/*
 * scrubber-engine.js — Scrubber (scrubber.css). Needs cloth-drop.js.
 *
 * A rail of ticks, one per item (a message in a thread, a chapter, a section),
 * that you run the pointer along. The ticks are threads: the one under the
 * pointer is drawn out and its neighbours with it, each on its own spring and
 * tied to the ones beside it, so the swell travels along the rail, overshoots
 * a little and ripples back when you leave. The item's card drops in beside it
 * as cloth the first time; while you keep moving, the same card slides along
 * and changes in place (no cloth again until it has been put away).
 *
 *   const s = new Scrubber(rootEl, { orientation: "vertical", onSelect: i => … });
 *
 * Markup (the React component renders it):
 *   <div class="scrub" data-orientation="vertical">
 *     <ol class="scrub__rail">

Usage

Usage
"use client";

import * as React from "react";
import { Scrubber } from "@/components/fabricui/scrubber";

const messages = [
  { id: "1", title: "Kick-off: what are we shipping?", detail: "Three launches, one migration.", weight: 2 },
  { id: "2", title: "Billing redesign", detail: "Invoices move into the dashboard." },
  { id: "3", title: "Offline mode", detail: "Drafts save locally and sync later." },
] as const;

export function Outline() {
  const [at, setAt] = React.useState(0);
  return <Scrubber items={[...messages]} value={at} onSelect={setAt} label="Jump to a message" />;
}

Props

PropTypeDefault
items

One tick each. title and detail fill the card (and the tick's label for screen readers); weight 2 draws a longer tick, for landmarks.

{ id: string; title: string; detail?: string; weight?: 1 | 2 }[]—
value

The current item: a brighter, longer tick, and where Tab lands.

number—
onSelect

An item was picked: clicked, scrubbed to and let go, or Enter / Space.

(index: number) => void—
orientation

Down the side with cards to the right, or along the bottom with cards above.

"vertical" | "horizontal""vertical"
label

The rail's accessible name.

string"Jump to"