Skip to content

Commit

Permalink
🎉 Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Androlax2 committed Apr 12, 2022
1 parent 11b9b4f commit 59398b1
Showing 1 changed file with 72 additions and 72 deletions.
144 changes: 72 additions & 72 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,93 +4,93 @@ const StyleDictionary = require('style-dictionary');
* Transform spacer to rem.
*/
StyleDictionary.registerTransform({
name: 'spacer/rem',
type: 'value',
matcher: function (prop) {
return prop.type === 'spacing';
},
transformer: function (prop) {
//@formatter:off
return `${(parseInt(prop.original.value) / 16).toString()}rem`;
//@formatter:on
}
name: 'spacer/rem',
type: 'value',
matcher: function (prop) {
return prop.type === 'spacing';
},
transformer: function (prop) {
//@formatter:off
return `${(parseInt(prop.original.value) / 16).toString()}rem`;
//@formatter:on
}
});

/**
* Transform font weights string to number.
*/
StyleDictionary.registerTransform({
name: 'font-weights/number',
type: 'value',
matcher: function (prop) {
return prop.type === 'fontWeights';
},
transformer: function (prop) {
switch (prop.original.value) {
case 'Regular':
return 400;
case 'Bold':
return 700;
}
}
name: 'font-weights/number',
type: 'value',
matcher: function (prop) {
return prop.type === 'fontWeights';
},
transformer: function (prop) {
switch (prop.original.value) {
case 'Regular':
return 400;
case 'Bold':
return 700;
}
}
});

/**
* Register filter to filter typography.
*/
StyleDictionary.registerFilter({
name: 'filter-typography',
matcher: function (prop) {
return [
"fontFamilies",
"fontWeights",
"fontSizes",
"letterSpacing",
"lineHeights"
].includes(prop.attributes.category);
}
name: 'filter-typography',
matcher: function (prop) {
return [
'fontFamilies',
'fontWeights',
'fontSizes',
'letterSpacing',
'lineHeights'
].includes(prop.attributes.category);
}
});

StyleDictionary.extend({
source: ["resources/figma-tokens/**/*.tokens.json"],
platforms: {
scss: {
transformGroup: "scss",
transforms: [
"spacer/rem",
"font-weights/number",
"attribute/cti",
"name/cti/kebab",
"time/seconds",
"content/icon",
"size/rem",
"color/css"
],
buildPath: "resources/styles/style-dictionary/",
prefix: "token",
files: [
{
destination: "_colors.scss",
format: "css/variables",
filter: {
type: "color"
}
},
{
destination: "_typography.scss",
format: "css/variables",
filter: "filter-typography"
},
{
destination: "_spacers.scss",
format: "css/variables",
filter: {
type: "spacing"
}
}
]
}
}
source: ['resources/figma-tokens/**/*.tokens.json'],
platforms: {
scss: {
transformGroup: 'scss',
transforms: [
'spacer/rem',
'font-weights/number',
'attribute/cti',
'name/cti/kebab',
'time/seconds',
'content/icon',
'size/rem',
'color/css'
],
buildPath: 'resources/styles/style-dictionary/',
prefix: 'token',
files: [
{
destination: '_colors.scss',
format: 'css/variables',
filter: {
type: 'color'
}
},
{
destination: '_typography.scss',
format: 'css/variables',
filter: 'filter-typography'
},
{
destination: '_spacers.scss',
format: 'css/variables',
filter: {
type: 'spacing'
}
}
]
}
}
});

export default StyleDictionary;

0 comments on commit 59398b1

Please sign in to comment.