Skip to content

Commit 998fc24

Browse files
fix-floatToPixel (#911)
1 parent e7d3c6c commit 998fc24

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

.changeset/tidy-points-visit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/primitives': patch
3+
---
4+
5+
Round pixel value in floatToPixel

src/transformers/floatToPixel.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,24 @@ describe('Transformer: floatToPixel', () => {
1212
},
1313
},
1414
}),
15+
getMockToken({
16+
value: 1.342,
17+
$extensions: {
18+
'org.primer.data': {
19+
fontSize: 16,
20+
},
21+
},
22+
}),
23+
getMockToken({
24+
value: 1.548,
25+
$extensions: {
26+
'org.primer.data': {
27+
fontSize: 16,
28+
},
29+
},
30+
}),
1531
]
16-
const expectedOutput = ['24px']
32+
const expectedOutput = ['24px', '21px', '25px']
1733
expect(input.map(item => floatToPixel.transformer(item, {}))).toStrictEqual(expectedOutput)
1834
})
1935

src/transformers/floatToPixel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const convertFloatToPixel = (token: StyleDictionary.TransformedToken) =>
1717
// convert value
1818
const convertedValue = token.$extensions?.['org.primer.data']?.fontSize * token.value
1919
// return converted value
20-
return convertedValue === 0 ? 0 : `${convertedValue}px`
20+
return convertedValue === 0 ? 0 : `${Math.round(convertedValue)}px`
2121
}
2222
/**
2323
* @description converts a float value to a pixel value based on the provided fontSize on the tokersn extension

0 commit comments

Comments
 (0)