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

FIDEFE-4643 - Use value object in design-tokens.json #5

Merged
Merged
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
25 changes: 19 additions & 6 deletions toolkit/themes/shared/design-system/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Expand All @@ -9,22 +10,34 @@ const StyleDictionary = require("style-dictionary");
module.exports = {
source: ["design-tokens.json"],
transform: {
defaultTransform: {
type: "value",
transitive: true,
name: "defaultTransform",
matcher: token => token.original.value.default,
transformer: token => token.original.value.default
},
lightDarkTransform: {
type: "value",
transitive: true,
name: "lightDarkTransform",
matcher: token => token.original.value && token.original.dark,
matcher: token => token.original.value.light && token.original.value.dark,
transformer: token => {
let lightDarkValue = `light-dark(${token.original.value}, ${token.original.dark})`;
// modify the original value and everything works like magic
token.original.value = lightDarkValue;
return lightDarkValue;
return `light-dark(${token.original.value.light}, ${token.original.value.dark})`;
},
},
},
platforms: {
css: {
transforms: [...StyleDictionary.transformGroup.css, "lightDarkTransform"],
// The ordering of transforms matter, so if we encountered
// "light", "dark", and "default" in the value object then
// this ordering would ensure that the "default" value is
// used to generate the token's value.
transforms: [
...StyleDictionary.transformGroup.css,
"lightDarkTransform",
"defaultTransform",
],
buildPath: "build/css/",
files: [
{
Expand Down
36 changes: 24 additions & 12 deletions toolkit/themes/shared/design-system/design-tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,28 @@
},
"background": {
"critical": {
"value": "{color.red.05}",
"dark": "{color.red.80}"
"value": {
"light": "{color.red.05}",
"dark": "{color.red.80}"
}
},
"information": {
"value": "{color.blue.05}",
"dark": "{color.blue.80}"
"value": {
"light": "{color.blue.05}",
"dark": "{color.blue.80}"
}
},
"success": {
"value": "{color.green.05}",
"dark": "{color.yellow.80}"
"value": {
"light": "{color.green.05}",
"dark": "{color.yellow.80}"
}
},
"warning": {
"value": "{color.yellow.05}",
"dark": "{color.blue.80}"
"value": {
"light": "{color.yellow.05}",
"dark": "{color.blue.80}"
}
}
}
},
Expand All @@ -128,15 +136,19 @@
"value": "CanvasText"
},
"brand": {
"value": "{color.gray.100}",
"dark": "{color.gray.05}"
"value": {
"light": "{color.gray.100}",
"dark": "{color.gray.05}"
}
},
"platform": {
"value": "currentColor"
},
"deemphasized": {
"value": "color-mix(in srgb, currentColor 60%, transparent)",
"prefersContrastValue": "inherit"
"value": {
"default": "color-mix(in srgb, currentColor 60%, transparent)",
"prefersContrast": "inherit"
}
}
}
}