Skip to content

Commit

Permalink
Allow to keep some tokens in output as references (#1100)
Browse files Browse the repository at this point in the history
* initial test

* update style dictionary
  • Loading branch information
lukasoppermann authored Dec 17, 2024
1 parent 3f9754b commit b995538
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-kiwis-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/primitives': minor
---

Changing the way we use references in css output, to keep all references to tokens that are present in the final output
24 changes: 11 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"json5": "^2.2.1",
"markdown-table-ts": "^1.0.3",
"prettier": "^3.3.3",
"style-dictionary": "^4.1.3",
"style-dictionary": "^4.3.0",
"tsx": "^4.19.0",
"typescript": "5.6",
"typescript-eslint": "^8.16.0",
Expand Down
10 changes: 9 additions & 1 deletion src/platforms/css.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {isFromFile, isSource} from '../filters/index.js'
import type {PlatformInitializer} from '../types/platformInitializer.js'
import type {PlatformConfig, TransformedToken} from 'style-dictionary/types'
import {outputReferencesTransformed, outputReferencesFilter} from 'style-dictionary/utils'

const getCssSelectors = (outputFile: string) => {
// check for dark in the beginning of the output filename
Expand Down Expand Up @@ -57,7 +58,8 @@ export const css: PlatformInitializer = (outputFile, prefix, buildPath, options)
]),
options: {
showFileHeader: false,
outputReferences: false,
outputReferences: (token, platformOptions) =>
outputReferencesFilter(token, platformOptions) && outputReferencesTransformed(token, platformOptions),
descriptions: false,
queries: getCssSelectors(outputFile),
...options?.options,
Expand All @@ -76,6 +78,8 @@ export const css: PlatformInitializer = (outputFile, prefix, buildPath, options)
]),
options: {
showFileHeader: false,
outputReferences: (token, platformOptions) =>
outputReferencesFilter(token, platformOptions) && outputReferencesTransformed(token, platformOptions),
descriptions: false,
...options?.options,
},
Expand All @@ -86,6 +90,8 @@ export const css: PlatformInitializer = (outputFile, prefix, buildPath, options)
filter: token => isSource(token) && options?.themed !== true && token.$type === 'custom-viewportRange',
options: {
showFileHeader: false,
outputReferences: (token, platformOptions) =>
outputReferencesFilter(token, platformOptions) && outputReferencesTransformed(token, platformOptions),
},
},
{
Expand All @@ -99,6 +105,8 @@ export const css: PlatformInitializer = (outputFile, prefix, buildPath, options)
]),
options: {
descriptions: false,
outputReferences: (token, platformOptions) =>
outputReferencesFilter(token, platformOptions) && outputReferencesTransformed(token, platformOptions),
showFileHeader: false,
queries: [
{
Expand Down

0 comments on commit b995538

Please sign in to comment.