![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@tokens-studio/sd-transforms
Advanced tools
Custom transforms for Style-Dictionary, to work with Design Tokens that are exported from Tokens Studio
This library is currently in beta.
This package contains custom transforms for Style-Dictionary, to work with Design Tokens that are exported from Tokens Studio:
Generic:
ts/descriptionToComment
ts/resolveMath
px
as a unit when missing (transitive) -> ts/size/px
%
to number between 0
and 1
-> ts/opacity
%
to unitless (150% -> 1.5) -> ts/size/lineheight
ts/type/fontWeight
ts/color/modifiers
CSS:
%
to em
-> ts/size/css/letterspacing
rgba()
format -> ts/color/css/hexrgba
ts/typography/css/shorthand
ts/shadow/css/shorthand
ts/border/css/shorthand
Android:
ts/typography/compose/shorthand
Registers the generic and CSS transforms, in addition to name/cti/camel
for naming purposes, as a transform group called tokens-studio
.
With NPM:
npm install @tokens-studio/sd-transforms
Note: this library is available both in CJS and ESM
const { registerTransforms } = require('@tokens-studio/sd-transforms');
// will register them on StyleDictionary object
// that is installed as a dependency of this package.
registerTransforms();
Can also import in ESM if needed.
In your Style-Dictionary config, you can either use the tokens-studio
transformGroup or the separate transforms (all of the names of those are listed):
{
"source": ["**/*.tokens.json"],
"platforms": {
"css": {
"transformGroup": "tokens-studio",
"buildPath": "build/css/",
"files": [
{
"destination": "variables.css",
"format": "css/variables"
}
]
}
}
}
More fine-grained control is possible, every transformation is available as a raw JavaScript function for you to create your own Style-Dictionary transformer out of.
const { transformDimension } = require('@tokens-studio/sd-transforms');
const StyleDictionary = require('style-dictionary');
StyleDictionary.registerTransform({
name: 'my/size/px',
type: 'value',
transitive: true,
matcher: token => ['fontSizes', 'dimension', 'borderRadius', 'spacing'].includes(token.type),
transformer: token => transformDimension(token.value),
});
You can pass options to the registerTransforms
function.
registerTransforms({
expand: {
composition: false,
typography: true,
border: (token, filePath) =>
token.value.width !== 0 && filePath.startsWith(path.resolve('tokens/core')),
shadow: false,
},
});
Options:
name | type | required | default | description |
---|---|---|---|---|
expand | boolean | ExpandOptions | ❌ | See props below | false to not register the parser at all. By default, expands composition tokens. Optionally, border, shadow and typography as well. |
expand.composition | boolean | ExpandFilter | ❌ | true | Whether or not to expand compositions. Also allows a filter callback function to conditionally expand per token/filePath |
expand.typography | boolean | ExpandFilter | ❌ | false | Whether or not to expand typography. Also allows a filter callback function to conditionally expand per token/filePath |
expand.shadow | boolean | ExpandFilter | ❌ | false | Whether or not to expand shadows. Also allows a filter callback function to conditionally expand per token/filePath |
expand.border | boolean | ExpandFilter | ❌ | false | Whether or not to expand borders. Also allows a filter callback function to conditionally expand per token/filePath |
Note: you can also import and use the
expandComposites
function to run the expansion on your token object manually. Handy if you have your own parsers set up (e.g. for JS files), and you want the expansions to work there too.
node build-tokens.js
build-tokens.js
:
const { registerTransforms } = require('@tokens-studio/sd-transforms');
const StyleDictionary = require('style-dictionary');
registerTransforms(StyleDictionary);
const sd = StyleDictionary.extend({
source: ['**/*.tokens.json'],
platforms: {
js: {
transformGroup: 'tokens-studio',
buildPath: 'build/js/',
files: [
{
destination: 'variables.js',
format: 'javascript/es6',
},
],
},
css: {
transforms: [
'ts/descriptionToComment',
'ts/size/px',
'ts/opacity',
'ts/size/css/letterspacing',
'ts/size/lineheight',
'ts/type/fontWeight',
'ts/resolveMath',
'ts/typography/css/shorthand',
'ts/border/css/shorthand',
'ts/shadow/css/shorthand',
'ts/color/css/hexrgba',
'ts/color/modifiers',
'name/cti/kebab',
],
buildPath: 'build/css/',
files: [
{
destination: 'variables.css',
format: 'css/variables',
},
],
},
},
});
sd.cleanAllPlatforms();
sd.buildAllPlatforms();
Note: make sure to choose either the full transformGroup, OR its separate transforms, so you can adjust or add your own. Combining a transformGroup with a transforms array can give unexpected results.
FAQs
Custom transforms for Style-Dictionary, to work with Design Tokens that are exported from Tokens Studio
The npm package @tokens-studio/sd-transforms receives a total of 13,885 weekly downloads. As such, @tokens-studio/sd-transforms popularity was classified as popular.
We found that @tokens-studio/sd-transforms demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.