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

wip: box shadow tokens naar CSS #805

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 114 additions & 42 deletions proprietary/nora-design-tokens/style-dictionary.config.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
import { register } from '@tokens-studio/sd-transforms';
import { register, expandTypesMap } from '@tokens-studio/sd-transforms';
import StyleDictionary from 'style-dictionary';
import { typeDtcgDelegate } from 'style-dictionary/utils';

Check failure on line 3 in proprietary/nora-design-tokens/style-dictionary.config.mjs

View workflow job for this annotation

GitHub Actions / Continuous integration

'typeDtcgDelegate' is defined but never used
import { readFile } from 'node:fs/promises';
import { createConfig } from '../../style-dictionary-config.js';

const isLargeVwToken = (token) => {

Check failure on line 7 in proprietary/nora-design-tokens/style-dictionary.config.mjs

View workflow job for this annotation

GitHub Actions / Continuous integration

'isLargeVwToken' is assigned a value but never used
return token.path && token.path.includes('large-vw');
};
// https://tr.designtokens.org/format/#shadow
const isShadowToken = (token) =>

Check failure on line 11 in proprietary/nora-design-tokens/style-dictionary.config.mjs

View workflow job for this annotation

GitHub Actions / Continuous integration

'isShadowToken' is assigned a value but never used
!!token &&
typeof token === 'object' &&
token['$type'] === 'shadow' &&
typeof token['$value'] === 'object' &&
!!token['$value'] &&
typeof token['$value']['color'] === 'string' &&
typeof token['$value']['offsetX'] === 'string' &&
typeof token['$value']['offsetY'] === 'string' &&
typeof token['$value']['blur'] === 'string' &&
typeof token['$value']['spread'] === 'string';

const isBoxShadowToken = (token) =>

Check failure on line 23 in proprietary/nora-design-tokens/style-dictionary.config.mjs

View workflow job for this annotation

GitHub Actions / Continuous integration

'isBoxShadowToken' is assigned a value but never used
typeof token === 'object' &&
!!token &&
token['$type'] === 'boxShadow' &&
typeof token['$value'] === 'object' &&
typeof token['$value'] &&
typeof token['$value']['color'] === 'string' &&
typeof token['$value']['x'] === 'string' &&
typeof token['$value']['y'] === 'string' &&
typeof token['$value']['blur'] === 'string' &&
typeof token['$value']['spread'] === 'string';

const build = async () => {
const themeConfig = JSON.parse(await readFile('./src/config.json', 'utf-8'));
StyleDictionary.registerPreprocessor({
name: 'dtcg-delegate',
preprocessor: typeDtcgDelegate,
});
// StyleDictionary.registerPreprocessor({
// name: 'dtcg-delegate',
// preprocessor: typeDtcgDelegate,
// });

register(StyleDictionary, {
excludeParentKeys: true,
Expand All @@ -27,47 +51,95 @@
}),
preprocessors: ['tokens-studio', 'dtcg-delegate'],
source: ['figma/**/*.tokens.json'],
expand: {
typesMap: expandTypesMap,
},
});

sd.registerFilter({
name: 'filter-large-vw',
filter: isLargeVwToken,
});
// sd.registerFilter({
// name: 'filter-large-vw',
// filter: isLargeVwToken,
// });

sd.registerTransform({
name: 'name/remove-large-vw',
type: 'name',
filter: isLargeVwToken,
transform: (token) => {
return token.name.replace(/-large-vw/g, '');
},
});
// sd.registerTransform({
// name: 'name/remove-large-vw',
// type: 'name',
// filter: isLargeVwToken,
// transform: (token) => {
// return token.name.replace(/-large-vw/g, '');
// },
// });

// sd.registerTransform({
// name: 'boxShadow',
// type: 'value',
// // transitive: false,
// transform: (token) => {
// console.log(token);
// if (token['original']['$type'] === 'boxShadow') console.log(token);
// return;
// if (isBoxShadowToken(token)) {
// return {
// offsetX: token.x,
// offsetY: token.y,
// blur: token.blur,
// spread: token.spread,
// color: token.color,
// };
// } else {
// return token.value;
// }
// },
// });

// sd.registerTransform({
// name: 'boxShadow/css',
// type: 'value',
// transitive: false,
// transform: (token) => {
// // return token.value;
// let value = token.value;
// console.log(token);

// if (isShadowToken(token)) {
// const { x, y, blur, spread, color } = token.value;
// value = `${x} ${y} ${blur} ${spread} ${color}`;
// } else if (isBoxShadowToken(token)) {
// const { offsetX, offsetY, blur, spread, color } = token.value;
// value = `${offsetX} ${offsetY} ${blur} ${spread} ${color}`;
// }
// if (value !== token.value) {
// console.log(value);
// }
// return value;
// },
// });

sd.platforms.largeCss = {
transformGroup: 'tokens-studio',
transforms: ['name/kebab', 'name/remove-large-vw'],
buildPath: 'dist/',
files: [
{
destination: 'theme-large-vw.css',
format: 'css/variables',
filter: 'filter-large-vw',
options: {
selector: themeSelector,
outputReferences: true,
},
},
{
destination: 'variables-large-vw.css',
format: 'css/variables',
filter: 'filter-large-vw',
options: {
selector: `:root`,
outputReferences: true,
},
},
],
};
// sd.platforms.largeCss = {
// transformGroup: 'tokens-studio',
// transforms: ['name/kebab', 'name/remove-large-vw'],
// buildPath: 'dist/',
// files: [
// {
// destination: 'theme-large-vw.css',
// format: 'css/variables',
// filter: 'filter-large-vw',
// options: {
// selector: themeSelector,
// outputReferences: true,
// },
// },
// {
// destination: 'variables-large-vw.css',
// format: 'css/variables',
// filter: 'filter-large-vw',
// options: {
// selector: `:root`,
// outputReferences: true,
// },
// },
// ],
// };

await sd.cleanAllPlatforms();
await sd.buildAllPlatforms();
Expand Down
2 changes: 2 additions & 0 deletions style-dictionary-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ const createConfig = ({
},
css: {
transformGroups: 'tokens-studio',
// transforms: ['boxShadow', 'shadow/css/shorthand', 'name/kebab'],
// transforms: ['shadow/css/shorthand', 'name/kebab'],
transforms: ['name/kebab'],
buildPath: 'dist/',
files: [
Expand Down
Loading