Jun 11, 2025
Creating strong, flexible design systems is vital in today's product development. At the core of these systems are design tokens. These tokens act as the single, reliable source for all your design choices—things like colors, fonts, and spacing. When these design decisions are made in a tool like Figma, the next challenge is smoothly turning them into usable code for different platforms, especially for dynamic themes that can change (like light or dark mode).
This is where Style Dictionary integrates seamlessly. It's an open-source tool that allows you to define your design tokens once and use them across platforms. Combined with custom transformations, it becomes an effective way to generate dynamic themes directly from your Figma files for React applications.
Design Tokens from Figma
Figma, with plugins like Tokens Studio for Figma (formerly Figma Tokens), enables designers to structure design decisions into JSON. These JSON structures can then be exported for further processing.
A common requirement is implementing light and dark themes, or even multiple brand themes. Managing these manually in code is error-prone. Style Dictionary offers an elegant solution by processing your tokens and applying logic to generate theme-specific outputs.
Style Dictionary: Your Theming Engine
Style Dictionary processes platform-agnostic tokens and generates platform-specific outputs. For React, you can generate JavaScript/TypeScript theme objects or CSS variables.
Tokens are defined hierarchically, such as:
json
For light/dark theming, you can export separate token sets (e.g., colors-light.json, colors-dark.json) and configure Style Dictionary to generate theme-specific code.
Dynamic Theming with Custom Transforms
To implement dynamic theming in React, you'll need:
Exported theme-specific JSON tokens from Figma.
Style Dictionary setup to handle light and dark tokens, with appropriate transforms and formats.
Integration of generated themes into your React application, using context, CSS variables, or libraries like styled-components.
Below is a React-based implementation focusing on colors.
Step 1: Export Tokens from Figma
Export your Figma tokens into tokens/light/color.json and tokens/dark/color.json:
tokens/light/color.json
json
Step 2: Set up Style Dictionary Project
Install Style Dictionary:
In package.json:
Step 3: Integrate into React Application
You can integrate these themes in a React app using styled-components, Emotion, CSS variables, or context.
Example with styled-components
Install:
export default App;
Beyond Colors: Applying to Other Tokens
The same approach applies to spacing, typography, border radius, shadows, etc. You’d:
Export tokens from Figma (e.g., spacing, typography).
Add transforms to convert units (e.g., px or rem to numbers or strings).
Create custom formats to output theme objects or CSS variable definitions.
For example, you can define spacing tokens as:
json
Then generate JavaScript objects:
js
Conclusion
Using Style Dictionary along with Figma and React provides a consistent, scalable theming pipeline:
Single source of truth in Figma.
Automatic code generation for multiple themes.
Consistent and error-free theme application in React.
Easy extension to support multiple brands, modes, or platforms.
This workflow accelerates development, minimizes manual work, and keeps your React app styles perfectly aligned with your design system.
Streamline Your Design-to-Code Workflow
Looking to automate your token pipeline without building it all yourself? Explore Superflex.ai an automation platform that keeps your design system in sync with Figma and generates ready-to-use code for React, Flutter, and more.