1 |
|
2 |
|
3 | import type {PluginConfig, PluginResult} from './index';
|
4 |
|
5 | let checkProps = (() => {}: any);
|
6 |
|
7 | if (process.env.NODE_ENV !== 'production') {
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | const shorthandPropertyExpansions = {
|
13 | background: [
|
14 | 'backgroundAttachment',
|
15 | 'backgroundBlendMode',
|
16 | 'backgroundClip',
|
17 | 'backgroundColor',
|
18 | 'backgroundImage',
|
19 | 'backgroundOrigin',
|
20 | 'backgroundPosition',
|
21 | 'backgroundPositionX',
|
22 | 'backgroundPositionY',
|
23 | 'backgroundRepeat',
|
24 | 'backgroundRepeatX',
|
25 | 'backgroundRepeatY',
|
26 | 'backgroundSize',
|
27 | ],
|
28 | border: [
|
29 | 'borderBottom',
|
30 | 'borderBottomColor',
|
31 | 'borderBottomStyle',
|
32 | 'borderBottomWidth',
|
33 | 'borderColor',
|
34 | 'borderLeft',
|
35 | 'borderLeftColor',
|
36 | 'borderLeftStyle',
|
37 | 'borderLeftWidth',
|
38 | 'borderRight',
|
39 | 'borderRightColor',
|
40 | 'borderRightStyle',
|
41 | 'borderRightWidth',
|
42 | 'borderStyle',
|
43 | 'borderTop',
|
44 | 'borderTopColor',
|
45 | 'borderTopStyle',
|
46 | 'borderTopWidth',
|
47 | 'borderWidth',
|
48 | ],
|
49 | borderImage: [
|
50 | 'borderImageOutset',
|
51 | 'borderImageRepeat',
|
52 | 'borderImageSlice',
|
53 | 'borderImageSource',
|
54 | 'borderImageWidth',
|
55 | ],
|
56 | borderRadius: [
|
57 | 'borderBottomLeftRadius',
|
58 | 'borderBottomRightRadius',
|
59 | 'borderTopLeftRadius',
|
60 | 'borderTopRightRadius',
|
61 | ],
|
62 | font: [
|
63 | 'fontFamily',
|
64 | 'fontKerning',
|
65 | 'fontSize',
|
66 | 'fontStretch',
|
67 | 'fontStyle',
|
68 | 'fontVariant',
|
69 | 'fontVariantLigatures',
|
70 | 'fontWeight',
|
71 | 'lineHeight',
|
72 | ],
|
73 | listStyle: ['listStyleImage', 'listStylePosition', 'listStyleType'],
|
74 | margin: ['marginBottom', 'marginLeft', 'marginRight', 'marginTop'],
|
75 | padding: ['paddingBottom', 'paddingLeft', 'paddingRight', 'paddingTop'],
|
76 | transition: [
|
77 | 'transitionDelay',
|
78 | 'transitionDuration',
|
79 | 'transitionProperty',
|
80 | 'transitionTimingFunction',
|
81 | ],
|
82 | };
|
83 |
|
84 | checkProps = function(config: PluginConfig): PluginResult {
|
85 | const {componentName, style} = config;
|
86 | if (typeof style !== 'object' || !style) {
|
87 | return;
|
88 | }
|
89 |
|
90 | const styleKeys = Object.keys(style);
|
91 | styleKeys.forEach(styleKey => {
|
92 | if (
|
93 | Array.isArray(shorthandPropertyExpansions[styleKey]) &&
|
94 | shorthandPropertyExpansions[styleKey].some(
|
95 | sp => styleKeys.indexOf(sp) !== -1,
|
96 | )
|
97 | ) {
|
98 | if (process.env.NODE_ENV !== 'production') {
|
99 |
|
100 | console.warn(
|
101 | 'Radium: property "' + styleKey + '" in style object',
|
102 | style,
|
103 | ': do not mix longhand and ' +
|
104 | 'shorthand properties in the same style object. Check the render ' +
|
105 | 'method of ' +
|
106 | componentName +
|
107 | '.',
|
108 | 'See https://github.com/FormidableLabs/radium/issues/95 for more ' +
|
109 | 'information.',
|
110 | );
|
111 |
|
112 | }
|
113 | }
|
114 | });
|
115 |
|
116 | styleKeys.forEach(k => checkProps({...config, style: style[k]}));
|
117 | return;
|
118 | };
|
119 | }
|
120 |
|
121 | export default checkProps;
|