Skip to content

Commit

Permalink
fix(designtokens): fix design token transformers option
Browse files Browse the repository at this point in the history
  • Loading branch information
masoudmanson committed Nov 7, 2024
1 parent f767201 commit dbbcd97
Show file tree
Hide file tree
Showing 2 changed files with 231 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ export function tailwindFormatter({ dictionary, options }) {
const { sds } = dictionary.tokens;
const tailwindConfig = {
fontFamily: transformDictionary(sds.font["font-family"], null, options),
...transformFonts(sds.font, ["body", "caps", "header", "tabular", "code"]),
...transformIconSizes(sds.iconSize),
...transformFonts(
sds.font,
["body", "caps", "header", "tabular", "code"],
options
),
...transformIconSizes(sds.iconSize, options),
borderRadius: transformDictionary(sds.corner, null, options),
boxShadow: transformDictionary(sds["drop-shadow"], null, options),
colors: transformColor(sds.color),
Expand Down Expand Up @@ -70,19 +74,19 @@ function transformColor(tokens) {
return colors;
}

function transformIconSizes(tokens) {
function transformIconSizes(tokens, options = {}) {
const width = {};
const height = {};

for (const [iconSize, token] of Object.entries(tokens)) {
width[getName(`icon-${iconSize}`)] = token.height.value;
height[getName(`icon-${iconSize}`)] = token.width.value;
width[getName(`icon-${iconSize}`, options)] = token.height.value;
height[getName(`icon-${iconSize}`, options)] = token.width.value;
}

return { height, width };
}

function transformFonts(tokens, keys) {
function transformFonts(tokens, keys, options = {}) {
const fontSize = { narrow: {}, wide: {} };
const lineHeight = { narrow: {}, wide: {} };
const letterSpacing = { narrow: {}, wide: {} };
Expand Down Expand Up @@ -122,7 +126,7 @@ function transformFonts(tokens, keys) {
for (const key of keys) {
for (const [size, fonts] of Object.entries(tokens[key])) {
for (const [, fontValue] of Object.entries(fonts)) {
makeFontValue(fontValue, getName([key, size]));
makeFontValue(fontValue, getName([key, size], options));
}
}
}
Expand Down
Loading

0 comments on commit dbbcd97

Please sign in to comment.