forked from jpmorganchase/salt-ds
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1d6b3a
commit 2d107ab
Showing
9 changed files
with
341 additions
and
44 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,59 @@ | ||
{ | ||
"globalAssetSetIds": [ | ||
"mode--light-density--low", | ||
"mode--dark-density--low", | ||
"mode--light-density--high", | ||
"mode--dark-density--high" | ||
"salt-light", | ||
"salt-dark", | ||
"check", | ||
"coin", | ||
"dollar" | ||
], | ||
"allAssetSets": { | ||
"mode--light-density--low": { | ||
"id": "mode--light-density--low", | ||
"title": "mode--light-density--low", | ||
"inlineCss": "", | ||
"inlineJs": "document.body.setAttribute('mode', 'light'); document.body.setAttribute('density', 'low');", | ||
"salt-light": { | ||
"id": "salt-light", | ||
"title": "Salt (light)", | ||
"inlineJs": "document.body.setAttribute('data-mode', 'light');", | ||
"assets": [] | ||
}, | ||
"mode--dark-density--low": { | ||
"id": "mode--dark-density--low", | ||
"title": "mode--dark-density--low", | ||
"inlineCss": "", | ||
"inlineJs": "document.body.setAttribute('mode', 'dark'); document.body.setAttribute('density', 'low');", | ||
"salt-dark": { | ||
"id": "salt-dark", | ||
"title": "Salt (dark)", | ||
"inlineJs": "document.body.setAttribute('data-mode', 'dark');", | ||
"assets": [] | ||
}, | ||
"mode--light-density--high": { | ||
"id": "mode--light-density--high", | ||
"title": "mode--light-density--high", | ||
"inlineCss": "", | ||
"inlineJs": "document.body.setAttribute('mode', 'light'); document.body.setAttribute('density', 'high');", | ||
"assets": [] | ||
"check": { | ||
"id": "check", | ||
"title": "check", | ||
"assets": [ | ||
{ | ||
"src": "../dist/tokens/design-tokens.css" | ||
}, | ||
{ | ||
"src": "../../ks-theme-check.css" | ||
} | ||
] | ||
}, | ||
"mode--dark-density--high": { | ||
"id": "mode--dark-density--high", | ||
"title": "mode--dark-density--high", | ||
"inlineCss": "", | ||
"inlineJs": "document.body.setAttribute('mode', 'dark'); document.body.setAttribute('density', 'high');", | ||
"assets": [] | ||
"coin": { | ||
"id": "coin", | ||
"title": "coin", | ||
"assets": [ | ||
{ | ||
"src": "../dist/tokens/design-tokens.css" | ||
}, | ||
{ | ||
"src": "../../ks-theme-coin.css" | ||
} | ||
] | ||
}, | ||
"dollar": { | ||
"id": "dollar", | ||
"title": "dollar", | ||
"assets": [ | ||
{ | ||
"src": "../dist/tokens/design-tokens.css" | ||
}, | ||
{ | ||
"src": "../../ks-theme-dollar.css" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.salt-theme.salt-theme { | ||
--salt-actionable-primary-background: var(--theme-check-actionable-primary-background); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.salt-theme.salt-theme { | ||
--salt-actionable-primary-background: var(--theme-coin-actionable-primary-background); | ||
--salt-actionable-primary-background-hover: var(--theme-coin-actionable-primary-background-hover); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { join, relative } from "path"; | ||
import fs from "fs"; | ||
import { | ||
KnapsackAssetSetsConfig, | ||
KnapsackAssetSetConfig, | ||
} from "@knapsack/types"; | ||
import tokens from "./knapsack/dist/tokens/design-tokens.nested.json"; | ||
|
||
const cssTokens = fs.readFileSync( | ||
join(__dirname, "./knapsack/dist/tokens/design-tokens.css"), | ||
"utf8" | ||
); | ||
const assetSetsPath = join( | ||
__dirname, | ||
"./knapsack/data/knapsack.asset-sets.json" | ||
); | ||
console.log("Creating theme..."); | ||
const themeNames = Object.keys(tokens.theme); | ||
|
||
const themes = themeNames.map((theme) => { | ||
console.log(`Making theme ${theme}`); | ||
const themeTokenNames = cssTokens.split("\n").flatMap((line) => { | ||
if (!line.trim().startsWith(`--theme-${theme}`)) return []; | ||
const tokenName = line.trim().split(":")[0]; | ||
return [ | ||
`${tokenName.replace(`theme-${theme}`, `salt`)}: var(${tokenName});`, | ||
]; | ||
}); | ||
const contents = [".salt-theme.salt-theme {", ...themeTokenNames, "}"].join( | ||
"\n" | ||
); | ||
const cssPath = join(__dirname, `ks-theme-${theme}.css`); | ||
fs.writeFileSync(cssPath, contents, { | ||
encoding: "utf8", | ||
}); | ||
return { | ||
cssPath, | ||
themeName: theme, | ||
}; | ||
}); | ||
|
||
const assetSets: KnapsackAssetSetsConfig = { | ||
globalAssetSetIds: ["salt-light", "salt-dark", ...themeNames], | ||
allAssetSets: Object.fromEntries([ | ||
[ | ||
"salt-light", | ||
((): KnapsackAssetSetConfig => ({ | ||
id: "salt-light", | ||
title: "Salt (light)", | ||
inlineJs: "document.body.setAttribute('data-mode', 'light');", | ||
assets: [], | ||
}))(), | ||
], | ||
[ | ||
"salt-dark", | ||
((): KnapsackAssetSetConfig => ({ | ||
id: "salt-dark", | ||
title: "Salt (dark)", | ||
inlineJs: "document.body.setAttribute('data-mode', 'dark');", | ||
assets: [], | ||
}))(), | ||
], | ||
...themes.map(({ cssPath, themeName }) => { | ||
const assetSet: KnapsackAssetSetConfig = { | ||
id: themeName, | ||
title: themeName, | ||
assets: [ | ||
{ | ||
src: "../dist/tokens/design-tokens.css", | ||
}, | ||
{ | ||
src: relative(join(__dirname, "./knapsack/data"), cssPath), | ||
}, | ||
], | ||
}; | ||
return [themeName, assetSet]; | ||
}), | ||
]), | ||
}; | ||
|
||
fs.writeFileSync( | ||
join(__dirname, "./knapsack/data/knapsack.asset-sets.json"), | ||
JSON.stringify(assetSets, null, 2) | ||
); | ||
console.log("Done"); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.salt-theme.salt-theme { | ||
--salt-actionable-primary-background: var(--theme-dollar-actionable-primary-background); | ||
--salt-actionable-primary-background-hover: var(--theme-dollar-actionable-primary-background-hover); | ||
} |
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
Oops, something went wrong.