Skip to content

Commit

Permalink
feat: add yaTypography/rem transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
petrukhin committed Jun 26, 2020
1 parent 03dec89 commit 90e6dd0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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

0 comments on commit 90e6dd0

Please sign in to comment.