How to make this library consumable by a Figma Make project (Figma's AI code-gen tool that emits React + Tailwind).
Two things make a custom library actually usable in Make:
- It must be installable — Make runs
pnpm addlike any other project, so the package needs to be on npm at a version that contains your latest code. - Figma Make needs to know it exists and how to use it — either via a context doc you paste into the project, or via Figma Code Connect, which links the Figma components in your design library to the React components in this repo. Code Connect mappings are surfaced to Make when it generates code from a frame that uses those components.
Today the package is on npm but every *.figma.tsx mapping still has the 'FIGMA_COMPONENT_URL' stub, so Code Connect publishes nothing useful. The steps below fix both.
- Figma library file URL — the Figma file that hosts your component library (the components Figma Make will pick up). Code Connect needs a node URL per component; without a Figma library, Code Connect is moot and you'd stop after step 1.
FIGMA_ACCESS_TOKEN— a Figma personal access token with at least File Content read scope. The Code Connect CLI reads it from env.- npm login as the
@bgunnarssonowner (verify withnpm whoami).
The current 0.1.14 build in dist/ is dated Apr 27. Confirm what's on the registry, then bump and publish.
npm view @bgunnarsson/react-primitives version— compare to localpackage.json.- If divergent or unsure, bump: edit
package.jsonversion(patch bump). No CHANGELOG exists in this repo; don't invent one. npx tsc --noEmit— typecheck must pass.NODE_OPTIONS="--max-old-space-size=8192" pnpm build— required heap; the default OOMs mid-DTS perCLAUDE.md.pnpm publish --access public—publishConfig.accessis alreadypublicandfiles: ["dist"]keeps the tarball lean.- Smoke test from a scratch dir:
pnpm add @bgunnarsson/react-primitivesand importButtonto confirm types resolve.
Files touched: package.json (version field only).
There are 97 src/components/*/*.figma.tsx files, each containing the literal 'FIGMA_COMPONENT_URL'. Hand-editing 97 files is error-prone; drive it from a manifest.
-
Build a manifest
figma-mapping.jsonat repo root:{ "Button": "https://www.figma.com/design/<FILE_KEY>/<NAME>?node-id=<NODE_ID>", ... }Populate it by walking your Figma library file (Figma sidebar → component → "Copy link to selection"). Component names must match the directory names under
src/components/. -
Patch script — a one-shot Node script (e.g.
scripts/apply-figma-urls.mjs) that:- Reads
figma-mapping.json. - For each entry, opens
src/components/<Name>/<Name>.figma.tsxand replaces the single occurrence of'FIGMA_COMPONENT_URL'with the real URL. - Logs any component in the manifest that has no matching file, and any
.figma.tsxstill containing the placeholder after the run.
Idempotent — safe to re-run as you fill in more mappings.
- Reads
-
Validate prop mappings — after URLs are in, open 3–5 representative
.figma.tsxfiles (e.g.Button,Dialog,Input,PhoneInputfor a multi-part case) and confirm thepropsblock reflects the real Figma component props. The current scaffolds were generated against a placeholder URL, so prop names may not match the live Figma component. Fix divergences manually — no shortcut. -
Publish Code Connect:
FIGMA_ACCESS_TOKEN=… pnpm figma:publish. The script is already wired inpackage.json. Re-publish whenever you change a mapping.
Files touched: all 97 src/components/*/*.figma.tsx (URL string only, unless you also fix prop drift), plus the new figma-mapping.json and scripts/apply-figma-urls.mjs.
Make's AI doesn't auto-discover your library's API even when it's installed. Paste a short context block into the Figma Make project's instructions:
- Package name and install line (
pnpm add @bgunnarsson/react-primitives). - Import style — prefer the per-component subpath (
@bgunnarsson/react-primitives/components/Button) for tree-shaking; top-level barrel works too. - Styling rule — className only, no
styleprop on components; Tailwind expected on the consumer side. - Compound-component shape — e.g.
DialogisDialogTrigger+DialogContent+ …; no monolithic wrapper. - Polymorphism —
BoxandTextacceptas. - Controlled/uncontrolled convention —
value+onValueChange+defaultValue, distinguish withvalueProp !== undefined.
The existing README.md already covers most of this. Easiest path: paste the README's "Quick start" + the components table into Figma Make's project instructions.
npm view @bgunnarsson/react-primitives versionreturns the version you just published.- In a fresh dir:
pnpm init -y && pnpm add @bgunnarsson/react-primitives react react-dom && node -e "console.log(Object.keys(require('@bgunnarsson/react-primitives')).length)"— non-zero export count. grep -rl "FIGMA_COMPONENT_URL" src/componentsreturns nothing (or only the components you've intentionally deferred).pnpm figma:publishexits 0 and reports the expected number of mappings created/updated.- In a Figma Make project: install the package, prompt Make to "build a login form using @bgunnarsson/react-primitives", confirm the output imports from the package and uses real component names (Button, Input, Label).
- Release CI/CD. No
.github/workflowsexists; manualpnpm publishmatches the current workflow. - Renaming components, adding new ones, or changing the API surface to "fit" Figma. Code Connect maps existing components to Figma; don't reshape the library for it.