@itcase/ui 1.3.18 → 1.3.19
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/dist/cjs/hooks/useStyles.js +41 -18
- package/dist/hooks/useStyles.js +41 -18
- package/package.json +1 -1
|
@@ -109,22 +109,39 @@ function useStyles(props) {
|
|
|
109
109
|
}
|
|
110
110
|
if (value) {
|
|
111
111
|
// Check not digit symbols. Chars means some unit ("px", "em", "rem" or custom "m")
|
|
112
|
-
const
|
|
112
|
+
const isValueHasUnit = /\D/.test(value);
|
|
113
113
|
// If value has some unit
|
|
114
|
-
if (
|
|
114
|
+
if (isValueHasUnit) {
|
|
115
115
|
// Check value on our custom "m"(module) unit
|
|
116
|
-
|
|
116
|
+
/** Pattern for:
|
|
117
|
+
* 1m
|
|
118
|
+
* 1.5m
|
|
119
|
+
* 1m 1m 1.5m
|
|
120
|
+
* 0 0 1m 1m
|
|
121
|
+
*/
|
|
122
|
+
const isValueHasModuleUnit = /\d+\.?\d*m\s?(?![a-zA-Z]+)/.test(value);
|
|
117
123
|
// If value has module unit
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
if (isValueHasModuleUnit) {
|
|
125
|
+
/** Order for shorthand properties:
|
|
126
|
+
* top
|
|
127
|
+
* right
|
|
128
|
+
* bottom
|
|
129
|
+
* left
|
|
130
|
+
* or:
|
|
131
|
+
* top
|
|
132
|
+
* right and left
|
|
133
|
+
* bottom
|
|
134
|
+
* or:
|
|
135
|
+
* top and bottom
|
|
136
|
+
* right and left
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
const valuePxPartsList = value.split(' ').map(valuePart => {
|
|
140
|
+
const valueModule = valuePart.replace(/[a-z]/gi, '');
|
|
141
|
+
const valuePx = parseFloat(valueModule) * 8;
|
|
142
|
+
return `${valuePx}px`;
|
|
143
|
+
}, []);
|
|
144
|
+
value = valuePxPartsList.join(' ');
|
|
128
145
|
}
|
|
129
146
|
} else {
|
|
130
147
|
// Some properties doesn't have any units
|
|
@@ -135,15 +152,21 @@ function useStyles(props) {
|
|
|
135
152
|
}
|
|
136
153
|
}
|
|
137
154
|
if (styleAttributeKey.includes('Horizontal')) {
|
|
138
|
-
const keyLeft = styleAttributeKey.replace('Horizontal', 'Left');
|
|
139
155
|
const keyRight = styleAttributeKey.replace('Horizontal', 'Right');
|
|
140
|
-
|
|
141
|
-
|
|
156
|
+
const keyLeft = styleAttributeKey.replace('Horizontal', 'Left');
|
|
157
|
+
const valuePartsList = value.split(' ');
|
|
158
|
+
const valueRight = valuePartsList[0];
|
|
159
|
+
const valueLeft = valuePartsList[1] || valuePartsList[0];
|
|
160
|
+
resultStylesGroups[targetElementGroupKey][keyRight] = valueRight;
|
|
161
|
+
resultStylesGroups[targetElementGroupKey][keyLeft] = valueLeft;
|
|
142
162
|
} else if (styleAttributeKey.includes('Vertical')) {
|
|
143
163
|
const keyTop = styleAttributeKey.replace('Vertical', 'Top');
|
|
144
164
|
const keyBottom = styleAttributeKey.replace('Vertical', 'Bottom');
|
|
145
|
-
|
|
146
|
-
|
|
165
|
+
const valuePartsList = value.split(' ');
|
|
166
|
+
const valueTop = valuePartsList[0];
|
|
167
|
+
const valueBottom = valuePartsList[1] || valuePartsList[0];
|
|
168
|
+
resultStylesGroups[targetElementGroupKey][keyTop] = valueTop;
|
|
169
|
+
resultStylesGroups[targetElementGroupKey][keyBottom] = valueBottom;
|
|
147
170
|
} else {
|
|
148
171
|
resultStylesGroups[targetElementGroupKey][styleAttributeKey] = value;
|
|
149
172
|
}
|
package/dist/hooks/useStyles.js
CHANGED
|
@@ -107,22 +107,39 @@ function useStyles(props) {
|
|
|
107
107
|
}
|
|
108
108
|
if (value) {
|
|
109
109
|
// Check not digit symbols. Chars means some unit ("px", "em", "rem" or custom "m")
|
|
110
|
-
const
|
|
110
|
+
const isValueHasUnit = /\D/.test(value);
|
|
111
111
|
// If value has some unit
|
|
112
|
-
if (
|
|
112
|
+
if (isValueHasUnit) {
|
|
113
113
|
// Check value on our custom "m"(module) unit
|
|
114
|
-
|
|
114
|
+
/** Pattern for:
|
|
115
|
+
* 1m
|
|
116
|
+
* 1.5m
|
|
117
|
+
* 1m 1m 1.5m
|
|
118
|
+
* 0 0 1m 1m
|
|
119
|
+
*/
|
|
120
|
+
const isValueHasModuleUnit = /\d+\.?\d*m\s?(?![a-zA-Z]+)/.test(value);
|
|
115
121
|
// If value has module unit
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
if (isValueHasModuleUnit) {
|
|
123
|
+
/** Order for shorthand properties:
|
|
124
|
+
* top
|
|
125
|
+
* right
|
|
126
|
+
* bottom
|
|
127
|
+
* left
|
|
128
|
+
* or:
|
|
129
|
+
* top
|
|
130
|
+
* right and left
|
|
131
|
+
* bottom
|
|
132
|
+
* or:
|
|
133
|
+
* top and bottom
|
|
134
|
+
* right and left
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
const valuePxPartsList = value.split(' ').map(valuePart => {
|
|
138
|
+
const valueModule = valuePart.replace(/[a-z]/gi, '');
|
|
139
|
+
const valuePx = parseFloat(valueModule) * 8;
|
|
140
|
+
return `${valuePx}px`;
|
|
141
|
+
}, []);
|
|
142
|
+
value = valuePxPartsList.join(' ');
|
|
126
143
|
}
|
|
127
144
|
} else {
|
|
128
145
|
// Some properties doesn't have any units
|
|
@@ -133,15 +150,21 @@ function useStyles(props) {
|
|
|
133
150
|
}
|
|
134
151
|
}
|
|
135
152
|
if (styleAttributeKey.includes('Horizontal')) {
|
|
136
|
-
const keyLeft = styleAttributeKey.replace('Horizontal', 'Left');
|
|
137
153
|
const keyRight = styleAttributeKey.replace('Horizontal', 'Right');
|
|
138
|
-
|
|
139
|
-
|
|
154
|
+
const keyLeft = styleAttributeKey.replace('Horizontal', 'Left');
|
|
155
|
+
const valuePartsList = value.split(' ');
|
|
156
|
+
const valueRight = valuePartsList[0];
|
|
157
|
+
const valueLeft = valuePartsList[1] || valuePartsList[0];
|
|
158
|
+
resultStylesGroups[targetElementGroupKey][keyRight] = valueRight;
|
|
159
|
+
resultStylesGroups[targetElementGroupKey][keyLeft] = valueLeft;
|
|
140
160
|
} else if (styleAttributeKey.includes('Vertical')) {
|
|
141
161
|
const keyTop = styleAttributeKey.replace('Vertical', 'Top');
|
|
142
162
|
const keyBottom = styleAttributeKey.replace('Vertical', 'Bottom');
|
|
143
|
-
|
|
144
|
-
|
|
163
|
+
const valuePartsList = value.split(' ');
|
|
164
|
+
const valueTop = valuePartsList[0];
|
|
165
|
+
const valueBottom = valuePartsList[1] || valuePartsList[0];
|
|
166
|
+
resultStylesGroups[targetElementGroupKey][keyTop] = valueTop;
|
|
167
|
+
resultStylesGroups[targetElementGroupKey][keyBottom] = valueBottom;
|
|
145
168
|
} else {
|
|
146
169
|
resultStylesGroups[targetElementGroupKey][styleAttributeKey] = value;
|
|
147
170
|
}
|