Skip to content

Commit b995538

Browse files
Allow to keep some tokens in output as references (#1100)
* initial test * update style dictionary
1 parent 3f9754b commit b995538

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

.changeset/khaki-kiwis-explain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/primitives': minor
3+
---
4+
5+
Changing the way we use references in css output, to keep all references to tokens that are present in the final output

package-lock.json

Lines changed: 11 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"json5": "^2.2.1",
7171
"markdown-table-ts": "^1.0.3",
7272
"prettier": "^3.3.3",
73-
"style-dictionary": "^4.1.3",
73+
"style-dictionary": "^4.3.0",
7474
"tsx": "^4.19.0",
7575
"typescript": "5.6",
7676
"typescript-eslint": "^8.16.0",

src/platforms/css.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {isFromFile, isSource} from '../filters/index.js'
22
import type {PlatformInitializer} from '../types/platformInitializer.js'
33
import type {PlatformConfig, TransformedToken} from 'style-dictionary/types'
4+
import {outputReferencesTransformed, outputReferencesFilter} from 'style-dictionary/utils'
45

56
const getCssSelectors = (outputFile: string) => {
67
// check for dark in the beginning of the output filename
@@ -57,7 +58,8 @@ export const css: PlatformInitializer = (outputFile, prefix, buildPath, options)
5758
]),
5859
options: {
5960
showFileHeader: false,
60-
outputReferences: false,
61+
outputReferences: (token, platformOptions) =>
62+
outputReferencesFilter(token, platformOptions) && outputReferencesTransformed(token, platformOptions),
6163
descriptions: false,
6264
queries: getCssSelectors(outputFile),
6365
...options?.options,
@@ -76,6 +78,8 @@ export const css: PlatformInitializer = (outputFile, prefix, buildPath, options)
7678
]),
7779
options: {
7880
showFileHeader: false,
81+
outputReferences: (token, platformOptions) =>
82+
outputReferencesFilter(token, platformOptions) && outputReferencesTransformed(token, platformOptions),
7983
descriptions: false,
8084
...options?.options,
8185
},
@@ -86,6 +90,8 @@ export const css: PlatformInitializer = (outputFile, prefix, buildPath, options)
8690
filter: token => isSource(token) && options?.themed !== true && token.$type === 'custom-viewportRange',
8791
options: {
8892
showFileHeader: false,
93+
outputReferences: (token, platformOptions) =>
94+
outputReferencesFilter(token, platformOptions) && outputReferencesTransformed(token, platformOptions),
8995
},
9096
},
9197
{
@@ -99,6 +105,8 @@ export const css: PlatformInitializer = (outputFile, prefix, buildPath, options)
99105
]),
100106
options: {
101107
descriptions: false,
108+
outputReferences: (token, platformOptions) =>
109+
outputReferencesFilter(token, platformOptions) && outputReferencesTransformed(token, platformOptions),
102110
showFileHeader: false,
103111
queries: [
104112
{

0 commit comments

Comments
 (0)