Accordion
Answers that unfold as cloth.
Billing with Egoist is simple and transparent. Choose a plan that fits your needs, add your payment method, and you're ready to go.
Track your usage, view payment history, download invoices, and manage your subscription, all from one place.
Yes. Cancel from your account settings in two clicks. You keep access until the end of your current billing period, and nothing renews after that.
If something isn't right within the first 14 days, reach out and we'll refund you in full, no questions, no forms.
Every plan includes collaborators. Invite teammates by email and choose whether they can edit, comment, or only view.
Seats are billed per month, prorated to the day.
All data is encrypted in transit and at rest. We never sell your data, and you can export or delete everything whenever you like.
Installation
npx shadcn@latest add https://fabrickit.org/r/accordion.jsonpnpm dlx shadcn@latest add https://fabrickit.org/r/accordion.jsonyarn shadcn@latest add https://fabrickit.org/r/accordion.jsonbunx --bun shadcn@latest add https://fabrickit.org/r/accordion.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/cloth-drop.jsimport { Dither } from "./dither"; /** * cloth-drop.js — the library's open/close motion, shared by every component * that drops open (calendar, accordion, …). * * ClothDrop: the open/close motion. * * Open is a dropped cloth: the panel falls under gravity from behind the * trigger (the calendar rides its bottom edge), the top edge catches, the * fabric stretches a touch and springs back, a wave runs up from the hem and * the drape folds and sway it was thrown into settle. * * The falling cloth is one finely subdivided WebGL mesh, textured with the * browser's own rendering of the calendar (the real HTML + CSS + Geist, drawn * through an SVG foreignObject), so its text is pixel-identical to the page.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 Accordion files
The component itself. Create each one at the same path in your project. It's your code from here on.components/fabricui/accordion.tsx"use client"; import * as React from "react"; import { mount } from "@/lib/fabricui/mount"; import { Accordion as AccordionEngine } from "@/lib/fabricui/accordion-engine"; import "./accordion.css"; const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect; export type AccordionProps = Omit<React.HTMLAttributes<HTMLDivElement>, "defaultValue"> & { /** The open item's index, -1 for none (controlled). Leave out to let it keep its own. */ value?: number; /** The item open at first when uncontrolled (-1: none). */ defaultValue?: number; /** Called with the open item's index (-1: none) when one is clicked open or shut. */ onValueChange?: (value: number) => void;components/fabricui/accordion.css/* * accordion.css — Accordion (accordion.js). Moved out of accordion.html. */ /* * Accordion. Each item is the calendar's trigger + panel pair: a #191919 * pill question with an edge glow, and an answer panel in #202020 tucked * up behind it. Answers drop open as cloth (cloth-drop.js, in-flow, so the * items below move with the falling fabric) and collapse plainly. */ .frame__slot:where(.fui-accordion, .fui-accordion *) { width: 320px; height: 420px; } .acc:where(.fui-accordion, .fui-accordion *) { display: flex; flex-direction: column; gap: 10px; }lib/fabricui/accordion-engine.jsimport { ClothDrop } from "./cloth-drop"; /* * accordion-engine.js — Accordion (accordion.css). Moved out of accordion.html so it can be used anywhere. */ const CHEVRON = `<svg class="icon acc__chevron" viewBox="0 0 24 24" aria-hidden="true"><path d="M18 9.00005C18 9.00005 13.5811 15 12 15C10.4188 15 6 9 6 9" /></svg>`; /** * Accordion: one item open at a time (opening one collapses the other), * clicking the open one closes it. Arrow keys move between questions. */ export class Accordion { /** * @param {HTMLElement} root * @param {({ q: string, a: string[] } | HTMLElement)[]} items questions to build, or `.acc__item`s already in root (rendered by accordion.tsx)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/accordion. The Usage example below shows it in a page.
Code
"use client";
import * as React from "react";
import { mount } from "@/lib/fabricui/mount";
import { Accordion as AccordionEngine } from "@/lib/fabricui/accordion-engine";
import "./accordion.css";
const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
export type AccordionProps = Omit<React.HTMLAttributes<HTMLDivElement>, "defaultValue"> & {
/** The open item's index, -1 for none (controlled). Leave out to let it keep its own. */
value?: number;
/** The item open at first when uncontrolled (-1: none). */
defaultValue?: number;
/** Called with the open item's index (-1: none) when one is clicked open or shut. */
onValueChange?: (value: number) => void;/*
* accordion.css — Accordion (accordion.js). Moved out of accordion.html.
*/
/*
* Accordion. Each item is the calendar's trigger + panel pair: a #191919
* pill question with an edge glow, and an answer panel in #202020 tucked
* up behind it. Answers drop open as cloth (cloth-drop.js, in-flow, so the
* items below move with the falling fabric) and collapse plainly.
*/
.frame__slot:where(.fui-accordion, .fui-accordion *) { width: 320px; height: 420px; }
.acc:where(.fui-accordion, .fui-accordion *) {
display: flex;
flex-direction: column;
gap: 10px;
}import { ClothDrop } from "./cloth-drop";
/*
* accordion-engine.js — Accordion (accordion.css). Moved out of accordion.html so it can be used anywhere.
*/
const CHEVRON = `<svg class="icon acc__chevron" viewBox="0 0 24 24" aria-hidden="true"><path d="M18 9.00005C18 9.00005 13.5811 15 12 15C10.4188 15 6 9 6 9" /></svg>`;
/**
* Accordion: one item open at a time (opening one collapses the other),
* clicking the open one closes it. Arrow keys move between questions.
*/
export class Accordion {
/**
* @param {HTMLElement} root
* @param {({ q: string, a: string[] } | HTMLElement)[]} items questions to build, or `.acc__item`s already in root (rendered by accordion.tsx)Usage
import { Accordion, AccordionItem } from "@/components/fabricui/accordion";
export function Faq() {
return (
<Accordion defaultValue={0}>
<AccordionItem title="How does billing work?">
<p>You're billed monthly from the day you start.</p>
</AccordionItem>
<AccordionItem title="Can I cancel my plan anytime?">
<p>Yes. Your plan stays active until the end of the period.</p>
</AccordionItem>
</Accordion>
);
}Props
| Prop | Type | Default |
|---|---|---|
| children The items. One is open at a time. | AccordionItem[] | — |
| value The open item's index, -1 for none, if you control it. | number | — |
| defaultValue The item open at first when you don't (-1: none). | number | 0 |
| onValueChange Called with the open item's index (-1: none) when one is clicked open or shut. | (value: number) => void | — |
| AccordionItem title The question: the item's trigger. | ReactNode | — |
| AccordionItem children The answer: paragraphs (<p>) or anything else. | ReactNode | — |