@itcase/ui-core 1.10.47 → 1.10.49
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/context/Notifications.interface.js +2 -1
- package/dist/cjs/context/Notifications.js +207 -1
- package/dist/cjs/context/UIContext.js +76 -1
- package/dist/cjs/context/UrlAssetPrefix.js +17 -1
- package/dist/cjs/context/index.js +24 -1
- package/dist/cjs/hoc/index.js +11 -1
- package/dist/cjs/hoc/urlWithAssetPrefix.js +78 -1
- package/dist/cjs/hooks/index.js +37 -1
- package/dist/cjs/hooks/useActiveClasses/index.js +9 -1
- package/dist/cjs/hooks/useActiveClasses/useActiveClasses.helpers.js +93 -1
- package/dist/cjs/hooks/useActiveClasses/useActiveClasses.interface.js +65 -1
- package/dist/cjs/hooks/useActiveClasses/useActiveClasses.js +60 -1
- package/dist/cjs/hooks/useAppearanceConfig/index.js +8 -1
- package/dist/cjs/hooks/useAppearanceConfig/useAppearanceConfig.js +30 -1
- package/dist/cjs/hooks/useDevicePropsGenerator/index.js +23 -1
- package/dist/cjs/hooks/useDevicePropsGenerator/useDevicePropsGenerator.interface.js +2 -1
- package/dist/cjs/hooks/useDevicePropsGenerator/useDevicePropsGenerator.js +236 -1
- package/dist/cjs/hooks/useDeviceTargetClass.js +64 -1
- package/dist/cjs/hooks/useMediaQueries/index.js +9 -1
- package/dist/cjs/hooks/useMediaQueries/useMediaQueries.js +124 -1
- package/dist/cjs/hooks/useStyles/index.js +23 -1
- package/dist/cjs/hooks/useStyles/styleAttributes.helpers.js +9 -1
- package/dist/cjs/hooks/useStyles/styleAttributes.interface.js +2 -1
- package/dist/cjs/hooks/useStyles/styleAttributes.js +177 -1
- package/dist/cjs/hooks/useStyles/useStyles.js +224 -1
- package/dist/cjs/hooks/useViewportFix.js +43 -1
- package/dist/cjs/utils/index.js +9 -1
- package/dist/cjs/utils/mergeAppearanceKeys.js +18 -1
- package/dist/cjs/utils/setViewportProperty.js +8 -1
- package/dist/context/Notifications.js +202 -1
- package/dist/context/UIContext.js +73 -1
- package/dist/context/UrlAssetPrefix.js +14 -1
- package/dist/context/index.js +11 -1
- package/dist/hoc/index.js +5 -1
- package/dist/hoc/urlWithAssetPrefix.js +76 -1
- package/dist/hooks/index.js +24 -1
- package/dist/hooks/useActiveClasses/index.js +3 -1
- package/dist/hooks/useActiveClasses/useActiveClasses.helpers.js +89 -1
- package/dist/hooks/useActiveClasses/useActiveClasses.interface.js +63 -1
- package/dist/hooks/useActiveClasses/useActiveClasses.js +58 -1
- package/dist/hooks/useAppearanceConfig/index.js +2 -1
- package/dist/hooks/useAppearanceConfig/useAppearanceConfig.js +28 -1
- package/dist/hooks/useDevicePropsGenerator/index.js +17 -1
- package/dist/hooks/useDevicePropsGenerator/useDevicePropsGenerator.js +234 -1
- package/dist/hooks/useDeviceTargetClass.js +62 -1
- package/dist/hooks/useMediaQueries/index.js +3 -1
- package/dist/hooks/useMediaQueries/useMediaQueries.js +122 -1
- package/dist/hooks/useStyles/index.js +16 -1
- package/dist/hooks/useStyles/styleAttributes.helpers.js +7 -1
- package/dist/hooks/useStyles/styleAttributes.js +173 -1
- package/dist/hooks/useStyles/useStyles.js +222 -1
- package/dist/hooks/useViewportFix.js +41 -1
- package/dist/types/context/Notifications.d.ts +8 -8
- package/dist/types/hoc/urlWithAssetPrefix.d.ts +2 -3
- package/dist/types/hooks/useActiveClasses/useActiveClasses.interface.d.ts +4 -4
- package/dist/types/hooks/useAppearanceConfig/useAppearanceConfig.d.ts +1 -1
- package/dist/types/hooks/useDevicePropsGenerator/useDevicePropsGenerator.d.ts +1 -1
- package/dist/types/hooks/useDeviceTargetClass.d.ts +2 -1
- package/dist/types/hooks/useMediaQueries/useMediaQueries.d.ts +2 -1
- package/dist/types/hooks/useStyles/styleAttributes.helpers.d.ts +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/mergeAppearanceKeys.js +16 -1
- package/dist/utils/setViewportProperty.js +6 -1
- package/package.json +2 -2
|
@@ -1 +1,173 @@
|
|
|
1
|
-
var
|
|
1
|
+
var styleAttributes = [
|
|
2
|
+
/**
|
|
3
|
+
* Layout
|
|
4
|
+
*/
|
|
5
|
+
'alignContent',
|
|
6
|
+
'alignItems',
|
|
7
|
+
'alignSelf',
|
|
8
|
+
'aspectRatio',
|
|
9
|
+
'border',
|
|
10
|
+
'borderBottomWidth',
|
|
11
|
+
'borderLeftWidth',
|
|
12
|
+
'borderRightWidth',
|
|
13
|
+
'borderTopWidth',
|
|
14
|
+
'borderWidth',
|
|
15
|
+
'bottom',
|
|
16
|
+
'display',
|
|
17
|
+
'flex',
|
|
18
|
+
'flexBasis',
|
|
19
|
+
'flexDirection',
|
|
20
|
+
'flexGrow',
|
|
21
|
+
'flexShrink',
|
|
22
|
+
'flexWrap',
|
|
23
|
+
'gap',
|
|
24
|
+
'rowGap',
|
|
25
|
+
'columnGap',
|
|
26
|
+
'columnWidth',
|
|
27
|
+
'height',
|
|
28
|
+
'justifyContent',
|
|
29
|
+
'left',
|
|
30
|
+
'margin',
|
|
31
|
+
'marginBottom',
|
|
32
|
+
'marginHorizontal',
|
|
33
|
+
'marginLeft',
|
|
34
|
+
'marginRight',
|
|
35
|
+
'marginTop',
|
|
36
|
+
'marginVertical',
|
|
37
|
+
'maxHeight',
|
|
38
|
+
'maxWidth',
|
|
39
|
+
'minHeight',
|
|
40
|
+
'minWidth',
|
|
41
|
+
'overflow',
|
|
42
|
+
'overflowY',
|
|
43
|
+
'overflowX',
|
|
44
|
+
'padding',
|
|
45
|
+
'paddingBottom',
|
|
46
|
+
'paddingEnd',
|
|
47
|
+
'paddingHorizontal',
|
|
48
|
+
'paddingLeft',
|
|
49
|
+
'paddingRight',
|
|
50
|
+
'paddingStart',
|
|
51
|
+
'paddingTop',
|
|
52
|
+
'paddingVertical',
|
|
53
|
+
'position',
|
|
54
|
+
'right',
|
|
55
|
+
'top',
|
|
56
|
+
[
|
|
57
|
+
'width',
|
|
58
|
+
{
|
|
59
|
+
validate: (value) => {
|
|
60
|
+
// Pass only number value for "width" style.
|
|
61
|
+
// If width have custom value, like "fill", we must set class by this value.
|
|
62
|
+
// "\d" - digit; "+" - 1 or more
|
|
63
|
+
return /\d+/.test(value);
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
'zIndex',
|
|
68
|
+
'order',
|
|
69
|
+
/**
|
|
70
|
+
* Shadow
|
|
71
|
+
*/
|
|
72
|
+
'shadowColor',
|
|
73
|
+
'shadowOffset',
|
|
74
|
+
'shadowOpacity',
|
|
75
|
+
'shadowRadius',
|
|
76
|
+
/**
|
|
77
|
+
* Transform
|
|
78
|
+
*/
|
|
79
|
+
'transform',
|
|
80
|
+
/**
|
|
81
|
+
* View
|
|
82
|
+
*/
|
|
83
|
+
'background',
|
|
84
|
+
'backgroundColor',
|
|
85
|
+
'borderBottomColor',
|
|
86
|
+
'borderBottomEndRadius',
|
|
87
|
+
'borderBottomLeftRadius',
|
|
88
|
+
'borderBottomRightRadius',
|
|
89
|
+
'borderBottomStartRadius',
|
|
90
|
+
'borderColor',
|
|
91
|
+
'borderCurve',
|
|
92
|
+
'borderEndColor',
|
|
93
|
+
'borderLeftColor',
|
|
94
|
+
'borderRadius',
|
|
95
|
+
'borderRightColor',
|
|
96
|
+
'borderStartColor',
|
|
97
|
+
'borderStyle',
|
|
98
|
+
'borderTopColor',
|
|
99
|
+
'borderTopEndRadius',
|
|
100
|
+
'borderTopLeftRadius',
|
|
101
|
+
'borderTopRightRadius',
|
|
102
|
+
'borderTopStartRadius',
|
|
103
|
+
'opacity',
|
|
104
|
+
'cursor',
|
|
105
|
+
/**
|
|
106
|
+
* Text
|
|
107
|
+
*/
|
|
108
|
+
'color',
|
|
109
|
+
'fontFamily',
|
|
110
|
+
'fontSize',
|
|
111
|
+
'fontStyle',
|
|
112
|
+
'fontVariant',
|
|
113
|
+
'fontWeight',
|
|
114
|
+
'letterSpacing',
|
|
115
|
+
'lineHeight',
|
|
116
|
+
'textAlign',
|
|
117
|
+
'textDecorationColor',
|
|
118
|
+
'textDecorationLine',
|
|
119
|
+
'textDecorationStyle',
|
|
120
|
+
'textShadowColor',
|
|
121
|
+
'textShadowOffset',
|
|
122
|
+
'textShadowRadius',
|
|
123
|
+
'textTransform',
|
|
124
|
+
'verticalAlign',
|
|
125
|
+
'writingMode',
|
|
126
|
+
'whiteSpace',
|
|
127
|
+
/**
|
|
128
|
+
* Image
|
|
129
|
+
*/
|
|
130
|
+
'overlayColor',
|
|
131
|
+
'resizeMode',
|
|
132
|
+
'tintColor',
|
|
133
|
+
'objectFit',
|
|
134
|
+
'objectPosition',
|
|
135
|
+
/**
|
|
136
|
+
* Grid
|
|
137
|
+
*/
|
|
138
|
+
'gridTemplateColumns',
|
|
139
|
+
'gridArea',
|
|
140
|
+
'gridAutoColumns',
|
|
141
|
+
'gridAutoFlow',
|
|
142
|
+
'gridAutoRows',
|
|
143
|
+
'gridTemplate',
|
|
144
|
+
'gridTemplateAreas',
|
|
145
|
+
'gridTemplateRows',
|
|
146
|
+
'gridColumn',
|
|
147
|
+
'gridColumnStart',
|
|
148
|
+
'gridColumnEnd',
|
|
149
|
+
'gridColumnGap',
|
|
150
|
+
'gridRow',
|
|
151
|
+
'gridRowStart',
|
|
152
|
+
'gridRowEnd',
|
|
153
|
+
'gridRowGap',
|
|
154
|
+
/**
|
|
155
|
+
* Filter
|
|
156
|
+
*/
|
|
157
|
+
'backdropFilter',
|
|
158
|
+
/**
|
|
159
|
+
* Transition
|
|
160
|
+
*/
|
|
161
|
+
'transition',
|
|
162
|
+
'transitionBehavior',
|
|
163
|
+
'transitionDelay',
|
|
164
|
+
'transitionDuration',
|
|
165
|
+
'transitionProperty',
|
|
166
|
+
'transitionTimingFunction',
|
|
167
|
+
/**
|
|
168
|
+
* Control
|
|
169
|
+
*/
|
|
170
|
+
'pointerEvents',
|
|
171
|
+
];
|
|
172
|
+
|
|
173
|
+
export { styleAttributes as default };
|
|
@@ -1 +1,222 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import camelCase from 'lodash/camelCase';
|
|
3
|
+
import maxBy from 'lodash/maxBy';
|
|
4
|
+
import upperFirst from 'lodash/upperFirst';
|
|
5
|
+
import '../../context/Notifications.js';
|
|
6
|
+
import { useUserDeviceContext } from '../../context/UIContext.js';
|
|
7
|
+
import '../../context/UrlAssetPrefix.js';
|
|
8
|
+
import styleAttributes from './styleAttributes.js';
|
|
9
|
+
import { getStyleAttributeKey } from './styleAttributes.helpers.js';
|
|
10
|
+
import 'react/jsx-runtime';
|
|
11
|
+
import 'uuid';
|
|
12
|
+
import '@itcase/common';
|
|
13
|
+
import '../useMediaQueries/useMediaQueries.js';
|
|
14
|
+
import 'react-responsive';
|
|
15
|
+
import '../../utils/setViewportProperty.js';
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* rule of prop key:
|
|
19
|
+
*
|
|
20
|
+
* first is style second is div target third is device
|
|
21
|
+
* paddingHorizontal GridInnerWrapper MobileNormal
|
|
22
|
+
*
|
|
23
|
+
* paddingHorizontalGridInnerWrapperMobileNormal: "10px"
|
|
24
|
+
*/
|
|
25
|
+
function useStyles(props) {
|
|
26
|
+
const { deviceCurrentMainType, deviceCurrentType, deviceTypesList } = useUserDeviceContext();
|
|
27
|
+
const propsStyleAttributes = useMemo(() => {
|
|
28
|
+
const styles = Object.entries(props).reduce((result, [propKey, propValue]) => {
|
|
29
|
+
const styleAttributeKey = getTargetStyleAttributeKey(propKey, propValue);
|
|
30
|
+
if (styleAttributeKey) {
|
|
31
|
+
result[propKey] = propValue;
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}, {});
|
|
35
|
+
return styles;
|
|
36
|
+
// "props" object maybe big and frequently changing
|
|
37
|
+
}, [props]);
|
|
38
|
+
const collectedStyles = useMemo(() => {
|
|
39
|
+
const resultStylesGroups = {};
|
|
40
|
+
for (const [propKey, propValue] of Object.entries(propsStyleAttributes)) {
|
|
41
|
+
let value = null;
|
|
42
|
+
const styleAttributeKey = getTargetStyleAttributeKey(propKey, propValue);
|
|
43
|
+
const isStyleForCurrentDevice = propKey
|
|
44
|
+
.toLowerCase()
|
|
45
|
+
.endsWith(deviceCurrentType.toLowerCase());
|
|
46
|
+
// e.g. "GridWrapperInner"
|
|
47
|
+
const targetElementKey = removeDeviceType(propKey.replace(styleAttributeKey, ''), deviceTypesList);
|
|
48
|
+
const targetElementGroupKey = camelCase(targetElementKey) || 'styles';
|
|
49
|
+
if (!resultStylesGroups[targetElementGroupKey]) {
|
|
50
|
+
resultStylesGroups[targetElementGroupKey] = {};
|
|
51
|
+
}
|
|
52
|
+
if (isStyleForCurrentDevice) {
|
|
53
|
+
value = propValue;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const propKeyWithOutDeviceType = `${styleAttributeKey}${targetElementKey}`;
|
|
57
|
+
const propKeyWithBaseDeviceType = `${propKeyWithOutDeviceType}${upperFirst(deviceCurrentMainType)}`;
|
|
58
|
+
const defaultValue = props[propKeyWithBaseDeviceType] || props[propKeyWithOutDeviceType];
|
|
59
|
+
let currentValue = resultStylesGroups[targetElementGroupKey][styleAttributeKey];
|
|
60
|
+
if (propKeyWithOutDeviceType.includes('Horizontal')) {
|
|
61
|
+
const keyLeft = styleAttributeKey.replace('Horizontal', 'Left');
|
|
62
|
+
currentValue =
|
|
63
|
+
resultStylesGroups[targetElementGroupKey][keyLeft];
|
|
64
|
+
}
|
|
65
|
+
else if (propKeyWithOutDeviceType.includes('Vertical')) {
|
|
66
|
+
const keyTop = styleAttributeKey.replace('Vertical', 'Top');
|
|
67
|
+
currentValue =
|
|
68
|
+
resultStylesGroups[targetElementGroupKey][keyTop];
|
|
69
|
+
}
|
|
70
|
+
if (!currentValue) {
|
|
71
|
+
value = defaultValue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (value) {
|
|
75
|
+
// Check not digit symbols. Chars means some unit ("px", "em", "rem" or custom "m")
|
|
76
|
+
const isValueHasUnit = /\D/.test(value);
|
|
77
|
+
// If value has some unit
|
|
78
|
+
if (isValueHasUnit) {
|
|
79
|
+
// Check value on our custom "m"(module) unit
|
|
80
|
+
/** Pattern for:
|
|
81
|
+
* 1m
|
|
82
|
+
* 1.5m
|
|
83
|
+
* 1m 1m 1.5m
|
|
84
|
+
* 0 0 1m 1m
|
|
85
|
+
*/
|
|
86
|
+
const isValueHasModuleUnit = /\d+\.?\d*m\s?(?![a-zA-Z]+)/.test(value);
|
|
87
|
+
// If value has module unit
|
|
88
|
+
if (isValueHasModuleUnit) {
|
|
89
|
+
/** Order for shorthand properties:
|
|
90
|
+
* top
|
|
91
|
+
* right
|
|
92
|
+
* bottom
|
|
93
|
+
* left
|
|
94
|
+
* or:
|
|
95
|
+
* top
|
|
96
|
+
* right and left
|
|
97
|
+
* bottom
|
|
98
|
+
* or:
|
|
99
|
+
* top and bottom
|
|
100
|
+
* right and left
|
|
101
|
+
*/
|
|
102
|
+
const valuePxPartsList = value
|
|
103
|
+
.split(' ')
|
|
104
|
+
.map((valuePart) => {
|
|
105
|
+
const valueModule = valuePart.replace(/[a-z]/gi, '');
|
|
106
|
+
const valuePx = parseFloat(valueModule) * 8;
|
|
107
|
+
return `${valuePx}px`;
|
|
108
|
+
}, []);
|
|
109
|
+
value = valuePxPartsList.join(' ');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// Some properties doesn't have any units
|
|
114
|
+
const ignorePX = [
|
|
115
|
+
'flexGrow',
|
|
116
|
+
'gridColumn',
|
|
117
|
+
'gridColumnEnd',
|
|
118
|
+
'gridColumnStart',
|
|
119
|
+
'gridRow',
|
|
120
|
+
'gridRowEnd',
|
|
121
|
+
'gridRowStart',
|
|
122
|
+
'opacity',
|
|
123
|
+
'order',
|
|
124
|
+
'zIndex',
|
|
125
|
+
].includes(styleAttributeKey);
|
|
126
|
+
if (!ignorePX) {
|
|
127
|
+
// Add px to non-unit value
|
|
128
|
+
value = `${value}px`;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (styleAttributeKey.includes('Horizontal')) {
|
|
132
|
+
const keyRight = styleAttributeKey.replace('Horizontal', 'Right');
|
|
133
|
+
const keyLeft = styleAttributeKey.replace('Horizontal', 'Left');
|
|
134
|
+
const valuePartsList = value.split(' ');
|
|
135
|
+
const valueRight = valuePartsList[0];
|
|
136
|
+
const valueLeft = valuePartsList[1] || valuePartsList[0];
|
|
137
|
+
resultStylesGroups[targetElementGroupKey][keyRight] = valueRight;
|
|
138
|
+
resultStylesGroups[targetElementGroupKey][keyLeft] = valueLeft;
|
|
139
|
+
}
|
|
140
|
+
else if (styleAttributeKey.includes('Vertical')) {
|
|
141
|
+
const keyTop = styleAttributeKey.replace('Vertical', 'Top');
|
|
142
|
+
const keyBottom = styleAttributeKey.replace('Vertical', 'Bottom');
|
|
143
|
+
const valuePartsList = value.split(' ');
|
|
144
|
+
const valueTop = valuePartsList[0];
|
|
145
|
+
const valueBottom = valuePartsList[1] || valuePartsList[0];
|
|
146
|
+
resultStylesGroups[targetElementGroupKey][keyTop] = valueTop;
|
|
147
|
+
resultStylesGroups[targetElementGroupKey][keyBottom] = valueBottom;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
resultStylesGroups[targetElementGroupKey][styleAttributeKey] = value;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return resultStylesGroups;
|
|
155
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
156
|
+
}, [
|
|
157
|
+
deviceCurrentMainType,
|
|
158
|
+
deviceCurrentType,
|
|
159
|
+
...Object.values(propsStyleAttributes),
|
|
160
|
+
]);
|
|
161
|
+
return collectedStyles;
|
|
162
|
+
}
|
|
163
|
+
const removeDeviceType = (originalKey, deviceTypesList) => {
|
|
164
|
+
// Remove "mobile"/"tablet"/"desktop"
|
|
165
|
+
const withOutDeviceType = deviceTypesList.reduce((cleanKey, deviceType) => {
|
|
166
|
+
if (cleanKey.endsWith(upperFirst(deviceType))) {
|
|
167
|
+
return cleanKey.replace(upperFirst(deviceType), '');
|
|
168
|
+
}
|
|
169
|
+
return cleanKey;
|
|
170
|
+
}, originalKey);
|
|
171
|
+
return withOutDeviceType;
|
|
172
|
+
};
|
|
173
|
+
const targetStyleAttributeKeyCache = new Map();
|
|
174
|
+
// This function is pure and it does a lot of useless work.
|
|
175
|
+
// We can achieve huge cache hit rate by memoizing it.
|
|
176
|
+
const getTargetStyleAttributeKey = (styleKey, styleValue = '') => {
|
|
177
|
+
const cacheKey = `${styleKey}_${styleValue}`;
|
|
178
|
+
if (targetStyleAttributeKeyCache.has(cacheKey)) {
|
|
179
|
+
return targetStyleAttributeKeyCache.get(cacheKey);
|
|
180
|
+
}
|
|
181
|
+
// Collect list of possible styles for propKey. e.g:
|
|
182
|
+
// "borderLeftWidthWrapperInnerMobileNormal" to ["border", "borderLeftWidth"]
|
|
183
|
+
const possibleStyleAttributesList = styleAttributes.filter((styleAttribute) => {
|
|
184
|
+
// Attribute can be array with key on first position and params on second
|
|
185
|
+
if (Array.isArray(styleAttribute)) {
|
|
186
|
+
// First item always attribute key (e.g. border, width, etc)
|
|
187
|
+
const styleAttributeKey = styleAttribute[0];
|
|
188
|
+
// Second item always params with some settings or methods
|
|
189
|
+
const styleAttributeParams = styleAttribute[1] || {};
|
|
190
|
+
// If is target attribute key
|
|
191
|
+
if (styleKey.startsWith(styleAttributeKey)) {
|
|
192
|
+
// If target attribute params has validate method
|
|
193
|
+
if (styleAttributeParams.validate) {
|
|
194
|
+
// Return validation result for target attribute
|
|
195
|
+
return styleAttributeParams.validate(styleValue);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
// Or always add to list
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
// Else ignore
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
// If is target attribute
|
|
209
|
+
return styleKey.startsWith(String(styleAttribute));
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
// Get longest style key (e.g. "borderLeftWidth")
|
|
213
|
+
const targetStyleAttribute = maxBy(possibleStyleAttributesList, (styleAttribute) => {
|
|
214
|
+
const key = getStyleAttributeKey(styleAttribute);
|
|
215
|
+
return key.length;
|
|
216
|
+
});
|
|
217
|
+
const styleAttributeKey = getStyleAttributeKey(targetStyleAttribute);
|
|
218
|
+
targetStyleAttributeKeyCache.set(cacheKey, styleAttributeKey);
|
|
219
|
+
return styleAttributeKey;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export { useStyles };
|
|
@@ -1 +1,41 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
function useViewportFix() {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
// https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
|
|
6
|
+
const setViewportProperty = () => {
|
|
7
|
+
// "vh" unit is equal to 1% of the height of the initial containing block
|
|
8
|
+
// https://www.w3.org/R/css-values-3/#viewport-relative-lengths
|
|
9
|
+
const vh = window.innerHeight * 0.01;
|
|
10
|
+
/** NOTE:
|
|
11
|
+
* In JavaScript, you can always get the value of the current viewport
|
|
12
|
+
* by using the global variable window.innerHeight. This value takes
|
|
13
|
+
* the browser’s interface into account and is updated when its
|
|
14
|
+
* visibility changes. The trick is to store the viewport value
|
|
15
|
+
* in a CSS variable and apply that to the element instead of the vh unit.
|
|
16
|
+
* Let’s say our CSS custom variable is --vh for this example.
|
|
17
|
+
* That means we will want to apply it in our CSS like this:
|
|
18
|
+
* ```
|
|
19
|
+
* .my-element {
|
|
20
|
+
* height: 100vh; (Fallback for browsers that do not support Custom Properties)
|
|
21
|
+
* height: calc(var(--vh, 1vh) * 100);
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
* We told JavaScript to grab the height of the viewport and then
|
|
25
|
+
* drilled it down into 1/100th of that total so we have a value
|
|
26
|
+
* to assign as our viewport height unit value.
|
|
27
|
+
* Then we politely asked JS to create the CSS variable "--vh" at the ":root":
|
|
28
|
+
*/
|
|
29
|
+
document.documentElement.style.setProperty('--vh', `${vh}px`);
|
|
30
|
+
};
|
|
31
|
+
// Update the value of "--vh" after render
|
|
32
|
+
setViewportProperty();
|
|
33
|
+
// Update the value of "--vh" by listening to the window resize event
|
|
34
|
+
window.addEventListener('resize', setViewportProperty);
|
|
35
|
+
return () => {
|
|
36
|
+
window.removeEventListener('resize', setViewportProperty);
|
|
37
|
+
};
|
|
38
|
+
}, []);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { useViewportFix };
|
|
@@ -7,16 +7,16 @@ declare function useNotificationsAPI(): {
|
|
|
7
7
|
removeNotification: (targetId?: GeneratedId) => void;
|
|
8
8
|
showNotification: (notification: string | CreatedNotification, onClose?: SimpleCallback) => void;
|
|
9
9
|
notificationStatuses: {
|
|
10
|
-
readonly error:
|
|
11
|
-
readonly info:
|
|
12
|
-
readonly success:
|
|
13
|
-
readonly warning:
|
|
10
|
+
readonly error: 'error';
|
|
11
|
+
readonly info: 'info';
|
|
12
|
+
readonly success: 'success';
|
|
13
|
+
readonly warning: 'warning';
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
16
|
declare const statusToAppearanceList: {
|
|
17
|
-
readonly error:
|
|
18
|
-
readonly info:
|
|
19
|
-
readonly success:
|
|
20
|
-
readonly warning:
|
|
17
|
+
readonly error: 'errorPrimary sizeS solid rounded';
|
|
18
|
+
readonly info: 'infoPrimary sizeS solid rounded';
|
|
19
|
+
readonly success: 'successPrimary sizeS solid rounded';
|
|
20
|
+
readonly warning: 'warningPrimary sizeS solid rounded';
|
|
21
21
|
};
|
|
22
22
|
export { NotificationsProvider, statusToAppearanceList, useNotifications, useNotificationsAPI, };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import type { ComponentType, ForwardRefExoticComponent, PropsWithoutRef, RefAttributes } from 'react';
|
|
3
2
|
import { RequireAtLeastOneProp, RequireAtLeastOnePropError } from '../types';
|
|
4
3
|
type UrlPropKeys = (typeof urlPropsList)[number];
|
|
@@ -6,7 +5,7 @@ type OnePropCheckError = [
|
|
|
6
5
|
'urlWithAssetPrefix: компонент должен содержать хотя бы один из пропсов',
|
|
7
6
|
UrlPropKeys
|
|
8
7
|
];
|
|
9
|
-
declare const urlPropsList: readonly [
|
|
8
|
+
declare const urlPropsList: readonly ['src', 'imageSrc', 'svgSrc', 'placeholderUrl'];
|
|
10
9
|
/**
|
|
11
10
|
* HOC, который добавляет assetPrefix к URL-пропсам.
|
|
12
11
|
*
|
|
@@ -24,5 +23,5 @@ declare const urlPropsList: readonly ["src", "imageSrc", "svgSrc", "placeholderU
|
|
|
24
23
|
* const B = (props: { id: string }) => <div />;
|
|
25
24
|
* urlWithAssetPrefix(B); // ❌ TS ошибка (нет url-пропов)
|
|
26
25
|
*/
|
|
27
|
-
declare const urlWithAssetPrefix: <P extends Record<string, any>, T = unknown, OnePropCheck extends RequireAtLeastOneProp<P, UrlPropKeys> = RequireAtLeastOneProp<P, UrlPropKeys>>(WrappedComponent: ComponentType<P> | ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>, ..._error: RequireAtLeastOnePropError<OnePropCheck, OnePropCheckError>) =>
|
|
26
|
+
declare const urlWithAssetPrefix: <P extends Record<string, any>, T = unknown, OnePropCheck extends RequireAtLeastOneProp<P, UrlPropKeys> = RequireAtLeastOneProp<P, UrlPropKeys>>(WrappedComponent: ComponentType<P> | ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>, ..._error: RequireAtLeastOnePropError<OnePropCheck, OnePropCheckError>) => ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>;
|
|
28
27
|
export { urlWithAssetPrefix };
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
declare const suffix: readonly [
|
|
1
|
+
declare const suffix: readonly ['Button', 'Checkbox', 'Radio', 'Checkmark', 'Avatar', 'AvatarStack', 'Badge', 'Breadcrumbs', 'Cell', 'Chips', 'Choice', 'Code', 'CookiesWarning', 'Dadata', 'DatePeriod', 'Divider', 'Dot', 'Drawer', 'Dropdown', 'DropdownItem', 'Flex', 'Grid', 'Group', 'HeroTitle', 'HTMLContent', 'Icon', 'Image', 'Input', 'InputPassword', 'Label', 'Link', 'List', 'Loader', 'Logo', 'MenuItem', 'Modal', 'ModalSheetBottom', 'Notification', 'Overlay', 'Pagination', 'RangeSlider', 'Response', 'ScrollBar', 'ScrollOnDrag', 'ScrollToView', 'Search', 'Segmented', 'Select', 'SvgContent', 'Swiper', 'Switch', 'Tab', 'Text', 'Textarea', 'Tile', 'Title', 'Tooltip', 'Video', 'Warning'];
|
|
2
2
|
type SuffixComponents = (typeof suffix)[number];
|
|
3
3
|
type SpecialSuffix<T extends string> = T extends 'HTMLContent' ? 'htmlContent' : Uncapitalize<T>;
|
|
4
4
|
type SuffixKeys = SpecialSuffix<SuffixComponents>;
|
|
5
5
|
interface PropsGenerator {
|
|
6
6
|
[key: string]: any | number | string | undefined;
|
|
7
|
-
getProp?: (propKey: string) =>
|
|
7
|
+
getProp?: (propKey: string) => unknown;
|
|
8
8
|
}
|
|
9
9
|
interface UseActiveClassesReturn {
|
|
10
10
|
rootClasses: string;
|
|
11
11
|
suffixClasses: Record<SuffixKeys, string>;
|
|
12
12
|
}
|
|
13
13
|
interface UseActiveClasses {
|
|
14
|
-
propsGenerator: PropsGenerator;
|
|
15
|
-
suffixes?: SuffixComponents[];
|
|
16
14
|
isActive?: boolean;
|
|
17
15
|
isDisabled?: boolean;
|
|
16
|
+
propsGenerator: PropsGenerator;
|
|
17
|
+
suffixes?: SuffixComponents[];
|
|
18
18
|
}
|
|
19
19
|
interface RulesConfig {
|
|
20
20
|
key: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AppearanceConfig } from '../useDevicePropsGenerator';
|
|
2
|
-
declare const useAppearanceConfig: <Keys extends string, Config extends Record<
|
|
2
|
+
declare const useAppearanceConfig: <Keys extends string, Config extends Record<'disabled' | 'disabledPrimary' | Keys, AppearanceConfig>>(appearance: string | undefined, componentConfig: {
|
|
3
3
|
appearance?: Partial<Config>;
|
|
4
4
|
}, isDisabled?: boolean) => AppearanceConfig;
|
|
5
5
|
export { useAppearanceConfig };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { KebabCase, WithClassKeys } from '../../types';
|
|
2
2
|
import type { AppearanceConfig, ComponentProps, GeneratorGetClassParams as GP } from './useDevicePropsGenerator.interface';
|
|
3
3
|
declare function useDevicePropsGenerator<Props extends ComponentProps>(componentProps: Props, appearanceConfig?: AppearanceConfig): Props & {
|
|
4
|
-
getProp(propKey: string):
|
|
4
|
+
getProp(propKey: string): any;
|
|
5
5
|
getClassName<K extends Extract<keyof Props, string>, P extends GP | undefined = undefined>(propKey: K, params?: P): ReturnGetClassName<Props, K, P>;
|
|
6
6
|
} & WithClassKeys<Props>;
|
|
7
7
|
type ReturnGetClassName<Props, K extends keyof Props, Params = undefined> = Params extends undefined ? NonNullable<Props[K]> extends string ? KebabCase<NonNullable<Props[K]>> : string : Props[K];
|
|
@@ -2,4 +2,5 @@
|
|
|
2
2
|
* Hook is still used in "itcase-forms".
|
|
3
3
|
* Need replace with "useDevicePropsGenerator" and delete this.
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
declare function useDeviceTargetClass(componentProps: any, hookProps: any): string;
|
|
6
|
+
export { useDeviceTargetClass };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { StyleAttributeOrValidator } from './styleAttributes.interface';
|
|
2
|
-
declare const getStyleAttributeKey: (targetStyleAttribute: StyleAttributeOrValidator) =>
|
|
2
|
+
declare const getStyleAttributeKey: (targetStyleAttribute: StyleAttributeOrValidator) => "-moz-fit-content" | "-moz-initial" | "-moz-max-content" | "-moz-min-content" | "-webkit-fit-content" | "-webkit-max-content" | "auto" | "fill" | "fit-content" | "fixed" | "hug" | "inherit" | "initial" | "intrinsic" | "max-content" | "min-content" | "min-intrinsic" | "revert" | "revert-layer" | "unset" | 0 | import("./styleAttributes.interface").StyleAttributes | (string & {});
|
|
3
3
|
export { getStyleAttributeKey };
|
package/dist/utils/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export{mergeAppearanceKeys}from
|
|
1
|
+
export { mergeAppearanceKeys } from './mergeAppearanceKeys.js';
|
|
2
|
+
export { setViewportProperty } from './setViewportProperty.js';
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @example
|
|
3
|
+
* mergeAppearanceKeys(' ', '1', undefined, '2', '1') === '1 2'
|
|
4
|
+
*/
|
|
5
|
+
const mergeAppearanceKeys = (...appearances) => {
|
|
6
|
+
const trimmedAppearances = appearances
|
|
7
|
+
.map((appearance) => appearance?.trim())
|
|
8
|
+
.filter(Boolean);
|
|
9
|
+
if (trimmedAppearances.length < 2) {
|
|
10
|
+
return trimmedAppearances[0] ?? '';
|
|
11
|
+
}
|
|
12
|
+
const uniqueAppearances = Array.from(new Set(trimmedAppearances));
|
|
13
|
+
return uniqueAppearances.join(' ');
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { mergeAppearanceKeys };
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const setViewportProperty = () => {
|
|
2
|
+
const vh = window.innerHeight * 0.01;
|
|
3
|
+
document.documentElement.style.setProperty('--vh', `${vh}px`);
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export { setViewportProperty };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itcase/ui-core",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.49",
|
|
4
4
|
"description": "UI shared components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Modal",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
97
97
|
"rollup-preserve-directives": "^1.1.3"
|
|
98
98
|
},
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "ead85bbfc14746e9fdffa79e015842111ff38d8b"
|
|
100
100
|
}
|