Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@divriots/style-dictionary-to-figma
Advanced tools
A utility that transforms a style-dictionary object into something Figma Tokens plugin understands
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:
{
"color": {
"tokenset": "custom",
"primary": {
"base": {
"type": "color",
"value": "#14b8a6"
}
}
}
}
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 yourselftransform(obj, { cleanMeta: ['foo', 'bar'] });
npm i @divriots/style-dictionary-to-figma
import { transform } from '@divriots/style-dictionary-to-figma';
const sdObject = { ... };
const figmaObj = transform(sdObject);
In case you want its separate counterparts, you can import them separately.
import {
trimValue,
trimName,
useRefValue,
markTokenset,
cleanMeta,
} 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:
const { transform } = require('@divriots/style-dictionary-to-figma');
const StyleDictionary = require('style-dictionary');
StyleDictionary.registerFormat({
name: 'figmaTokensPlugin',
formatter: ({ dictionary }) => {
const transformedTokens = transform(dictionary.tokens);
return JSON.stringify(transformedTokens, null, 2);
},
});
Or you can also put the formatter directly into the config without registering it imperatively:
const { transform } = require('@divriots/style-dictionary-to-figma');
module.exports = {
source: ['**/*.tokens.json'],
format: {
figmaTokensPlugin: ({ dictionary }) => {
const transformedTokens = transform(dictionary.tokens);
return JSON.stringify(transformedTokens, null, 2);
},
},
platforms: {
json: {
transformGroup: 'js',
buildPath: '/tokens/',
files: [
{
destination: 'tokens.json',
format: 'figmaTokensPlugin',
},
],
},
},
};
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.
0.4.0
ab01a1e: BREAKING: if an upper token group does not have a tokenset property, it will get placed in a "global" tokenset by default. This means that no action is required by the user of the transformer to get a working JSON for Figma Tokens Plugin, but this change is potentially breaking because of how it changes the JSON output.
{
"core": {
"color": {
"primary": {
"base": {
"type": "color",
"value": "#14b8a6"
},
"secondary": {
"type": "color",
"value": "#ff0000"
}
}
}
}
}
Nothing is changed in the output. However, if you have references, they might be broken because the plugin will interpret this as "color"
being the upper property in a tokenset called "core"
.
{
"core": {
"color": {
"primary": {
"base": {
"type": "color",
"value": "#14b8a6"
},
"secondary": {
"type": "color",
"value": "#ff0000"
}
}
}
}
}
turns into
{
"global": {
"core": {
"color": {
"primary": {
"base": {
"type": "color",
"value": "#14b8a6"
},
"secondary": {
"type": "color",
"value": "#ff0000"
}
}
}
}
}
}
Your reference, for example {core.color.primary.base}
will now work properly because "core"
is not interpreted as the tokenset, "global"
is.
FAQs
A utility that transforms a style-dictionary object into something Figma Tokens plugin understands
The npm package @divriots/style-dictionary-to-figma receives a total of 8,263 weekly downloads. As such, @divriots/style-dictionary-to-figma popularity was classified as popular.
We found that @divriots/style-dictionary-to-figma demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.