Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added vars references (#DS-2679) WIP #40

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions packages/design-tokens/web/components/markdown.json5
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
'max-width': { value: '{markdown.size.max-width}'},
'margin-top': { value: '{size.m}' },
'margin-bottom': { value: '{size.m}' },
'margin-top-after-paragraph': { value: '-{size.s}' },
'margin-top-after-paragraph': { value: 'calc(-1 * {size.s})' },
'ol-number-padding-right': { value: '{size.xxs}' },
'ul-padding': { value: '0 0 0 {size.xxl}' },
'item-margin-bottom': { value: '{size.xxs}' }
Expand Down Expand Up @@ -332,7 +332,7 @@
'margin-top': { value: '{size.m}' },
'margin-bottom': { value: '{size.m}' },

'caption-margin-top': { value: '-{size.s}' },
'caption-margin-top': { value: 'calc(-1 * {size.s})' },
'caption-margin-bottom': { value: '{size.xxl}' },
},
font: {
Expand Down
9 changes: 7 additions & 2 deletions packages/tokens-builder/configs/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ module.exports = {
destination: 'css-tokens.css',
format: 'css/variables',
filter: 'css-variables',
prefix: 'kbq'
prefix: 'kbq',
options: {
outputReferences: true
}
},
{
destination: 'css-tokens-light.css',
Expand All @@ -32,7 +35,9 @@ module.exports = {
filter: 'css-variables-font',
prefix: 'kbq',
options: {
selector: '.kbq-font'
selector: '.kbq-font',
// warnings expected, since global fonts are defined in css-tokens.css
outputReferences: true
}
}
]
Expand Down
14 changes: 13 additions & 1 deletion packages/tokens-builder/formats/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@ const getMapFromObj = (object) => {
return `(\n${result}\n)`;
};

const applyCustomTransformations = (dictionary) => {
dictionary.allProperties = dictionary.allTokens = dictionary.allTokens.flatMap((token) => {
if (typeof token.value === 'object' && token.type === 'font') {
return unwrapObjectTransformer(token);
}
return token;
});

return dictionary.allTokens;
};

module.exports = {
unwrapObjectTransformer,
getMapFromObj
getMapFromObj,
applyCustomTransformations
};
10 changes: 2 additions & 8 deletions packages/tokens-builder/formats/variables.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { formatHelpers } = require('style-dictionary');
const { unwrapObjectTransformer } = require('../formats/utils');
const { applyCustomTransformations } = require('../formats/utils');

module.exports = (StyleDictionary) => {
StyleDictionary.registerFormat({
Expand All @@ -8,13 +8,7 @@ module.exports = (StyleDictionary) => {
const selector = options.selector ? options.selector : `:root`;
const { outputReferences } = options;

// apply custom transformations for tokens
dictionary.allProperties = dictionary.allTokens = dictionary.allTokens.flatMap((token) => {
if (typeof token.value === 'object' && token.type === 'font') {
return unwrapObjectTransformer(token);
}
return token;
});
applyCustomTransformations(dictionary);

dictionary.allTokens.forEach((token) => {
token.name = token.name.replace(/(light|dark)-/, '');
Expand Down