Gathering detailed insights and metrics for @divriots/style-dictionary-to-figma
Gathering detailed insights and metrics for @divriots/style-dictionary-to-figma
Gathering detailed insights and metrics for @divriots/style-dictionary-to-figma
Gathering detailed insights and metrics for @divriots/style-dictionary-to-figma
A utility that mutates and transforms a style-dictionary object into something Figma Tokens plugin understands.
npm install @divriots/style-dictionary-to-figma
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
104 Stars
43 Commits
7 Forks
3 Watching
5 Branches
7 Contributors
Updated on 16 Nov 2024
JavaScript (99.79%)
Shell (0.21%)
Cumulative downloads
Total Downloads
Last day
-59.1%
1,270
Compared to previous day
Last week
1.5%
9,541
Compared to previous week
Last month
8.1%
35,966
Compared to previous month
Last year
839.5%
332,965
Compared to previous year
A utility that transforms a style-dictionary object into something Figma Tokens plugin understands.
Used by Design Systems in Backlight using design tokens in style-dictionary that can be synced into Figma via the Figma Tokens plugin.
The tool, at the moment, assumes usage of the Sync feature of Figma Tokens Plugin. The JSON output is catered to this as it is a single file containing the tokensets information.
Supports marking a token group as a custom tokenset so that it will appear as a separate tokenset in Figma. By default, "global"
is used as the tokenset, and your tokens will be placed inside of this, but you can override it. This is useful if you want to combine many base tokens into a "global" set but theme-specific token groups into a "theme-dark" set for example. You can configure it like so:
1{ 2 "color": { 3 "tokenset": "custom", 4 "primary": { 5 "base": { 6 "type": "color", 7 "value": "#14b8a6" 8 } 9 } 10 } 11}
color.primary.base
token will appear under custom
tokenset now in the plugin.
You can also configure or turn off this automatic tokenset mapping by passing defaultTokenset: false
or configuring a string for it defaultTokenset: 'default'
Trims .value
from reference values as Figma Tokens plugin does not use this suffix.
Trims the name
properties from tokens since Figma Tokens plugin uses this property to name its tokens, however, without a name property it creates its own naming/nesting by the object structure which is way nicer.
Use the reference values rather than its resolved values. Put ignoreUseRefValue: true
as a sibling property to the value prop if you want to make an exception and keep it as a resolved value.
Allow passing some optional options to adjust the object conversion:
true
, will clean up some of the meta info that style-dictionary creates, which Figma Tokens plugin doesn't care about. Can also pass a string[]
if you want to configure a blacklist of meta props that you want to filter out yourself1transform(obj, { cleanMeta: ['foo', 'bar'] });
1npm i @divriots/style-dictionary-to-figma
1import { transform } from '@divriots/style-dictionary-to-figma'; 2 3const sdObject = { ... }; 4const figmaObj = transform(sdObject);
In case you want its separate counterparts, you can import them separately.
1import { 2 trimValue, 3 trimName, 4 useRefValue, 5 markTokenset, 6 cleanMeta, 7} from '@divriots/style-dictionary-to-figma';
Once you transformed the object to Figma, a recommendation is to push this to GitHub and use the Figma Tokens plugin to sync with it to use the tokens in Figma.
Import the transform
utility and create a style-dictionary formatter:
1const { transform } = require('@divriots/style-dictionary-to-figma'); 2const StyleDictionary = require('style-dictionary'); 3 4StyleDictionary.registerFormat({ 5 name: 'figmaTokensPlugin', 6 formatter: ({ dictionary }) => { 7 const transformedTokens = transform(dictionary.tokens); 8 return JSON.stringify(transformedTokens, null, 2); 9 }, 10});
Or you can also put the formatter directly into the config without registering it imperatively:
1const { transform } = require('@divriots/style-dictionary-to-figma'); 2 3module.exports = { 4 source: ['**/*.tokens.json'], 5 format: { 6 figmaTokensPlugin: ({ dictionary }) => { 7 const transformedTokens = transform(dictionary.tokens); 8 return JSON.stringify(transformedTokens, null, 2); 9 }, 10 }, 11 platforms: { 12 json: { 13 transformGroup: 'js', 14 buildPath: '/tokens/', 15 files: [ 16 { 17 destination: 'tokens.json', 18 format: 'figmaTokensPlugin', 19 }, 20 ], 21 }, 22 }, 23};
This spits out a file /tokens/tokens.json
which Figma Tokens plugin can import (e.g. through GitHub).
Since Backlight has GitHub and Style-Dictionary integration out of the box, this process is very simple.
Perhaps you'd like to use this tool to generate a separate JSON file for each tokenset, which you can then manually paste into the Figma Tokens Plugin JSON view. For example, when you're not using the Figma Tokens Plugin Sync feature.
For this, refer to this code snippet from this issue.
No vulnerabilities found.
No security vulnerabilities found.