ID card

A woven fabric ID card on a stitched lanyard. Take hold of it and it swings and creases like cloth.

Installation

Terminal
npx shadcn@latest add https://fabrickit.org/r/id-card.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/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);

Usage

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

PropTypeDefault
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.

booleantrue
entrance

It drops in on its strap and the strap catches it. Off, it is already hanging there.

booleantrue
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).

booleanfalse
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—