Skip to content

Commit

Permalink
add typo to figma build
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann committed Apr 17, 2024
1 parent 47bb2bf commit 6e9bc8a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 2 deletions.
12 changes: 12 additions & 0 deletions scripts/buildFigma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ const buildFigma = (buildOptions: ConfigGeneratorOptions): void => {
},
}).buildAllPlatforms()

/** -----------------------------------
* Typography
* ----------------------------------- */
//
PrimerStyleDictionary.extend({
source: ['src/tokens/base/typography/typography.json', 'src/tokens/functional/typography/typography.json'],
include: [],
platforms: {
figma: figma(`figma/typography/typography.json`, buildOptions.prefix, buildOptions.buildPath),
},
}).buildAllPlatforms()

/** -----------------------------------
* Shadow tokens
* ----------------------------------- */
Expand Down
2 changes: 2 additions & 0 deletions src/formats/jsonFigma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const getFigmaType = (type: string): string => {
const validTypes = {
color: 'COLOR',
dimension: 'FLOAT',
fontWeight: 'FLOAT',
fontFamily: 'STRING',
}
if (type in validTypes) return validTypes[type as keyof typeof validTypes]
throw new Error(`Invalid type: ${type}`)
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/figma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {PlatformInitializer} from '../types/PlatformInitializer'
import {isSource} from '../filters'

const validFigmaToken = (token: StyleDictionary.TransformedToken) => {
const validTypes = ['color', 'dimension', 'shadow']
const validTypes = ['color', 'dimension', 'shadow', 'fontWeight', 'fontFamily']
// is a siource token, not an included one
if (!isSource(token)) return false
// has a collection attribute
Expand Down
2 changes: 2 additions & 0 deletions src/schemas/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ type Collections =
| 'base/color/dark'
| 'base/color/dark-dimmed'
| 'base/color/dark-high-contrast'
| 'base/typography'
| 'mode'
| 'pattern/mode'
| 'base/size'
| 'functional/size'
| 'pattern/size'
| 'typography'

export const collection = (collections: Collections[]) => {
return z.string().refine(
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/dimensionToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const dimensionToken = baseToken
$extensions: z
.object({
'org.primer.figma': z.object({
collection: collection(['base/size', 'functional/size', 'pattern/size']),
collection: collection(['base/size', 'functional/size', 'pattern/size', 'typography']),
scopes: scopes(['all', 'size', 'gap', 'radius', 'borderColor']),
}),
})
Expand Down
10 changes: 10 additions & 0 deletions src/schemas/fontFamilyToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ import {z} from 'zod'
import {referenceValue} from './referenceValue'
import {baseToken} from './baseToken'
import {tokenType} from './tokenType'
import {collection} from './collections'
import {scopes} from './scopes'

export const fontFamilyToken = baseToken
.extend({
$value: z.union([z.string(), referenceValue]),
$type: tokenType('fontFamily'),
$extensions: z
.object({
'org.primer.figma': z.object({
collection: collection(['base/typography', 'typography']).optional(),
scopes: scopes(['all']).optional(),
}),
})
.optional(),
})
.strict()
10 changes: 10 additions & 0 deletions src/schemas/fontWeightToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ import {fontWeightValue} from './fontWeightValue'
import {referenceValue} from './referenceValue'
import {baseToken} from './baseToken'
import {tokenType} from './tokenType'
import {collection} from './collections'
import {scopes} from './scopes'

export const fontWeightToken = baseToken
.extend({
$type: tokenType('fontWeight'),
$value: z.union([fontWeightValue, referenceValue]),
$extensions: z
.object({
'org.primer.figma': z.object({
collection: collection(['base/typography', 'typography']).optional(),
scopes: scopes(['all']).optional(),
}),
})
.optional(),
})
.strict()

0 comments on commit 6e9bc8a

Please sign in to comment.