Goo Slider
Press the knob and a drop of goo pulls up out of it with the value, then drips back in.
Installation
Terminal
npx shadcn@latest add https://fabrickit.org/r/goo-slider.jsonTerminal
pnpm dlx shadcn@latest add https://fabrickit.org/r/goo-slider.jsonTerminal
yarn shadcn@latest add https://fabrickit.org/r/goo-slider.jsonTerminal
bunx --bun shadcn@latest add https://fabrickit.org/r/goo-slider.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/goo.js/* * goo.js — Fabric Kit's goo: the springs everything liquid moves on, and the * goo filters. * * GooKit.spring(s, target, w, z, dt) one damped spring step ({ x, v }), substepped * GooKit.still(s, target) settled? * GooKit.loop(owner, step) owner.kick() runs step(dt) each frame while it returns true * GooKit.key(e, value, min, max, step) slider keys → a new value * GooKit.reduced() prefers reduced motion? * ensureGooFilters() adds url(#fabric-goo) and url(#fabric-goo-sm) to the page, once * * The filters: blur, then a hard alpha cut, so shapes that touch flow into * each other as one liquid (#fabric-goo-sm is the same, tighter, for small parts). */ export const GooKit = { spring(s, target, w, z, dt) {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 Goo Slider files
The component itself. Create each one at the same path in your project. It's your code from here on.components/fabricui/goo-slider.tsx"use client"; import * as React from "react"; import { ensureGooFilters } from "@/lib/fabricui/goo"; import { GooSliderEngine } from "@/lib/fabricui/goo-slider-engine"; import "./goo-slider.css"; export type GooSliderProps = { /** The value (controlled). Leave out to let the slider keep its own. */ value?: number; /** The starting value when uncontrolled. */ defaultValue?: number; min?: number; max?: number; /** Called with each new whole-number value as it changes. */ onValueChange?: (value: number) => void;components/fabricui/goo-slider.css/* * Goo Slider * Everything moves on springs: the knob glides to the pointer; press it and * a drop of goo pulls up out of the knob, pinches off and floats above with * the value; let go and it drips back in. The drop trails the knob a beat * behind, so it swings when you drag fast. The goo filter covers the knob and * the drop only; the number sits on top, crisp. */ .fui-gs { position: relative; height: 28px; /* the hit area; the track is drawn in its middle */ cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; } .fui-gs__track, .fui-gs__fill {lib/fabricui/goo-slider-engine.js/* * goo-slider-engine.js — the Goo Slider's motion, framework-free. * The React component (components/fabricui/goo-slider.tsx) renders the parts * and hands them over; this moves them, every frame, on springs. */ import { GooKit } from "./goo"; /** * GooSlider. The value is whole numbers between min and max; the picture is * all springs: * knob x follows the pointer, stiff and critically damped (silky, no wobble) * drop x follows the knob, looser and a little bouncy (it swings behind) * lift the drop rising out of the knob while pressed, with a little bob * press the knob swelling slightly while held * Keyboard: arrows ±1 (Shift ±10), Page Up/Down ±10, Home/End. */components/fabricui/goo-range.tsx"use client"; import * as React from "react"; import { mount } from "@/lib/fabricui/mount"; import { ensureGooFilters } from "@/lib/fabricui/goo"; import { GooRange as GooRangeEngine } from "@/lib/fabricui/goo-range-engine"; import "./goo-range.css"; const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect; export type GooRangeProps = { /** The two values, low and high (controlled). Leave out to let the slider keep its own. */ value?: [number, number]; /** The starting values when uncontrolled. */ defaultValue?: [number, number]; min?: number;components/fabricui/goo-range.css/* * Goo sliders — Value, Range, Steps, Liquid (goo-sliders.js; needs goo.js). The liquid parts sit * in a layer under the page's #goo filter (an SVG filter: blur, then a hard * alpha cut; Steps uses the tighter #goo-sm), so whatever touches flows * together. Thin bars and numbers stay outside it, crisp. */ /* shared: the invisible, focusable stand-in for a knob, with its ring while held */ .gx-handle:where(.fui-goo-range, .fui-goo-range *) { position: absolute; left: 0; top: 50%; width: 28px; height: 28px; margin: -14px 0 0 -14px; border-radius: 50%;lib/fabricui/goo-range-engine.js/* * goo-range-engine.js — from goo-sliders.js (styles in components/fabricui/goo-range.css). * * new GooRange(el, { min, max, step, values: [lo, hi], format, onChange }) * Two knobs on one bar; each knob melts into the bar between them, and * when they meet they fuse into a single drop. * Its liquid parts sit in one layer under the #fabric-goo filter (blur, then a hard * alpha cut), so shapes that touch flow into each other. Everything moves on * springs, every frame. Keyboard: arrows (Shift ×10), Page Up/Down, Home/End. */ import { GooKit } from "./goo"; export class GooRange { /** * @param {HTMLElement} root the .gr element * @param {{ min?: number, max?: number, step?: number, values?: number[], format?: (v: number) => string, onChange?: (values: number[]) => void }} [options]components/fabricui/goo-steps.tsx"use client"; import * as React from "react"; import { mount } from "@/lib/fabricui/mount"; import { ensureGooFilters } from "@/lib/fabricui/goo"; import { GooSteps as GooStepsEngine } from "@/lib/fabricui/goo-steps-engine"; import "./goo-steps.css"; const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect; export type GooStepsProps = { /** The steps' names, in order (shown under their dots). Read when it mounts. */ steps: string[]; /** The chosen step's index (controlled). Leave out to let the slider keep its own. */ value?: number; /** The starting step when uncontrolled. */components/fabricui/goo-steps.css/* * Goo sliders — Value, Range, Steps, Liquid (goo-sliders.js; needs goo.js). The liquid parts sit * in a layer under the page's #goo filter (an SVG filter: blur, then a hard * alpha cut; Steps uses the tighter #goo-sm), so whatever touches flows * together. Thin bars and numbers stay outside it, crisp. */ /* shared: the invisible, focusable stand-in for a knob, with its ring while held */ .gx-handle:where(.fui-goo-steps, .fui-goo-steps *) { position: absolute; left: 0; top: 50%; width: 28px; height: 28px; margin: -14px 0 0 -14px; border-radius: 50%;lib/fabricui/goo-steps-engine.js/* * goo-steps-engine.js — from goo-sliders.js (styles in components/fabricui/goo-steps.css). * * new GooSteps(el, { steps: ["240p", …], value, onChange }) * A bead on a string of step dots: it slides freely while you drag, * swallowing each dot it passes, and drops into the nearest step with a * little wobble when you let go. * Its liquid parts sit in one layer under the #fabric-goo filter (blur, then a hard * alpha cut), so shapes that touch flow into each other. Everything moves on * springs, every frame. Keyboard: arrows (Shift ×10), Page Up/Down, Home/End. */ import { GooKit } from "./goo"; export class GooSteps { /** * @param {HTMLElement} root the .gst elementcomponents/fabricui/goo-liquid.tsx"use client"; import * as React from "react"; import { mount } from "@/lib/fabricui/mount"; import { ensureGooFilters } from "@/lib/fabricui/goo"; import { GooLiquid as GooLiquidEngine } from "@/lib/fabricui/goo-liquid-engine"; import "./goo-liquid.css"; const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect; export type GooLiquidProps = { /** The value, 0 – 100 (controlled). Leave out to let the slider keep its own. */ value?: number; /** The starting value when uncontrolled. */ defaultValue?: number; /** Called with each new whole-number value. */components/fabricui/goo-liquid.css/* * Goo sliders — Value, Range, Steps, Liquid (goo-sliders.js; needs goo.js). The liquid parts sit * in a layer under the page's #goo filter (an SVG filter: blur, then a hard * alpha cut; Steps uses the tighter #goo-sm), so whatever touches flows * together. Thin bars and numbers stay outside it, crisp. */ /* ---------- Liquid ---------- */ .gl:where(.fui-goo-liquid, .fui-goo-liquid *) { position: relative; height: 48px; border-radius: calc(48px * var(--fabric-roundness)); background: var(--fabric-surface); box-shadow: var(--fabric-edge); overflow: hidden; cursor: pointer;lib/fabricui/goo-liquid-engine.js/* * goo-liquid-engine.js — from goo-sliders.js (styles in components/fabricui/goo-liquid.css). * * new GooLiquid(el, { value, onChange }) * A thick bar filled with liquid (a volume control). The liquid's front * reaches for your finger ahead of the rest of it, stretching on a neck, * then the body catches up and the surface settles flat. * Its liquid parts sit in one layer under the #fabric-goo filter (blur, then a hard * alpha cut), so shapes that touch flow into each other. Everything moves on * springs, every frame. Keyboard: arrows (Shift ×10), Page Up/Down, Home/End. */ import { GooKit } from "./goo"; export class GooLiquid { /** * @param {HTMLElement} root the .gl elementStep 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/goo-slider. The Usage example below shows it in a page.
Code
components/fabricui/goo-slider.tsx
"use client";
import * as React from "react";
import { ensureGooFilters } from "@/lib/fabricui/goo";
import { GooSliderEngine } from "@/lib/fabricui/goo-slider-engine";
import "./goo-slider.css";
export type GooSliderProps = {
/** The value (controlled). Leave out to let the slider keep its own. */
value?: number;
/** The starting value when uncontrolled. */
defaultValue?: number;
min?: number;
max?: number;
/** Called with each new whole-number value as it changes. */
onValueChange?: (value: number) => void;components/fabricui/goo-slider.css
/*
* Goo Slider
* Everything moves on springs: the knob glides to the pointer; press it and
* a drop of goo pulls up out of the knob, pinches off and floats above with
* the value; let go and it drips back in. The drop trails the knob a beat
* behind, so it swings when you drag fast. The goo filter covers the knob and
* the drop only; the number sits on top, crisp.
*/
.fui-gs {
position: relative;
height: 28px; /* the hit area; the track is drawn in its middle */
cursor: pointer;
touch-action: none;
-webkit-tap-highlight-color: transparent;
}
.fui-gs__track, .fui-gs__fill {lib/fabricui/goo-slider-engine.js
/*
* goo-slider-engine.js — the Goo Slider's motion, framework-free.
* The React component (components/fabricui/goo-slider.tsx) renders the parts
* and hands them over; this moves them, every frame, on springs.
*/
import { GooKit } from "./goo";
/**
* GooSlider. The value is whole numbers between min and max; the picture is
* all springs:
* knob x follows the pointer, stiff and critically damped (silky, no wobble)
* drop x follows the knob, looser and a little bouncy (it swings behind)
* lift the drop rising out of the knob while pressed, with a little bob
* press the knob swelling slightly while held
* Keyboard: arrows ±1 (Shift ±10), Page Up/Down ±10, Home/End.
*/components/fabricui/goo-range.tsx
"use client";
import * as React from "react";
import { mount } from "@/lib/fabricui/mount";
import { ensureGooFilters } from "@/lib/fabricui/goo";
import { GooRange as GooRangeEngine } from "@/lib/fabricui/goo-range-engine";
import "./goo-range.css";
const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
export type GooRangeProps = {
/** The two values, low and high (controlled). Leave out to let the slider keep its own. */
value?: [number, number];
/** The starting values when uncontrolled. */
defaultValue?: [number, number];
min?: number;components/fabricui/goo-range.css
/*
* Goo sliders — Value, Range, Steps, Liquid (goo-sliders.js; needs goo.js). The liquid parts sit
* in a layer under the page's #goo filter (an SVG filter: blur, then a hard
* alpha cut; Steps uses the tighter #goo-sm), so whatever touches flows
* together. Thin bars and numbers stay outside it, crisp.
*/
/* shared: the invisible, focusable stand-in for a knob, with its ring while held */
.gx-handle:where(.fui-goo-range, .fui-goo-range *) {
position: absolute;
left: 0;
top: 50%;
width: 28px;
height: 28px;
margin: -14px 0 0 -14px;
border-radius: 50%;lib/fabricui/goo-range-engine.js
/*
* goo-range-engine.js — from goo-sliders.js (styles in components/fabricui/goo-range.css).
*
* new GooRange(el, { min, max, step, values: [lo, hi], format, onChange })
* Two knobs on one bar; each knob melts into the bar between them, and
* when they meet they fuse into a single drop.
* Its liquid parts sit in one layer under the #fabric-goo filter (blur, then a hard
* alpha cut), so shapes that touch flow into each other. Everything moves on
* springs, every frame. Keyboard: arrows (Shift ×10), Page Up/Down, Home/End.
*/
import { GooKit } from "./goo";
export class GooRange {
/**
* @param {HTMLElement} root the .gr element
* @param {{ min?: number, max?: number, step?: number, values?: number[], format?: (v: number) => string, onChange?: (values: number[]) => void }} [options]components/fabricui/goo-steps.tsx
"use client";
import * as React from "react";
import { mount } from "@/lib/fabricui/mount";
import { ensureGooFilters } from "@/lib/fabricui/goo";
import { GooSteps as GooStepsEngine } from "@/lib/fabricui/goo-steps-engine";
import "./goo-steps.css";
const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
export type GooStepsProps = {
/** The steps' names, in order (shown under their dots). Read when it mounts. */
steps: string[];
/** The chosen step's index (controlled). Leave out to let the slider keep its own. */
value?: number;
/** The starting step when uncontrolled. */components/fabricui/goo-steps.css
/*
* Goo sliders — Value, Range, Steps, Liquid (goo-sliders.js; needs goo.js). The liquid parts sit
* in a layer under the page's #goo filter (an SVG filter: blur, then a hard
* alpha cut; Steps uses the tighter #goo-sm), so whatever touches flows
* together. Thin bars and numbers stay outside it, crisp.
*/
/* shared: the invisible, focusable stand-in for a knob, with its ring while held */
.gx-handle:where(.fui-goo-steps, .fui-goo-steps *) {
position: absolute;
left: 0;
top: 50%;
width: 28px;
height: 28px;
margin: -14px 0 0 -14px;
border-radius: 50%;lib/fabricui/goo-steps-engine.js
/*
* goo-steps-engine.js — from goo-sliders.js (styles in components/fabricui/goo-steps.css).
*
* new GooSteps(el, { steps: ["240p", …], value, onChange })
* A bead on a string of step dots: it slides freely while you drag,
* swallowing each dot it passes, and drops into the nearest step with a
* little wobble when you let go.
* Its liquid parts sit in one layer under the #fabric-goo filter (blur, then a hard
* alpha cut), so shapes that touch flow into each other. Everything moves on
* springs, every frame. Keyboard: arrows (Shift ×10), Page Up/Down, Home/End.
*/
import { GooKit } from "./goo";
export class GooSteps {
/**
* @param {HTMLElement} root the .gst elementcomponents/fabricui/goo-liquid.tsx
"use client";
import * as React from "react";
import { mount } from "@/lib/fabricui/mount";
import { ensureGooFilters } from "@/lib/fabricui/goo";
import { GooLiquid as GooLiquidEngine } from "@/lib/fabricui/goo-liquid-engine";
import "./goo-liquid.css";
const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
export type GooLiquidProps = {
/** The value, 0 – 100 (controlled). Leave out to let the slider keep its own. */
value?: number;
/** The starting value when uncontrolled. */
defaultValue?: number;
/** Called with each new whole-number value. */components/fabricui/goo-liquid.css
/*
* Goo sliders — Value, Range, Steps, Liquid (goo-sliders.js; needs goo.js). The liquid parts sit
* in a layer under the page's #goo filter (an SVG filter: blur, then a hard
* alpha cut; Steps uses the tighter #goo-sm), so whatever touches flows
* together. Thin bars and numbers stay outside it, crisp.
*/
/* ---------- Liquid ---------- */
.gl:where(.fui-goo-liquid, .fui-goo-liquid *) {
position: relative;
height: 48px;
border-radius: calc(48px * var(--fabric-roundness));
background: var(--fabric-surface);
box-shadow: var(--fabric-edge);
overflow: hidden;
cursor: pointer;lib/fabricui/goo-liquid-engine.js
/*
* goo-liquid-engine.js — from goo-sliders.js (styles in components/fabricui/goo-liquid.css).
*
* new GooLiquid(el, { value, onChange })
* A thick bar filled with liquid (a volume control). The liquid's front
* reaches for your finger ahead of the rest of it, stretching on a neck,
* then the body catches up and the surface settles flat.
* Its liquid parts sit in one layer under the #fabric-goo filter (blur, then a hard
* alpha cut), so shapes that touch flow into each other. Everything moves on
* springs, every frame. Keyboard: arrows (Shift ×10), Page Up/Down, Home/End.
*/
import { GooKit } from "./goo";
export class GooLiquid {
/**
* @param {HTMLElement} root the .gl elementUsage
Usage
"use client";
import * as React from "react";
import { GooSlider } from "@/components/fabricui/goo-slider";
import { GooRange } from "@/components/fabricui/goo-range";
export function Volume() {
const [value, setValue] = React.useState(64);
return <GooSlider value={value} onValueChange={setValue} label="Volume" />;
}
// the other three work the same way: GooRange (two knobs), GooSteps (snaps to stops), GooLiquid
export function Budget() {
const [range, setRange] = React.useState<[number, number]>([180, 640]);
return <GooRange min={0} max={1000} step={10} value={range} onValueChange={setRange} />;
}Props
| Prop | Type | Default |
|---|---|---|
| value The value, if you control it. | number | — |
| defaultValue The starting value when you don't. | number | 50 |
| min The lowest value. | number | 0 |
| max The highest value. | number | 100 |
| onValueChange Called with each new whole-number value. | (value: number) => void | — |
| label The accessible name. | string | "Value" |