Design Token Generation
When to use this skill
Use this skill when you need to:
- Generate design tokens from component dimension configurations
- Create token combinations from multiple dimensions (variant, state, size, theme, etc.)
- Build hierarchical token naming structures using slash notation
- Transform dimension schemas into complete token sets
- Generate tokens with proper Figma variable metadata (types and scopes)
How to generate tokens
Basic token generation
Define your configuration:
baseName: Component name (e.g., "button", "card")
dimensions: Array of dimension objects with id, enabled status, and selected values
selectedValues: Object mapping dimension IDs to Sets of selected values
customOrder: Optional array to specify dimension ordering
Use the generation script:
const config = {
baseName: 'button',
dimensions: activeDimensions,
selectedValues: selectedValuesMap,
customOrder: ['component', 'variant', 'state', 'property']
};
const tokens = generateTokens(config);
Generated tokens include:
name: Hierarchical slash-separated token name
type: Figma variable type (COLOR, FLOAT, STRING, BOOLEAN)
scopes: Array of Figma scopes for the property
Dimension configuration structure
Each dimension must have:
id: Unique identifier (variant, state, size, property, etc.)
enabled: Boolean indicating if dimension is active
values: Array of possible values (strings or objects with metadata)
For property dimensions, values should include Figma metadata:
{
name: 'background-color',
type: 'COLOR',
scopes: ['FRAME_FILL', 'SHAPE_FILL']
}
Token naming conventions
Tokens are named using forward slash hierarchy:
button/primary/default/background-color
card/elevated/hover/shadow-color
text/heading/large/font-size
Custom ordering
You can specify custom dimension ordering including the component name:
customOrder: ['component', 'variant', 'state', 'size', 'property']
If no custom order is provided, the default is:
- Component name (if present)
- Dimensions in their default order
Property type mapping
The skill automatically maps CSS properties to Figma variable types:
Colors (COLOR type)
background-color → FRAME_FILL, SHAPE_FILL
text-color → TEXT_FILL
border-color → STROKE_COLOR
shadow-color → EFFECT_COLOR
Numbers (FLOAT type)
width, height → WIDTH_HEIGHT
border-radius → CORNER_RADIUS
padding, margin, gap → GAP
font-size → FONT_SIZE
opacity → OPACITY
Text (STRING type)
font-family → FONT_FAMILY
font-style, text-align → ALL_SCOPES
Examples
Simple button tokens
const config = {
baseName: 'button',
dimensions: [
{ id: 'variant', enabled: true, values: ['primary', 'secondary'] },
{ id: 'state', enabled: true, values: ['default', 'hover'] },
{ id: 'property', enabled: true, values: [
{ name: 'background-color', type: 'COLOR', scopes: ['FRAME_FILL'] }
]}
],
selectedValues: {
variant: new Set(['primary', 'secondary']),
state: new Set(['default', 'hover']),
property: new Set(['background-color'])
}
};
// Generates:
// button/primary/default/background-color
// button/primary/hover/background-color
// button/secondary/default/background-color
// button/secondary/hover/background-color
Typography tokens with custom order
const config = {
baseName: 'text',
customOrder: ['component', 'hierarchy', 'size', 'property'],
// ... dimensions and selectedValues
};
// Generates:
// text/heading/large/font-size
// text/body/medium/line-height
Common patterns
Primitive tokens
- Color scales:
red/50, red/100, red/500
- Spacing:
spacing/xs, spacing/md, spacing/lg
- Typography:
font-size/sm, font-weight/bold
Semantic tokens
- Purpose-based:
color/primary, color/success, color/warning
- Context-aware:
surface/elevated, text/muted
Component tokens
- Component-specific:
button/primary/hover/background-color
- State-aware:
input/error/border-color
1---2name: design-token-generation3description: Generates design tokens from multi-dimensional configurations, creating hierarchical token names with proper naming conventions. Use when building design systems, creating token sets from component schemas, or generating token combinations from dimensions like variant, state, size, and properties.4---5
6# Design Token Generation
7
8## When to use this skill
9
10Use this skill when you need to:
11- Generate design tokens from component dimension configurations
12- Create token combinations from multiple dimensions (variant, state, size, theme, etc.)
13- Build hierarchical token naming structures using slash notation
14- Transform dimension schemas into complete token sets
15- Generate tokens with proper Figma variable metadata (types and scopes)
16
17## How to generate tokens
18
19### Basic token generation
20
211. **Define your configuration**:
22 - `baseName`: Component name (e.g., "button", "card")
23 - `dimensions`: Array of dimension objects with id, enabled status, and selected values
24 - `selectedValues`: Object mapping dimension IDs to Sets of selected values
25 - `customOrder`: Optional array to specify dimension ordering
26
272. **Use the generation script**:
28 ```javascript
29 const config = {
30 baseName: 'button',
31 dimensions: activeDimensions,
32 selectedValues: selectedValuesMap,
33 customOrder: ['component', 'variant', 'state', 'property']
34 };
35 const tokens = generateTokens(config);
36 ```
37
383. **Generated tokens include**:
39 - `name`: Hierarchical slash-separated token name
40 - `type`: Figma variable type (COLOR, FLOAT, STRING, BOOLEAN)
41 - `scopes`: Array of Figma scopes for the property
42
43### Dimension configuration structure
44
45Each dimension must have:
46- `id`: Unique identifier (variant, state, size, property, etc.)
47- `enabled`: Boolean indicating if dimension is active
48- `values`: Array of possible values (strings or objects with metadata)
49
50For property dimensions, values should include Figma metadata:
51```javascript
52{
53 name: 'background-color',
54 type: 'COLOR',
55 scopes: ['FRAME_FILL', 'SHAPE_FILL']
56}
57```
58
59### Token naming conventions
60
61Tokens are named using forward slash hierarchy:
62- `button/primary/default/background-color`
63- `card/elevated/hover/shadow-color`
64- `text/heading/large/font-size`
65
66### Custom ordering
67
68You can specify custom dimension ordering including the component name:
69```javascript
70customOrder: ['component', 'variant', 'state', 'size', 'property']
71```
72
73If no custom order is provided, the default is:
741. Component name (if present)
752. Dimensions in their default order
76
77## Property type mapping
78
79The skill automatically maps CSS properties to Figma variable types:
80
81### Colors (COLOR type)
82- `background-color` → FRAME_FILL, SHAPE_FILL
83- `text-color` → TEXT_FILL
84- `border-color` → STROKE_COLOR
85- `shadow-color` → EFFECT_COLOR
86
87### Numbers (FLOAT type)
88- `width`, `height` → WIDTH_HEIGHT
89- `border-radius` → CORNER_RADIUS
90- `padding`, `margin`, `gap` → GAP
91- `font-size` → FONT_SIZE
92- `opacity` → OPACITY
93
94### Text (STRING type)
95- `font-family` → FONT_FAMILY
96- `font-style`, `text-align` → ALL_SCOPES
97
98## Examples
99
100### Simple button tokens
101```javascript
102const config = {
103 baseName: 'button',
104 dimensions: [
105 { id: 'variant', enabled: true, values: ['primary', 'secondary'] },
106 { id: 'state', enabled: true, values: ['default', 'hover'] },
107 { id: 'property', enabled: true, values: [
108 { name: 'background-color', type: 'COLOR', scopes: ['FRAME_FILL'] }
109 ]}
110 ],
111 selectedValues: {
112 variant: new Set(['primary', 'secondary']),
113 state: new Set(['default', 'hover']),
114 property: new Set(['background-color'])
115 }
116};
117
118// Generates:
119// button/primary/default/background-color
120// button/primary/hover/background-color
121// button/secondary/default/background-color
122// button/secondary/hover/background-color
123```
124
125### Typography tokens with custom order
126```javascript
127const config = {
128 baseName: 'text',
129 customOrder: ['component', 'hierarchy', 'size', 'property'],
130 // ... dimensions and selectedValues
131};
132
133// Generates:
134// text/heading/large/font-size
135// text/body/medium/line-height
136```
137
138## Common patterns
139
140### Primitive tokens
141- Color scales: `red/50`, `red/100`, `red/500`
142- Spacing: `spacing/xs`, `spacing/md`, `spacing/lg`
143- Typography: `font-size/sm`, `font-weight/bold`
144
145### Semantic tokens
146- Purpose-based: `color/primary`, `color/success`, `color/warning`
147- Context-aware: `surface/elevated`, `text/muted`
148
149### Component tokens
150- Component-specific: `button/primary/hover/background-color`
151- State-aware: `input/error/border-color`