Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/core/build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './yaml-interop'
import StyleDictionaryApi from 'style-dictionary'
import StyleDictionaryApi, { Property } from 'style-dictionary'
import cssColorFn from 'css-color-function'
import { resolve } from 'path'
import { readFileSync, writeFileSync } from 'fs-extra'
Expand Down Expand Up @@ -34,6 +34,28 @@ StyleDictionaryApi.registerTransform({
},
})

const isTypographyCategory = (prop: Property) => {
const category = prop.attributes.category
return category === 'fontSize' || category === 'lineHeight'
}

StyleDictionaryApi.registerTransform({
name: 'yaTypography/rem',
type: 'value',
matcher: isTypographyCategory,
transformer: (prop) => {
const {
value,
} = prop

if (typeof value === 'number') {
return `${value}rem`
}

return value
},
})

StyleDictionaryApi.registerFilter({
name: 'whitepaper/color',
matcher: (prop) => {
Expand Down
3 changes: 2 additions & 1 deletion src/modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ declare module 'style-dictionary' {
export type Property = {
value: string | number
group: string
name: string
name: string,
attributes: any
}

export type Platform = {
Expand Down