Created
September 9, 2022 09:11
-
-
Save joduplessis/a13230896862ad14d8ef12f8d74f7ff0 to your computer and use it in GitHub Desktop.
Style Dictionary setups for exporting darkValue values to 1 file or to 2 files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function darkFormatWrapper(format) { | |
return function (args) { | |
const darkTokens = [] | |
const dictionary = { | |
...args.dictionary | |
} | |
// Strip out the dark tokens | |
dictionary.allTokens = dictionary.allTokens.map((token) => { | |
const { darkValue } = token; | |
if (darkValue) darkTokens.push({ | |
...token, | |
value: token.darkValue, | |
name: token.name + '-dark', | |
}) | |
return token | |
}) | |
// Add them back in | |
dictionary.allTokens = [...dictionary.allTokens, ...darkTokens] | |
// Re-assign the dictionary | |
return StyleDictionary.format[format]({ ...args, dictionary }); | |
}; | |
} | |
module.exports = { | |
source: ["tokens/**/*.json"], | |
format: { | |
cssDark: darkFormatWrapper(`css/variables`), | |
}, | |
platforms: { | |
css: { | |
transformGroup: "css", | |
buildPath: "dist/", | |
prefix: "f-", | |
files: [ | |
{ | |
destination: "fold/base.css", | |
format: "cssDark", | |
filter: (token) => | |
token.darkValue && token.attributes.category === `color`, | |
}, | |
], | |
}, | |
}, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function darkFormatWrapper(format) { | |
return function (args) { | |
const dictionary = { | |
...args.dictionary | |
}; | |
// Replace the value with darkValue | |
dictionary.allTokens = dictionary.allTokens.map((token) => { | |
const { darkValue } = token; | |
if (darkValue) { | |
return { | |
...token, | |
value: token.darkValue, | |
}; | |
} else { | |
return token; | |
} | |
}); | |
// Re-assign the dictionary | |
return StyleDictionary.format[format]({ ...args, dictionary }); | |
}; | |
} | |
module.exports = { | |
source: ["tokens/**/*.json"], | |
format: { | |
cssDark: darkFormatWrapper(`css/variables`), | |
}, | |
platforms: { | |
css: { | |
transformGroup: "css", | |
buildPath: "dist/", | |
prefix: "f-", | |
files: [ | |
{ | |
destination: "fold/base.css", | |
format: "css/variables", | |
}, | |
{ | |
destination: "fold/base.css", | |
format: "cssDark", | |
filter: (token) => | |
token.darkValue && token.attributes.category === `color`, | |
}, | |
], | |
}, | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment