1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | const isUnitlessNumber = {
|
7 | animationIterationCount: true,
|
8 | boxFlex: true,
|
9 | boxFlexGroup: true,
|
10 | boxOrdinalGroup: true,
|
11 | columnCount: true,
|
12 | flex: true,
|
13 | flexGrow: true,
|
14 | flexPositive: true,
|
15 | flexShrink: true,
|
16 | flexNegative: true,
|
17 | flexOrder: true,
|
18 | gridRow: true,
|
19 | gridColumn: true,
|
20 | fontWeight: true,
|
21 | lineClamp: true,
|
22 | lineHeight: true,
|
23 | opacity: true,
|
24 | order: true,
|
25 | orphans: true,
|
26 | tabSize: true,
|
27 | widows: true,
|
28 | zIndex: true,
|
29 | zoom: true,
|
30 |
|
31 |
|
32 | fillOpacity: true,
|
33 | stopOpacity: true,
|
34 | strokeDashoffset: true,
|
35 | strokeOpacity: true,
|
36 | strokeWidth: true
|
37 | };
|
38 |
|
39 | export default function appendPxIfNeeded(
|
40 | propertyName: string,
|
41 | value: any
|
42 | ): string {
|
43 | const needsPxSuffix = !isUnitlessNumber[propertyName] &&
|
44 | typeof value === 'number' &&
|
45 | value !== 0;
|
46 | return needsPxSuffix ? value + 'px' : value;
|
47 | }
|