@reforma/icons
v0.2.0
Published
Icon library for Reforma design system
Readme
@reforma/icons
React/TypeScript icon library for the Reforma design system. The package automatically discovers icon packs from the src/ directory and generates optimized components with full TypeScript support.
Overview
This package provides a flexible icon system that:
- Automatically discovers icon packs from subdirectories in
src/(e.g.,src/12,src/14,src/16,src/custom-pack) - Optimizes SVG files by removing
fillattributes, Figma artifacts (likeclip-path), and unnecessary elements - Supports both SVG and PNG icons (PNG files are copied as-is without optimization)
- Generates React components for each icon with proper TypeScript types
- Provides base styles for consistent icon rendering with
currentColorinheritance - Offers strict TypeScript typing that ensures icon names match their respective packs
Usage
Basic Usage
import { Icon } from '@reforma/icons';
import '@reforma/icons/styles.css'; // Import base styles
// Using the Icon component with pack specification
<Icon pack="16" name="add" className="text-primary" title="Add item" />
// Without pack (uses default pack '16')
<Icon name="close" />Direct Icon Import
You can also import individual icons directly:
import { AddIcon } from '@reforma/icons/16';
import { CloseIcon } from '@reforma/icons/14';
<AddIcon className="text-primary" title="Add" />
<CloseIcon size={20} />Package Structure
packages/icons/
├── src/
│ ├── [pack]/ # Source of truth - place your SVG/PNG files here (e.g., 12/, 14/, 16/)
│ ├── icons-metadata.json # Icon metadata configuration
│ └── styles.css # Base icon styles
├── dist/ # Built output
│ ├── [pack]/ # Generated React components per pack
│ └── index.ts # Main entry point
└── scripts/
└── build.js # Build script that generates componentsCommands
Run from packages/icons:
bun run build— Generates React components from SVG files insrc/and builds the packagebun run sync— Synchronizes every icon pack from Figmabun run sync 14— Synchronizes only the exact14packbun run sync --list— Lists available Figma packs without changing local filesbun run sync auth— Replaces and verifies the saved Figma token without synchronizing filesbun run typecheck— Type checks the package
Run from the repository root:
./reforma sync icons— Synchronizes every icon pack from the configured Figma frame./reforma sync icons 14— Synchronizes only the14pack./reforma sync icons --list— Lists exact pack names, node IDs, and icon counts without exporting or writing./reforma sync icons --list --json— Returns the versioned pack list for scripts and AI agents./reforma sync icons auth— Replaces and verifies the saved token without synchronizing files
The node-specific URL of the root Figma frame is stored in icons-metadata.json:
{
"figma": {
"excludeFromSyncSuffix": "~",
"iconsSourceUrl": "https://www.figma.com/design/FILE_KEY/FILE_NAME?node-id=1-2"
}
}Run ./reforma sync icons auth and follow the authorization steps printed in the terminal:
- In the opened Figma settings, select Security.
- Under Personal access tokens, click Generate new token.
- Set Name to
Reforma icons. - Set Expiration to 90 days.
- Under Scopes, select Files →
file_content:read. - Generate and copy the token, then paste it into the hidden terminal prompt.
The command verifies access to the configured Figma file and stores the token outside the repository
in ~/.config/reforma/figma-access-token with user-only (0600) permissions. Later runs reuse it.
When Figma rejects an expired token, the command asks for a replacement.
FIGMA_ACCESS_TOKEN remains available as a non-interactive CI override. A non-interactive run
without a token fails with AUTH_REQUIRED; an agent must ask the developer to run
./reforma sync icons auth in their own terminal and must never request the token in chat.
During synchronization, the command shows the current phase and progress for pack comparison, SVG
export, downloading, local file updates, and package build. --json reserves stdout for one
versioned result, including addedFiles, changedFiles, and removedFiles; progress is written to stderr. Machine errors use stable codes including
AUTH_REQUIRED, PACK_NOT_FOUND, INVALID_FIGMA_STRUCTURE, and FIGMA_REQUEST_FAILED.
The root frame's direct auto-layout children are packs. Each pack frame name becomes the source
directory name, its text heading is ignored, and it must contain exactly one direct component set. A
variant property such as name=color is exported to color.svg. To bypass optimization for a new
icon, use the configured suffix in Figma too: with excludeFromOptimizationSuffix: ".",
name=google. becomes google..svg. The same suffix on a pack applies this behavior to every icon:
logo. synchronizes into src/logo, while its SVG files retain their original colors and structure.
A pack ending with figma.excludeFromSyncSuffix is excluded from synchronization entirely;
with the configured ~, private~ is not listed, exported, or validated.
The generated src/figma-icons-manifest.json stores a fingerprint per Figma component. Subsequent
runs export only new, renamed, visually changed, or locally modified vector icons. Variants that
contain component instances are conservatively re-exported because their master can change outside
the variant subtree. A full sync also removes previously managed icons and packs that no longer exist
in Figma; a selected sync changes only the requested packs, and pre-existing files absent from the
manifest are never removed. The package build runs only after managed source files changed.
What Happens During Build
When you run bun run build, the following happens:
- Clean — Removes
dist/and.turbo/directories - Process Icons — Processes icons from
src/:- SVG files: Optimized with SVGO to:
- Remove
fillattributes (icons inheritcurrentColor) - Remove
widthandheightattributes (keepsviewBoxfor flexibility) - Remove Figma artifacts (
clip-pathattributes, empty<defs>,<clipPath>elements) - Clean up unnecessary attributes and elements
- Remove
- PNG files: Copied as-is (no optimization)
- SVG files: Optimized with SVGO to:
- Generate Components — Creates:
- React components for each icon (one per file)
- Index files for each pack (barrel exports)
- Main index.ts that exports all packs
- Updates
package.jsonexports for each pack
- Copy Assets — Copies
styles.csstodist/
Adding New Icons
Step-by-Step Guide
Prepare your icons:
- Export SVG or PNG files from Figma (or any design tool)
- Ensure file names match the desired icon names (e.g.,
user-add.svg,settings.svg)
Place icons in the correct pack directory:
- Each subdirectory in
src/represents an icon pack - Pack names can be numeric (e.g.,
12,14,16) or custom strings (e.g.,custom-pack) - Example: To add an icon to pack
16, place it insrc/16/my-icon.svg
- Each subdirectory in
Run the build command:
cd packages/icons bun run buildVerify the results:
- Check
dist/[pack]/to see generated components - TypeScript types will be automatically updated
- Check
Rules for Adding Icons
- Icon name = file name: The icon name is derived from the file name (without extension)
user-add.svg→ icon name"user-add"settings.png→ icon name"settings"
- Skip optimization: Add the suffix configured in
icons-metadata.jsonto the source filename. Withoptimization.excludeFromOptimizationSuffix: ".",google..svgskips SVGO and still exports asGoogle. - Pattern exclusions:
packs[pack].excludeFromOptimizationremains available for glob-based or pack-wide exclusions. - File format: Supported formats are
.svgand.png - Naming convention: Use kebab-case for file names (e.g.,
user-add.svg, notuserAdd.svg)
SVG Requirements
For best results, SVG files should:
- Use
currentColorfor fills/strokes (or no fill attribute, which will be removed during optimization) - Have a
viewBoxattribute (width/height will be removed) - Not contain hard-coded colors
- Have transparent backgrounds (no raster data)
The optimization process will:
- ✅ Remove
fillattributes (ensurescurrentColorinheritance) - ✅ Remove
widthandheightattributes - ✅ Remove Figma artifacts (
clip-path, empty<defs>,<clipPath>) - ✅ Clean up unnecessary attributes
- ✅ Preserve
viewBoxfor flexible sizing
Styles
The package includes base styles in styles.css that ensure icons inherit currentColor by default. Import them in your application:
// In your main CSS file (e.g., globals.css)
import '@reforma/icons/styles.css';The styles ensure:
- Icons inherit
currentColorfrom their parent - SVG and IMG elements properly handle sizing
- Consistent rendering across different icon types
TypeScript Types
The package provides the following types:
IconPack— Union type of all pack namesIconName— Union type of all icon names across all packsIconCollection— Object type mapping packs to their icon names:type IconCollection = { 'pack1': 'close' | 'code' | ...; 'pack2': 'H' | 'W' | ...; 'pack3': 'add' | 'arrow-left' | ...; };IconSize— Union type of numeric pack sizes (for backward compatibility)IconComponent— Type for individual icon components
Accessibility
The Icon component handles accessibility automatically:
- With
titleprop: Rendersrole="img"andaria-labelwith the title, plus a<title>element inside SVG - Without
titleprop: Rendersaria-hidden="true"to hide from assistive technologies
Fallback Behavior
If an icon is not found in the specified pack, the Icon component returns null. There is no automatic fallback to other packs — TypeScript will catch these errors at compile time when using strict typing.
