Skip to content

Commit

Permalink
Figma type token scope (#965)
Browse files Browse the repository at this point in the history
* added scopes to zod and zod scope test

* implemeny figma type scoping

* adding type token scopes for figma
  • Loading branch information
lukasoppermann authored Jun 6, 2024
1 parent d553741 commit 43ddc91
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 48 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-clouds-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/primitives': patch
---

Adding scope to type tokens
13 changes: 12 additions & 1 deletion src/schemas/dimensionToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@ export const dimensionToken = baseToken
.object({
'org.primer.figma': z.object({
collection: collection(['base/size', 'functional/size', 'pattern/size', 'typography']),
scopes: scopes(['all', 'size', 'gap', 'radius', 'borderColor']),
scopes: scopes([
'all',
'size',
'gap',
'radius',
'borderColor',
'fontSize',
'letterSpacing',
'lineHeight',
'paragraphSpacing',
'paragraphIndent',
]),
}),
})
.optional(),
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/fontFamilyToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const fontFamilyToken = baseToken
.object({
'org.primer.figma': z.object({
collection: collection(['base/typography', 'typography']).optional(),
scopes: scopes(['all']).optional(),
scopes: scopes(['fontFamily']).optional(),
}),
})
.optional(),
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/fontWeightToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const fontWeightToken = baseToken
.object({
'org.primer.figma': z.object({
collection: collection(['base/typography', 'typography']).optional(),
scopes: scopes(['all']).optional(),
scopes: scopes(['fontWeight']).optional(),
}),
})
.optional(),
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/numberToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const numberToken = baseToken
'org.primer.figma': z
.object({
collection: collection(['typography']).optional(),
scopes: scopes(['all']).optional(),
scopes: scopes(['fontWeight', 'lineHeight']).optional(),
})
.optional(),
})
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/numberTokenSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Schema: numberToken', () => {
},
'org.primer.figma': {
collection: 'typography',
scopes: ['all'],
scopes: ['fontWeight'],
},
},
}
Expand Down
50 changes: 48 additions & 2 deletions src/schemas/scopeTokenSchema.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import type {ValidScope} from './scopes'
import {scopes} from './scopes'

const validScopes: ValidScope[] = ['all', 'bgColor', 'fgColor', 'borderColor', 'size', 'gap', 'radius']
const validScopes: ValidScope[] = [
'all',
'bgColor',
'fgColor',
'borderColor',
'size',
'gap',
'radius',
'effectColor',
'opacity',
'fontFamily',
'fontStyle',
'fontWeight',
'fontSize',
'lineHeight',
'letterSpacing',
'paragraphSpacing',
'paragraphIndent',
]
const scopeSchema = scopes(validScopes)

describe('Schema: scopes', () => {
Expand All @@ -13,8 +31,36 @@ describe('Schema: scopes', () => {
expect(scopeSchema.safeParse(['size']).success).toStrictEqual(true)
expect(scopeSchema.safeParse(['gap']).success).toStrictEqual(true)
expect(scopeSchema.safeParse(['radius']).success).toStrictEqual(true)
expect(scopeSchema.safeParse(['effectColor']).success).toStrictEqual(true)
expect(scopeSchema.safeParse(['opacity']).success).toStrictEqual(true)
expect(scopeSchema.safeParse(['fontFamily']).success).toStrictEqual(true)
expect(scopeSchema.safeParse(['fontStyle']).success).toStrictEqual(true)
expect(scopeSchema.safeParse(['fontWeight']).success).toStrictEqual(true)
expect(scopeSchema.safeParse(['fontSize']).success).toStrictEqual(true)
expect(scopeSchema.safeParse(['lineHeight']).success).toStrictEqual(true)
expect(scopeSchema.safeParse(['letterSpacing']).success).toStrictEqual(true)
expect(scopeSchema.safeParse(['paragraphSpacing']).success).toStrictEqual(true)
expect(scopeSchema.safeParse(['paragraphIndent']).success).toStrictEqual(true)
expect(
scopeSchema.safeParse(['all', 'bgColor', 'fgColor', 'borderColor', 'size', 'gap', 'radius']).success,
scopeSchema.safeParse([
'all',
'bgColor',
'fgColor',
'borderColor',
'size',
'gap',
'radius',
'effectColor',
'opacity',
'fontFamily',
'fontStyle',
'fontWeight',
'fontSize',
'lineHeight',
'letterSpacing',
'paragraphSpacing',
'paragraphIndent',
]).success,
).toStrictEqual(true)
expect(scopeSchema.safeParse([]).success).toStrictEqual(true)
})
Expand Down
39 changes: 37 additions & 2 deletions src/schemas/scopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,43 @@ import {z} from 'zod'
import {joinFriendly} from '../utilities/joinFriendly'
import {schemaErrorMessage} from '../utilities/schemaErrorMessage'

export type ValidScope = 'all' | 'bgColor' | 'fgColor' | 'borderColor' | 'size' | 'gap' | 'radius' | 'effectColor'
const validScopes: ValidScope[] = ['all', 'bgColor', 'fgColor', 'borderColor', 'size', 'gap', 'radius', 'effectColor']
export type ValidScope =
| 'all'
| 'bgColor'
| 'fgColor'
| 'borderColor'
| 'size'
| 'gap'
| 'radius'
| 'effectColor'
| 'opacity'
| 'fontFamily'
| 'fontStyle'
| 'fontWeight'
| 'fontSize'
| 'lineHeight'
| 'letterSpacing'
| 'paragraphSpacing'
| 'paragraphIndent'
const validScopes: ValidScope[] = [
'all',
'bgColor',
'fgColor',
'borderColor',
'size',
'gap',
'radius',
'effectColor',
'opacity',
'fontFamily',
'fontStyle',
'fontWeight',
'fontSize',
'lineHeight',
'letterSpacing',
'paragraphSpacing',
'paragraphIndent',
]

export const scopes = (scopeSubset?: ValidScope[]) => {
const scopeArray = scopeSubset ?? validScopes
Expand Down
8 changes: 4 additions & 4 deletions src/tokens/base/typography/typography.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"$extensions": {
"org.primer.figma": {
"collection": "base/typography",
"scopes": ["all"]
"scopes": ["fontWeight"]
}
}
},
Expand All @@ -18,7 +18,7 @@
"$extensions": {
"org.primer.figma": {
"collection": "base/typography",
"scopes": ["all"]
"scopes": ["fontWeight"]
}
}
},
Expand All @@ -28,7 +28,7 @@
"$extensions": {
"org.primer.figma": {
"collection": "base/typography",
"scopes": ["all"]
"scopes": ["fontWeight"]
}
}
},
Expand All @@ -38,7 +38,7 @@
"$extensions": {
"org.primer.figma": {
"collection": "base/typography",
"scopes": ["all"]
"scopes": ["fontWeight"]
}
}
}
Expand Down
Loading

0 comments on commit 43ddc91

Please sign in to comment.