Skip to content

Commit 6e59707

Browse files
authoredFeb 20, 2024
Adding all color modes to figma export (#805)
* adding color modes * update schema validation
1 parent 2a9f484 commit 6e59707

File tree

9 files changed

+1813
-108
lines changed

9 files changed

+1813
-108
lines changed
 

‎.changeset/early-guests-sort.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/primitives': patch
3+
---
4+
5+
Adding exports for all colormodes for Figma

‎scripts/buildPlatforms/buildFigma.ts

+33-13
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,22 @@ export const buildFigma = (buildOptions: ConfigGeneratorOptions): void => {
1414
name: 'light',
1515
source: [`src/tokens/base/color/light/light.json5`],
1616
},
17+
{
18+
name: 'light-high-constrast',
19+
source: [`src/tokens/base/color/light/light.json5`, `src/tokens/base/color/light/light.high-contrast.json5`],
20+
},
1721
{
1822
name: 'dark',
1923
source: [`src/tokens/base/color/dark/dark.json5`],
2024
},
25+
{
26+
name: 'dark-high-constrast',
27+
source: [`src/tokens/base/color/dark/dark.json5`, `src/tokens/base/color/dark/dark.high-contrast.json5`],
28+
},
29+
{
30+
name: 'dark-dimmed',
31+
source: [`src/tokens/base/color/dark/dark.json5`, `src/tokens/base/color/dark/dark.dimmed.json5`],
32+
},
2133
]
2234

2335
for (const {name, source} of baseScales) {
@@ -30,18 +42,16 @@ export const buildFigma = (buildOptions: ConfigGeneratorOptions): void => {
3042
}
3143
//
3244
for (const {filename, source, include} of themes) {
33-
if (['light', 'dark'].includes(filename)) {
34-
// build functional scales
35-
PrimerStyleDictionary.extend({
36-
source,
37-
include,
38-
platforms: {
39-
figma: figma(`figma/themes/${filename}.json`, buildOptions.prefix, buildOptions.buildPath, {
40-
mode: filename,
41-
}),
42-
},
43-
}).buildAllPlatforms()
44-
}
45+
// build functional scales
46+
PrimerStyleDictionary.extend({
47+
source,
48+
include,
49+
platforms: {
50+
figma: figma(`figma/themes/${filename}.json`, buildOptions.prefix, buildOptions.buildPath, {
51+
mode: filename.replaceAll('-', ' '),
52+
}),
53+
},
54+
}).buildAllPlatforms()
4555
}
4656
/** -----------------------------------
4757
* Size tokens
@@ -109,7 +119,17 @@ export const buildFigma = (buildOptions: ConfigGeneratorOptions): void => {
109119

110120
// define the order of the modes
111121
// we inverse it to deal with the -1 of the indexOf if item is not found in the array: basically anything that is not in the list should come last
112-
const modeOrder = ['light', 'dark'].reverse()
122+
const modeOrder = [
123+
'light',
124+
'dark',
125+
'dark dimmed',
126+
'light high contrast',
127+
'dark high contrast',
128+
'light colorblind',
129+
'dark colorblind',
130+
'light tritanopia',
131+
'dark tritanopia',
132+
].reverse()
113133
// sort modes in the order defined above
114134
for (const collection in collections) {
115135
collections[collection].modes.sort((a, b) => modeOrder.indexOf(b) - modeOrder.indexOf(a))

‎src/schemas/collectionSchema.test.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import {collection, mode} from './collections'
33
describe('Schema: collection', () => {
44
const collections = collection([
55
'base/color/light',
6+
'base/color/light-high-contrast',
67
'base/color/dark',
78
'base/color/dark-dimmed',
9+
'base/color/dark-high-contrast',
810
'mode',
911
'pattern/mode',
1012
])
@@ -26,7 +28,17 @@ describe('Schema: collection', () => {
2628
})
2729

2830
describe('Schema: mode', () => {
29-
const modes = mode(['light', 'dark'])
31+
const modes = mode([
32+
'light',
33+
'dark',
34+
'dark dimmed',
35+
'light high contrast',
36+
'dark high contrast',
37+
'light colorblind',
38+
'dark colorblind',
39+
'light tritanopia',
40+
'dark tritanopia',
41+
])
3042

3143
it('passes on valid values', () => {
3244
expect(modes.safeParse('light').success).toStrictEqual(true)

‎src/schemas/collections.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import {schemaErrorMessage} from '../utilities/schemaErrorMessage'
44

55
type Collections =
66
| 'base/color/light'
7+
| 'base/color/light-high-contrast'
78
| 'base/color/dark'
89
| 'base/color/dark-dimmed'
10+
| 'base/color/dark-high-contrast'
911
| 'mode'
1012
| 'pattern/mode'
1113
| 'base/size'
@@ -24,7 +26,16 @@ export const collection = (collections: Collections[]) => {
2426
)
2527
}
2628

27-
type Modes = 'light' | 'dark'
29+
type Modes =
30+
| 'light'
31+
| 'dark'
32+
| 'dark dimmed'
33+
| 'light high contrast'
34+
| 'dark high contrast'
35+
| 'light colorblind'
36+
| 'dark colorblind'
37+
| 'light tritanopia'
38+
| 'dark tritanopia'
2839

2940
export const mode = (modes: Modes[]) => {
3041
return z.string().refine(

‎src/schemas/colorToken.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,24 @@ export const colorToken = baseToken
2424
'org.primer.figma': z.object({
2525
collection: collection([
2626
'base/color/light',
27+
'base/color/light-high-contrast',
2728
'base/color/dark',
2829
'base/color/dark-dimmed',
30+
'base/color/dark-high-contrast',
2931
'mode',
3032
'pattern/mode',
3133
]).optional(),
32-
mode: mode(['light', 'dark']).optional(),
34+
mode: mode([
35+
'light',
36+
'dark',
37+
'dark dimmed',
38+
'light high contrast',
39+
'dark high contrast',
40+
'light colorblind',
41+
'dark colorblind',
42+
'light tritanopia',
43+
'dark tritanopia',
44+
]).optional(),
3345
scopes: scopes(['all', 'bgColor', 'fgColor', 'borderColor']).optional(),
3446
}),
3547
})

‎src/schemas/scopes.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {z} from 'zod'
22
import {joinFriendly} from '../utilities/joinFriendly'
33
import {schemaErrorMessage} from '../utilities/schemaErrorMessage'
44

5-
export type ValidScope = 'all' | 'bgColor' | 'fgColor' | 'borderColor' | 'size' | 'gap' | 'radius'
6-
const validScopes: ValidScope[] = ['all', 'bgColor', 'fgColor', 'borderColor', 'size', 'gap', 'radius']
5+
export type ValidScope = 'all' | 'bgColor' | 'fgColor' | 'borderColor' | 'size' | 'gap' | 'radius' | 'effectColor'
6+
const validScopes: ValidScope[] = ['all', 'bgColor', 'fgColor', 'borderColor', 'size', 'gap', 'radius', 'effectColor']
77

88
export const scopes = (scopeSubset?: ValidScope[]) => {
99
const scopeArray = scopeSubset ?? validScopes

0 commit comments

Comments
 (0)