ID card
A woven fabric ID card on a stitched lanyard. Take hold of it and it swings and creases like cloth.
Installation
npx shadcn@latest add https://fabrickit.org/r/id-card.jsonpnpm dlx shadcn@latest add https://fabrickit.org/r/id-card.jsonyarn shadcn@latest add https://fabrickit.org/r/id-card.jsonbunx --bun shadcn@latest add https://fabrickit.org/r/id-card.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: Install its packages
It needs three from npm.Terminalnpm install threeStep 3: 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 4: Copy the ID card files
The component itself. Create each one at the same path in your project. It's your code from here on.components/fabricui/id-card.tsx"use client"; import * as React from "react"; import { mount } from "@/lib/fabricui/mount"; import { createIdCard, CARD_TEXT } from "@/lib/fabricui/id-card-engine"; import "./id-card.css"; const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect; type Engine = ReturnType<typeof createIdCard>; export type IdCardProps = Omit<React.HTMLAttributes<HTMLDivElement>, "children"> & { /** The holder's name, large across the lower half. */ name?: string; /** Under the name. */ role?: string;components/fabricui/id-card.css/* * ID card — a woven fabric ID card on a stitched lanyard strap, on the page's own background. * id-card-engine.js draws it (three.js) into .idcard__stage. * * <div class="idcard"> data-ready, data-grab, data-grabbing * <div class="idcard__stage"><canvas class="idcard__gl"></div> * </div> */ .idcard:where(.fui-id-card, .fui-id-card *) { position: relative; width: 100%; height: 560px; overflow: hidden; isolation: isolate; background: transparent; color: var(--fabric-text);lib/fabricui/id-card-engine.js/* * id-card-engine.js — the Fabric ID card: a woven fabric card hanging on a * stitched lanyard strap, on black. Drag the card and it swings and * cloth-simulates (id-card-cloth.js); its weave, ink and stitching are baked * into canvas textures (id-card-textures.js) and lit by one soft key light, a * cool rim and a whisper of fill. * * Carried over from the standalone page (main.js), made to live inside a * component: it draws into its own canvas in the element it's given, sizes to * that element, stops drawing while it's off screen or the tab is hidden, and * destroy() takes everything back (frame loop, listeners, GPU resources). * * const card = createIdCard(stage, { root, text: { name: "Ada L" }, zoom: false }); * card.setText({ role: "Engineer" }); // re-bakes the card's ink * card.setZoom(true); // scroll / pinch to get close to the weave * card.destroy();lib/fabricui/id-card-cloth.js/** * Position-based (Verlet) cloth: a fabric card sewn to the end of a lanyard strap. * The strap's bottom row *is* the card's top-centre row, so it's one connected sheet. * * Stability comes from three things layered on plain PBD cloth: * - shape matching toward the flat rest card (the stiffened-patch feel) * - extra damping on the card's centre-of-mass velocity (kills pendulum swing, * keeps local fabric motion alive) * - tethers only to truly pinned anchors (anything else injects energy) */ export const CARD_W = 5.4; export const CARD_H = 8.56; export class FabricSim { constructor() {lib/fabricui/id-card-textures.js/* * id-card-textures.js — the ID card's woven textures, baked on a canvas: * the card (plain weave, printed ink, hem, topstitch, frayed edge) and the * lanyard strap (tiling weave with selvedge stitching). Used by id-card-engine.js. */ import * as THREE from 'three'; /* ------------------------------------------------------------------ */ /* Small deterministic helpers */ /* ------------------------------------------------------------------ */ function mulberry32(a) { return function () { a |= 0; a = (a + 0x6d2b79f5) | 0; let t = Math.imul(a ^ (a >>> 15), 1 | a);Step 5: 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 6: Use it
Import it from @/components/fabricui/id-card. The Usage example below shows it in a page.
Code
"use client";
import * as React from "react";
import { mount } from "@/lib/fabricui/mount";
import { createIdCard, CARD_TEXT } from "@/lib/fabricui/id-card-engine";
import "./id-card.css";
const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
type Engine = ReturnType<typeof createIdCard>;
export type IdCardProps = Omit<React.HTMLAttributes<HTMLDivElement>, "children"> & {
/** The holder's name, large across the lower half. */
name?: string;
/** Under the name. */
role?: string;/*
* ID card — a woven fabric ID card on a stitched lanyard strap, on the page's own background.
* id-card-engine.js draws it (three.js) into .idcard__stage.
*
* <div class="idcard"> data-ready, data-grab, data-grabbing
* <div class="idcard__stage"><canvas class="idcard__gl"></div>
* </div>
*/
.idcard:where(.fui-id-card, .fui-id-card *) {
position: relative;
width: 100%;
height: 560px;
overflow: hidden;
isolation: isolate;
background: transparent;
color: var(--fabric-text);/*
* id-card-engine.js — the Fabric ID card: a woven fabric card hanging on a
* stitched lanyard strap, on black. Drag the card and it swings and
* cloth-simulates (id-card-cloth.js); its weave, ink and stitching are baked
* into canvas textures (id-card-textures.js) and lit by one soft key light, a
* cool rim and a whisper of fill.
*
* Carried over from the standalone page (main.js), made to live inside a
* component: it draws into its own canvas in the element it's given, sizes to
* that element, stops drawing while it's off screen or the tab is hidden, and
* destroy() takes everything back (frame loop, listeners, GPU resources).
*
* const card = createIdCard(stage, { root, text: { name: "Ada L" }, zoom: false });
* card.setText({ role: "Engineer" }); // re-bakes the card's ink
* card.setZoom(true); // scroll / pinch to get close to the weave
* card.destroy();/**
* Position-based (Verlet) cloth: a fabric card sewn to the end of a lanyard strap.
* The strap's bottom row *is* the card's top-centre row, so it's one connected sheet.
*
* Stability comes from three things layered on plain PBD cloth:
* - shape matching toward the flat rest card (the stiffened-patch feel)
* - extra damping on the card's centre-of-mass velocity (kills pendulum swing,
* keeps local fabric motion alive)
* - tethers only to truly pinned anchors (anything else injects energy)
*/
export const CARD_W = 5.4;
export const CARD_H = 8.56;
export class FabricSim {
constructor() {/*
* id-card-textures.js — the ID card's woven textures, baked on a canvas:
* the card (plain weave, printed ink, hem, topstitch, frayed edge) and the
* lanyard strap (tiling weave with selvedge stitching). Used by id-card-engine.js.
*/
import * as THREE from 'three';
/* ------------------------------------------------------------------ */
/* Small deterministic helpers */
/* ------------------------------------------------------------------ */
function mulberry32(a) {
return function () {
a |= 0;
a = (a + 0x6d2b79f5) | 0;
let t = Math.imul(a ^ (a >>> 15), 1 | a);Usage
"use client";
import { IdCard } from "@/components/fabricui/id-card";
export function Badge() {
return (
<IdCard
name="Ada L"
role="Engineer"
org="Analytical"
year="1843"
member="0001"
access="Engine room"
style={{ height: 640, borderRadius: 24 }}
/>
);
}Props
| Prop | Type | Default |
|---|---|---|
| name The holder's name, large across the lower half. A long name shrinks to fit. | string | "Aditya S" |
| role The line under the name. | string | "Design Engineer" |
| org The wordmark in the top left. | string | "Fabric Kit" |
| year Top right, dimmed. | string | "2026" |
| member The member number, bottom left. | string | "0427" |
| access What it gets you into, bottom right. | string | "All areas" |
| zoom Scroll or pinch over the card to get close to the weave. Zoomed all the way out, scrolling on moves the page. Off, the wheel always scrolls the page. | boolean | true |
| entrance It drops in on its strap and the strap catches it. Off, it is already hanging there. | boolean | true |
| autoplay It plays on its own, like a product video: a light breeze, a slow turn now and then, and the camera pushing in on the weave and back out. It doesn't take the pointer (no grabbing; with zoom on, the wheel still zooms). | boolean | false |
| onReady Called once the card is woven and hanging. | () => void | — |
| className Added to the root. It's 100% wide and 560 px tall; set its size with a class or style. | string | — |