Skip to content

Commit

Permalink
Merge pull request #3836 from Royal-Navy/feat/generate-css-vars-from-…
Browse files Browse the repository at this point in the history
…tokens

feat(DesignTokens): Generate and expose CSS vars
  • Loading branch information
m7kvqbe1 authored Jul 4, 2024
2 parents fcb8939 + aa27ff4 commit 47db5cb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/design-tokens/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
src/tokens
src/flat.ts
babel.config.js
build-dictionary.js
11 changes: 11 additions & 0 deletions packages/design-tokens/build-dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ StyleDictionary.registerFormat({
formatter: mapDeepDoubleQuotesTemplate,
})

StyleDictionary.registerFormat({
name: 'css/variables',
formatter: function ({ dictionary, options }) {
return `${this.selector || ':root'} {
${dictionary.allProperties
.map((prop) => `--${prop.name}: ${prop.value};`)
.join('\n ')}
}`
},
})

StyleDictionary.buildAllPlatforms()
22 changes: 17 additions & 5 deletions packages/design-tokens/config.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
{
"source": ["src/tokens/light/*.json"],
"platforms": {
"web": {
"transformGroup": "css",
"buildPath": "dist/",
"files": [
{
"destination": "variables.css",
"format": "css/variables"
}
]
},
"scss": {
"transformGroup": "scss",
"buildPath": "dist/",
"files": [{
"destination": "index.scss",
"format": "sass/map-deep-double-quotes",
"mapName": "tokens"
}]
"files": [
{
"destination": "variables.scss",
"format": "sass/map-deep-double-quotes",
"mapName": "tokens"
}
]
},
"ts-flat": {
"transformGroup": "js",
Expand Down
4 changes: 2 additions & 2 deletions packages/design-tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
"types": "tsc --emitDeclarationOnly --declarationMap --declaration --noEmit false --allowJs false --outDir dist/types",
"prepack": "pnpm run build",
"test": "jest",
"lint": "eslint src --ext .js --ext .jsx --ext .ts --ext .tsx --ext .json --max-warnings 0 --resolve-plugins-relative-to ../eslint-config-react"
"lint": "eslint src --ext .js --ext .jsx --ext .ts --ext .tsx --ext .json --resolve-plugins-relative-to ../eslint-config-react"
},
"lint-staged": {
"*.@(js|jsx|ts|tsx)": [
"eslint --ext .js --ext .jsx --ext .ts --ext .tsx --ext .json --max-warnings 0 --resolve-plugins-relative-to ../eslint-config-react",
"eslint --ext .js --ext .jsx --ext .ts --ext .tsx --ext .json --resolve-plugins-relative-to ../eslint-config-react",
"prettier --write"
]
},
Expand Down

0 comments on commit 47db5cb

Please sign in to comment.