Skip to content

Commit 33d8505

Browse files
fix(tokens): NO-JIRA output line-height as unitless instead of percentages (#1040)
1 parent 864fd24 commit 33d8505

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

packages/dialtone-tokens/build-sd-transforms-layered.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ StyleDictionary.registerAction({
120120

121121
StyleDictionary.registerTransformGroup({
122122
name: 'custom/css/tokens-studio',
123-
transforms: [...getTransforms({ platform: 'css' }), 'name/kebab', 'dt/size/pxToRem', 'dt/space/pxToRem']
123+
transforms: [...getTransforms({ platform: 'css' }), 'name/kebab', 'dt/size/pxToRem', 'dt/space/pxToRem', 'dt/lineHeight/percentToDecimal']
124124
.filter(transform => !['name/camel', 'ts/size/px', 'ts/typography/css/fontFamily'].includes(transform)),
125125
});
126126

packages/dialtone-tokens/build-sd-transforms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ StyleDictionary.registerAction({
2828

2929
StyleDictionary.registerTransformGroup({
3030
name: 'custom/css/tokens-studio',
31-
transforms: [...getTransforms({ platform: 'css' }), 'name/kebab', 'dt/size/pxToRem', 'dt/space/pxToRem'].filter(transform => !['name/camel', 'ts/size/px', 'ts/typography/css/fontFamily'].includes(transform)),
31+
transforms: [...getTransforms({ platform: 'css' }), 'name/kebab', 'dt/size/pxToRem', 'dt/space/pxToRem', 'dt/lineHeight/percentToDecimal'].filter(transform => !['name/camel', 'ts/size/px', 'ts/typography/css/fontFamily'].includes(transform)),
3232
});
3333

3434
export async function run () {

packages/dialtone-tokens/dialtone-transforms.js

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function registerDialtoneTransforms (styleDictionary) {
7474
transform: (token) => {
7575
// replace unmathable characters with empty string
7676
const mathString = token.value.replace(/dp|sp|em|px|%/g, '');
77-
// eslint-disable-next-line no-eval
77+
7878
const result = eval(mathString).toFixed(2);
7979
return `${result}dp`;
8080
},
@@ -167,6 +167,8 @@ export function registerDialtoneTransforms (styleDictionary) {
167167
type: 'value',
168168
transitive: true,
169169
filter: function (token) {
170+
// Exclude lineHeight dimension tokens - they're handled by lineHeight transform
171+
if (token.type === 'dimension' && token.path?.includes('lineHeight')) return false;
170172
return [...SPACING_IDENTIFIERS, ...SIZE_IDENTIFIERS].includes(token.type) &&
171173
// The fontSize token in typography tokens is a 'dimension' type for some reason,
172174
// so have this special case to exclude it from this transform.
@@ -219,7 +221,7 @@ export function registerDialtoneTransforms (styleDictionary) {
219221
if (token.value.includes('.sp')) unit = 'sp';
220222
if (token.value.includes('.em')) unit = 'em';
221223
const mathString = token.value.replace(/\.dp|\.sp|\.em|px|%/g, '');
222-
// eslint-disable-next-line no-eval
224+
223225
const result = eval(mathString);
224226
return `${result}.${unit}`;
225227
},
@@ -229,7 +231,9 @@ export function registerDialtoneTransforms (styleDictionary) {
229231
name: 'dt/android/compose/lineHeight/percentToDecimal',
230232
type: 'value',
231233
filter: function (token) {
232-
return LINE_HEIGHT_IDENTIFIERS.includes(token.type);
234+
// Match by type (legacy tokens) or path (DTCG-compliant tokens with type: dimension)
235+
return LINE_HEIGHT_IDENTIFIERS.includes(token.type) ||
236+
(token.type === 'dimension' && token.path?.includes('lineHeight'));
233237
},
234238
transform: (token) => {
235239
const floatVal = parseFloat(token.value);
@@ -313,6 +317,8 @@ export function registerDialtoneTransforms (styleDictionary) {
313317
name: 'dt/ios/size/pxToCGFloat',
314318
type: 'value',
315319
filter: function (token) {
320+
// Exclude lineHeight dimension tokens - they're handled by dt/ios/lineHeight/percentToDecimal
321+
if (token.type === 'dimension' && token.path?.includes('lineHeight')) return false;
316322
return [...SPACING_IDENTIFIERS, ...SIZE_IDENTIFIERS].includes(token.type);
317323
},
318324
transform: (token) => {
@@ -330,7 +336,11 @@ export function registerDialtoneTransforms (styleDictionary) {
330336
name: 'dt/ios/lineHeight/percentToDecimal',
331337
type: 'value',
332338
filter: function (token) {
333-
return ['opacity', ...LINE_HEIGHT_IDENTIFIERS].includes(token.type);
339+
// Skip if already transformed to CGFloat
340+
if (typeof token.value === 'string' && token.value.includes('CGFloat')) return false;
341+
// Match by type (legacy tokens) or path (DTCG-compliant tokens with type: dimension)
342+
return ['opacity', ...LINE_HEIGHT_IDENTIFIERS].includes(token.type) ||
343+
(token.type === 'dimension' && token.path?.includes('lineHeight'));
334344
},
335345
transform: (token) => {
336346
const floatVal = parseFloat(token.value);
@@ -347,7 +357,9 @@ export function registerDialtoneTransforms (styleDictionary) {
347357
name: 'dt/lineHeight/percentToDecimal',
348358
type: 'value',
349359
filter: function (token) {
350-
return LINE_HEIGHT_IDENTIFIERS.includes(token.type);
360+
// Match by type (legacy tokens) or path (DTCG-compliant tokens with type: dimension)
361+
return LINE_HEIGHT_IDENTIFIERS.includes(token.type) ||
362+
(token.type === 'dimension' && token.path?.includes('lineHeight'));
351363
},
352364
transform: (token) => {
353365
const floatVal = parseFloat(token.value);
@@ -380,24 +392,4 @@ export function registerDialtoneTransforms (styleDictionary) {
380392
},
381393
});
382394

383-
styleDictionary.registerTransform({
384-
name: 'dt/lineHeight/percentToDecimal',
385-
type: 'value',
386-
filter: function (token) {
387-
return LINE_HEIGHT_IDENTIFIERS.includes(token.type);
388-
},
389-
transform: (token) => {
390-
const floatVal = parseFloat(token.value);
391-
392-
if (isNaN(floatVal)) {
393-
throwSizeError(token.path, token.value, '%');
394-
}
395-
396-
if (floatVal === 0) {
397-
return '0';
398-
}
399-
400-
return `${floatVal / 100}`;
401-
},
402-
});
403395
}

0 commit comments

Comments
 (0)