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: new dark mode colors and tokens #554

Merged
merged 17 commits into from
Feb 6, 2024
Merged
26 changes: 25 additions & 1 deletion ui/theme/build/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const dark = {};
const light = {};
const staticColors = {};
const theme = {};
const themeDark = {};
const sizes = {};
const spaces = {};
const radii = {};
Expand Down Expand Up @@ -80,7 +81,7 @@ function handleColor() {
loopAndAdd(Tokens.color[colorGroup], staticColors, "-static");
break;
case "theme":
loopAndAdd(Tokens.color[colorGroup], theme);
loopAndAddTheme(Tokens.color[colorGroup]);
break;
default:
break;
Expand Down Expand Up @@ -109,6 +110,28 @@ function loopAndAdd(tokens, ToObject, hyphen) {
}
}


/** Sets up theme tokens */
function loopAndAddTheme(tokens) {
for (var token in tokens) {
//Must contain both a dark and light value. In a future update we should avoid this
if (tokens[token].hasOwnProperty("value") && tokens[token].hasOwnProperty("valueDark")) {
let value = tokens[token].value;
let darkValue = tokens[token].valueDark;
//Checks to see if it is a reference to another token
if (value[0] == "{") {
value = value.substring(1, value.length - 1);
darkValue = darkValue.substring(1, darkValue.length - 1);
theme[`${token}`] = `$${value}`;
themeDark[`${token}`] = `$${darkValue}`;

} else {
//Should have a reference token and not a tier 1 token
return;
}
}
}
}
/** Looks up the value of a token alias path depth supported up to 3 token[1][2][3]*/
function lookupValue(lookUpToken) {
const path = lookUpToken.split(".");
Expand Down Expand Up @@ -142,6 +165,7 @@ function createTransformTokens() {
export const dark=${JSON.stringify(dark)}
export const staticColors=${JSON.stringify(staticColors)}
export const defaultTheme=${JSON.stringify(theme)}
export const darkTheme=${JSON.stringify(themeDark)}
export const sizes=${JSON.stringify(sizes)}
export const spaces=${JSON.stringify(spaces)}
export const radii=${JSON.stringify(radii)}
Expand Down
2 changes: 1 addition & 1 deletion ui/theme/src/stitches.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const darkTheme = createTheme(`${prefix}-dark`, {
colors: {
...tokens.dark,
...tokens.staticColors,
...tokens.defaultTheme,
...tokens.darkTheme,
artmsilva marked this conversation as resolved.
Show resolved Hide resolved
},
});

Expand Down
Loading
Loading