UNPKG

1.02 kBJavaScriptView Raw
1/* @flow */
2
3// Copied from https://github.com/facebook/react/blob/
4// 102cd291899f9942a76c40a0e78920a6fe544dc1/
5// src/renderers/dom/shared/CSSProperty.js
6const 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 // SVG-related properties
32 fillOpacity: true,
33 stopOpacity: true,
34 strokeDashoffset: true,
35 strokeOpacity: true,
36 strokeWidth: true,
37};
38
39export 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}