@primer/primitives 7.17.0-rc.a96c5b69 → 7.17.0-rc.ad176f0c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
shadowToCss,
|
|
24
24
|
typographyToCss,
|
|
25
25
|
dimensionToRemPxArray,
|
|
26
|
+
floatToPixel,
|
|
26
27
|
} from './transformers'
|
|
27
28
|
import {
|
|
28
29
|
javascriptCommonJs,
|
|
@@ -132,6 +133,11 @@ StyleDictionary.registerTransform({
|
|
|
132
133
|
...colorToHex,
|
|
133
134
|
})
|
|
134
135
|
|
|
136
|
+
StyleDictionary.registerTransform({
|
|
137
|
+
name: 'float/pixel',
|
|
138
|
+
...floatToPixel,
|
|
139
|
+
})
|
|
140
|
+
|
|
135
141
|
StyleDictionary.registerTransform({
|
|
136
142
|
name: 'dimension/rem',
|
|
137
143
|
...dimensionToRem,
|
package/src/filters/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export {isDeprecated} from './isDeprecated'
|
|
|
7
7
|
export {isFromFile} from './isFromFile'
|
|
8
8
|
export {isFontFamily} from './isFontFamily'
|
|
9
9
|
export {isFontWeight} from './isFontWeight'
|
|
10
|
+
export {isNumber} from './isNumber'
|
|
10
11
|
export {isShadow} from './isShadow'
|
|
11
12
|
export {isSource} from './isSource'
|
|
12
13
|
export {isTypography} from './isTypography'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type StyleDictionary from 'style-dictionary'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description Checks if token type is a number
|
|
5
|
+
* @param token [StyleDictionary.TransformedToken](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts)
|
|
6
|
+
* @returns boolean
|
|
7
|
+
*/
|
|
8
|
+
export const isNumber = (token: StyleDictionary.TransformedToken): boolean => token.$type === 'number'
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type StyleDictionary from 'style-dictionary'
|
|
2
|
+
import {isNumber} from '../filters'
|
|
3
|
+
/**
|
|
4
|
+
* takes a value and returns it if its a px string if it is a float and the token has a fontSize value in extensions['org.primer.data']
|
|
5
|
+
* @param value
|
|
6
|
+
* @returns string
|
|
7
|
+
*/
|
|
8
|
+
export const convertFloatToPixel = (token: StyleDictionary.TransformedToken) => {
|
|
9
|
+
// short circut if value is not a number
|
|
10
|
+
if (
|
|
11
|
+
typeof token.value !== 'number' ||
|
|
12
|
+
!token.$extensions?.['org.primer.data']?.fontSize ||
|
|
13
|
+
typeof token.$extensions?.['org.primer.data']?.fontSize !== 'number'
|
|
14
|
+
) {
|
|
15
|
+
return token.value
|
|
16
|
+
}
|
|
17
|
+
// convert value
|
|
18
|
+
const convertedValue = token.$extensions?.['org.primer.data']?.fontSize * token.value
|
|
19
|
+
// return converted value
|
|
20
|
+
return `${convertedValue}px`
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @description converts a float value to a pixel value based on the provided fontSize on the tokersn extension
|
|
24
|
+
* @type value transformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
|
|
25
|
+
* @matcher matches all tokens of $type `isNumber`
|
|
26
|
+
* @transformer returns a pixel string
|
|
27
|
+
*/
|
|
28
|
+
export const floatToPixel: StyleDictionary.Transform = {
|
|
29
|
+
type: `value`,
|
|
30
|
+
transitive: true,
|
|
31
|
+
matcher: isNumber,
|
|
32
|
+
transformer: (token: StyleDictionary.TransformedToken): string => convertFloatToPixel(token),
|
|
33
|
+
}
|
|
@@ -4,6 +4,7 @@ export {colorToHexAlpha} from './colorToHexAlpha'
|
|
|
4
4
|
export {colorToHexMix} from './colorToHexMix'
|
|
5
5
|
export {colorToRgbAlpha} from './colorToRgbAlpha'
|
|
6
6
|
export {colorToRgbaFloat} from './colorToRgbaFloat'
|
|
7
|
+
export {floatToPixel} from './floatToPixel'
|
|
7
8
|
export {dimensionToRem} from './dimensionToRem'
|
|
8
9
|
export {dimensionToRemPxArray} from './dimensionToRemPxArray'
|
|
9
10
|
export {dimensionToPixelUnitless} from './dimensionToPixelUnitless'
|