Skip to content

Commit 4f52045

Browse files
fix: ensure Figma base scale output includes all tokens for override themes (#1355)
* fix: ensure Figma base scale output includes all tokens for override themes Override themes (dark-dimmed, dark-high-contrast, light-high-contrast) inherit tokens from their parent theme. Previously, inherited tokens retained the parent's Figma collection name (e.g. base/color/dark instead of base/color/dark-dimmed), causing them to be missing from the override theme's collection in Figma output. Add collectionOverride support to the figmaAttributes transformer and pass collection mappings for each override theme in buildFigma.ts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add changeset Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9558473 commit 4f52045

File tree

5 files changed

+117
-6
lines changed

5 files changed

+117
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/primitives": patch
3+
---
4+
5+
Fix Figma base scale output for override themes (dark-dimmed, dark-high-contrast, light-high-contrast) to include all tokens. Previously, inherited tokens (e.g. neutral, black, transparent) retained the parent theme's collection name and were missing from the override theme's Figma collection.

package-lock.json

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

scripts/buildFigma.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const buildFigma = async (buildOptions: ConfigGeneratorOptions): Promise<void> =
2626
`src/tokens/base/color/light/display-light.json5`,
2727
`src/tokens/base/color/light/light.high-contrast.json5`,
2828
],
29+
collectionOverride: {'base/color/light': 'base/color/light-high-contrast'},
2930
},
3031
{
3132
name: 'dark',
@@ -40,6 +41,7 @@ const buildFigma = async (buildOptions: ConfigGeneratorOptions): Promise<void> =
4041
`src/tokens/base/color/dark/display-dark.json5`,
4142
`src/tokens/base/color/dark/dark.high-contrast.json5`,
4243
],
44+
collectionOverride: {'base/color/dark': 'base/color/dark-high-contrast'},
4345
},
4446
{
4547
theme: 'dark-dimmed',
@@ -49,14 +51,17 @@ const buildFigma = async (buildOptions: ConfigGeneratorOptions): Promise<void> =
4951
`src/tokens/base/color/dark/display-dark.json5`,
5052
`src/tokens/base/color/dark/dark.dimmed.json5`,
5153
],
54+
collectionOverride: {'base/color/dark': 'base/color/dark-dimmed'},
5255
},
5356
]
5457

55-
for (const {name, source} of baseScales) {
58+
for (const {name, source, collectionOverride} of baseScales) {
5659
const extended = await PrimerStyleDictionary.extend({
5760
source,
5861
platforms: {
59-
figma: figma(`figma/scales/${name}.json`, buildOptions.prefix, buildOptions.buildPath),
62+
figma: figma(`figma/scales/${name}.json`, buildOptions.prefix, buildOptions.buildPath, {
63+
collectionOverride,
64+
}),
6065
},
6166
})
6267
// build
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import {figmaAttributes} from './figmaAttributes.js'
2+
import type {TransformedToken, PlatformConfig} from 'style-dictionary/types'
3+
4+
describe('figmaAttributes', () => {
5+
const baseToken = {
6+
$extensions: {
7+
'org.primer.figma': {
8+
collection: 'base/color/dark',
9+
scopes: ['bgColor'],
10+
group: undefined,
11+
codeSyntax: undefined,
12+
},
13+
},
14+
} as unknown as TransformedToken
15+
16+
it('returns collection from token extensions', () => {
17+
const result = figmaAttributes.transform(baseToken, {} as PlatformConfig)
18+
expect(result).toMatchObject({
19+
collection: 'base/color/dark',
20+
group: 'base/color/dark',
21+
})
22+
})
23+
24+
it('applies collectionOverride when collection matches', () => {
25+
const platform = {
26+
options: {
27+
collectionOverride: {'base/color/dark': 'base/color/dark-dimmed'},
28+
},
29+
} as unknown as PlatformConfig
30+
31+
const result = figmaAttributes.transform(baseToken, platform)
32+
expect(result).toMatchObject({
33+
collection: 'base/color/dark-dimmed',
34+
group: 'base/color/dark-dimmed',
35+
})
36+
})
37+
38+
it('does not apply collectionOverride when collection does not match', () => {
39+
const token = {
40+
$extensions: {
41+
'org.primer.figma': {
42+
collection: 'base/color/dark-dimmed',
43+
scopes: ['bgColor'],
44+
},
45+
},
46+
} as unknown as TransformedToken
47+
48+
const platform = {
49+
options: {
50+
collectionOverride: {'base/color/dark': 'base/color/dark-dimmed'},
51+
},
52+
} as unknown as PlatformConfig
53+
54+
const result = figmaAttributes.transform(token, platform)
55+
expect(result).toMatchObject({
56+
collection: 'base/color/dark-dimmed',
57+
group: 'base/color/dark-dimmed',
58+
})
59+
})
60+
61+
it('preserves explicit group when set', () => {
62+
const token = {
63+
$extensions: {
64+
'org.primer.figma': {
65+
collection: 'base/color/dark',
66+
group: 'custom-group',
67+
scopes: ['bgColor'],
68+
},
69+
},
70+
} as unknown as TransformedToken
71+
72+
const platform = {
73+
options: {
74+
collectionOverride: {'base/color/dark': 'base/color/dark-dimmed'},
75+
},
76+
} as unknown as PlatformConfig
77+
78+
const result = figmaAttributes.transform(token, platform)
79+
expect(result).toMatchObject({
80+
collection: 'base/color/dark-dimmed',
81+
group: 'custom-group',
82+
})
83+
})
84+
85+
it('uses theme for mode when available', () => {
86+
const platform = {
87+
options: {
88+
theme: 'dark dimmed',
89+
},
90+
} as unknown as PlatformConfig
91+
92+
const result = figmaAttributes.transform(baseToken, platform)
93+
expect(result).toMatchObject({
94+
mode: 'dark dimmed',
95+
})
96+
})
97+
})

src/transformers/figmaAttributes.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,14 @@ export const figmaAttributes: Transform = {
7171
transform: (token: TransformedToken, platform: PlatformConfig = {}) => {
7272
const {modeOverride, collection, scopes, group, codeSyntax} = token.$extensions?.['org.primer.figma'] || {}
7373

74+
const collectionOverride = platform.options?.collectionOverride as Record<string, string> | undefined
75+
const resolvedCollection =
76+
collectionOverride && collection && collection in collectionOverride ? collectionOverride[collection] : collection
77+
7478
return {
7579
mode: asArray(platform.options?.theme)[0] || modeOverride || 'default',
76-
collection,
77-
group: group || collection,
80+
collection: resolvedCollection,
81+
group: group || resolvedCollection,
7882
scopes: getScopes(scopes),
7983
codeSyntax,
8084
}

0 commit comments

Comments
 (0)