@itcase/ui-core 1.10.47 → 1.10.48
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,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
const useAppearanceConfig = (appearance, componentConfig, isDisabled) => {
|
|
4
|
+
const appearanceConfig = useMemo(() => {
|
|
5
|
+
if (appearance) {
|
|
6
|
+
const appearanceProps = appearance
|
|
7
|
+
.split(' ')
|
|
8
|
+
.reduce((resultConfig, appearanceKey) => {
|
|
9
|
+
return Object.assign(resultConfig, componentConfig?.appearance?.[appearanceKey]);
|
|
10
|
+
}, {});
|
|
11
|
+
if (isDisabled &&
|
|
12
|
+
(componentConfig?.appearance?.disabled ||
|
|
13
|
+
componentConfig?.appearance?.disabledPrimary)) {
|
|
14
|
+
Object.assign(appearanceProps, componentConfig?.appearance?.disabled ||
|
|
15
|
+
componentConfig?.appearance?.disabledPrimary);
|
|
16
|
+
}
|
|
17
|
+
return appearanceProps;
|
|
18
|
+
}
|
|
19
|
+
if (isDisabled) {
|
|
20
|
+
return (componentConfig?.appearance?.disabled ||
|
|
21
|
+
componentConfig?.appearance?.disabledPrimary);
|
|
22
|
+
}
|
|
23
|
+
return {};
|
|
24
|
+
}, [appearance, componentConfig?.appearance, isDisabled]);
|
|
25
|
+
return appearanceConfig;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { useAppearanceConfig };
|
|
@@ -1 +1,17 @@
|
|
|
1
|
-
export{useDevicePropsGenerator}from
|
|
1
|
+
export { useDevicePropsGenerator } from './useDevicePropsGenerator.js';
|
|
2
|
+
import 'react';
|
|
3
|
+
import 'lodash/camelCase';
|
|
4
|
+
import 'lodash/castArray';
|
|
5
|
+
import 'lodash/upperFirst';
|
|
6
|
+
import '../../context/Notifications.js';
|
|
7
|
+
import 'react/jsx-runtime';
|
|
8
|
+
import 'uuid';
|
|
9
|
+
import '@itcase/common';
|
|
10
|
+
import '../../context/UIContext.js';
|
|
11
|
+
import '../useMediaQueries/useMediaQueries.js';
|
|
12
|
+
import 'react-responsive';
|
|
13
|
+
import '../../utils/setViewportProperty.js';
|
|
14
|
+
import '../../context/UrlAssetPrefix.js';
|
|
15
|
+
import '../useStyles/styleAttributes.js';
|
|
16
|
+
import '../useStyles/styleAttributes.helpers.js';
|
|
17
|
+
import 'lodash/maxBy';
|
|
@@ -1 +1,234 @@
|
|
|
1
|
-
import{useRef
|
|
1
|
+
import { useRef, useMemo } from 'react';
|
|
2
|
+
import camelCase from 'lodash/camelCase';
|
|
3
|
+
import castArray from 'lodash/castArray';
|
|
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 '../useStyles/styleAttributes.js';
|
|
9
|
+
import { getStyleAttributeKey } from '../useStyles/styleAttributes.helpers.js';
|
|
10
|
+
import 'lodash/maxBy';
|
|
11
|
+
import 'react/jsx-runtime';
|
|
12
|
+
import 'uuid';
|
|
13
|
+
import '@itcase/common';
|
|
14
|
+
import '../useMediaQueries/useMediaQueries.js';
|
|
15
|
+
import 'react-responsive';
|
|
16
|
+
import '../../utils/setViewportProperty.js';
|
|
17
|
+
|
|
18
|
+
/* eslint-disable react-hooks/immutability */
|
|
19
|
+
/* eslint-disable react-hooks/refs */
|
|
20
|
+
function useDevicePropsGenerator(componentProps, appearanceConfig) {
|
|
21
|
+
/** Get or generate(classname) a prop depending on the user's device.
|
|
22
|
+
* Props:
|
|
23
|
+
* - "componentProps" - original "props" from component
|
|
24
|
+
* - "appearanceConfig" - special appearance dictionary with styles presets
|
|
25
|
+
*
|
|
26
|
+
* Usage for create class value:
|
|
27
|
+
* const appearanceConfig = (
|
|
28
|
+
* appearance && componentConfig.appearance && componentConfig.appearance[appearance]
|
|
29
|
+
* )
|
|
30
|
+
* const propsGenerator = useDevicePropsGenerator(props, appearanceConfig)
|
|
31
|
+
* ---------
|
|
32
|
+
* const fillClass = propsGenerator.getClassName('fill')
|
|
33
|
+
* "fillClass" - is "surface-secondary"
|
|
34
|
+
* ---------
|
|
35
|
+
* const fillClass = propsGenerator.getClassName('fill', { prefix: 'fill_' })
|
|
36
|
+
* "fillClass" - is "fill_surface-secondary"
|
|
37
|
+
* ---------
|
|
38
|
+
* const fillClass = propsGenerator.fillClass
|
|
39
|
+
* "fillClass" - is "surface-secondary"
|
|
40
|
+
* ---------
|
|
41
|
+
* const { fillClass } = propsGenerator
|
|
42
|
+
* "fillClass" - is "surface-secondary"
|
|
43
|
+
*
|
|
44
|
+
* Usage for props value for device:
|
|
45
|
+
* const { titleTextSize } = propsGenerator / const titleTextSize = propsGenerator.titleTextSize
|
|
46
|
+
*
|
|
47
|
+
* "titleTextSize" - contain some value from props:
|
|
48
|
+
* - titleTextSize
|
|
49
|
+
* - titleTextSizeMobile
|
|
50
|
+
* - titleTextSizeTablet
|
|
51
|
+
* - titleTextSizeDesktop
|
|
52
|
+
* ---------
|
|
53
|
+
**/
|
|
54
|
+
const { deviceCurrentMainType } = useUserDeviceContext();
|
|
55
|
+
// if (isDevelopmentEnv && isClientEnv) {
|
|
56
|
+
// if (window.__cache === undefined) {
|
|
57
|
+
// window.__cache = {
|
|
58
|
+
// reset: () => {
|
|
59
|
+
// window.__cache.cache_creation_count = 0
|
|
60
|
+
// window.__cache.proxy_field_access_count = 0
|
|
61
|
+
// window.__cache.proxy_creation_count = 0
|
|
62
|
+
// window.__cache.cache_miss_count = 0
|
|
63
|
+
// window.__cache.cache_hit_count = 0
|
|
64
|
+
// window.__cache.cache_early_avoid_count = 0
|
|
65
|
+
// },
|
|
66
|
+
// cache_creation_count: 0,
|
|
67
|
+
// cache_early_avoid_count: 0,
|
|
68
|
+
// cache_hit_count: 0,
|
|
69
|
+
// cache_miss_count: 0,
|
|
70
|
+
// proxy_creation_count: 0,
|
|
71
|
+
// proxy_field_access_count: 0,
|
|
72
|
+
// }
|
|
73
|
+
// }
|
|
74
|
+
// }
|
|
75
|
+
// Used by proxy getter.
|
|
76
|
+
// Proxy getter does not care about reference of "componentProps" and
|
|
77
|
+
// "deviceCurrentMainType", because it always get actual value from these refs.
|
|
78
|
+
// We should not pass these values in proxy's dependency list.
|
|
79
|
+
// All we have to do is to update these refs on each render.
|
|
80
|
+
const propsRef = useRef(componentProps);
|
|
81
|
+
propsRef.current = componentProps;
|
|
82
|
+
const deviceCurrentMainTypeRef = useRef(deviceCurrentMainType);
|
|
83
|
+
deviceCurrentMainTypeRef.current = deviceCurrentMainType;
|
|
84
|
+
const appearanceConfigRef = useRef(appearanceConfig);
|
|
85
|
+
appearanceConfigRef.current = appearanceConfig;
|
|
86
|
+
// Store mutable cache.
|
|
87
|
+
// Cache will be reset on "appearanceConfig" or "deviceCurrentMainType" change.
|
|
88
|
+
const cachedClassValueMap = useMemo(() => {
|
|
89
|
+
// if (isDevelopmentEnv && isClientEnv) {
|
|
90
|
+
// window.__cache.cache_creation_count += 1
|
|
91
|
+
// }
|
|
92
|
+
return new Map();
|
|
93
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
|
+
}, [appearanceConfig, deviceCurrentMainType]);
|
|
95
|
+
// Same as before, we need to keep track of updated value in stable reference.
|
|
96
|
+
const cachedClassValueMapRef = useRef(cachedClassValueMap);
|
|
97
|
+
cachedClassValueMapRef.current = cachedClassValueMap;
|
|
98
|
+
const devicePropsGenerator = useMemo(() => {
|
|
99
|
+
// if (isDevelopmentEnv && isClientEnv) {
|
|
100
|
+
// window.__cache.proxy_creation_count += 1;
|
|
101
|
+
// }
|
|
102
|
+
let cachedDeviceType;
|
|
103
|
+
let cachedDeviceTypeUpperFirst;
|
|
104
|
+
const propsGenerator = {
|
|
105
|
+
getProp(propKey) {
|
|
106
|
+
const deviceType = deviceCurrentMainTypeRef.current;
|
|
107
|
+
if (cachedDeviceType !== deviceType) {
|
|
108
|
+
cachedDeviceType = deviceType;
|
|
109
|
+
cachedDeviceTypeUpperFirst = upperFirst(deviceType);
|
|
110
|
+
}
|
|
111
|
+
const propsForDeviceKey = propKey + cachedDeviceTypeUpperFirst;
|
|
112
|
+
let targetPropsValue = undefined;
|
|
113
|
+
if (propsForDeviceKey in propsRef.current) {
|
|
114
|
+
// Value for device from props is first priority
|
|
115
|
+
targetPropsValue = propsRef.current[propsForDeviceKey];
|
|
116
|
+
}
|
|
117
|
+
else if (propKey in propsRef.current) {
|
|
118
|
+
// Value without device from props is second priority
|
|
119
|
+
targetPropsValue = propsRef.current[propKey];
|
|
120
|
+
}
|
|
121
|
+
else if (appearanceConfigRef.current &&
|
|
122
|
+
propsForDeviceKey in appearanceConfigRef.current) {
|
|
123
|
+
// Value for device from appearance config is third priority
|
|
124
|
+
targetPropsValue = appearanceConfigRef.current[propsForDeviceKey];
|
|
125
|
+
}
|
|
126
|
+
else if (appearanceConfigRef.current &&
|
|
127
|
+
propKey in appearanceConfigRef.current) {
|
|
128
|
+
// Value without device from appearance config is last priority
|
|
129
|
+
targetPropsValue = appearanceConfigRef.current[propKey];
|
|
130
|
+
}
|
|
131
|
+
// prettier-ignore
|
|
132
|
+
// const targetPropsValue = (
|
|
133
|
+
// // Value for device from props is first priority
|
|
134
|
+
// propsRef.current[propsForDeviceKey] ||
|
|
135
|
+
// // Value without device from props is second priority
|
|
136
|
+
// propsRef.current[propKey] ||
|
|
137
|
+
// // Value for device from appearance config is third priority
|
|
138
|
+
// appearanceConfigRef.current?.[propsForDeviceKey] ||
|
|
139
|
+
// // Value without device from appearance config is last priority
|
|
140
|
+
// appearanceConfigRef.current?.[propKey]
|
|
141
|
+
// )
|
|
142
|
+
return targetPropsValue;
|
|
143
|
+
},
|
|
144
|
+
// eslint-disable-next-line perfectionist/sort-objects
|
|
145
|
+
getClassName(propKey, params) {
|
|
146
|
+
let prefix = '';
|
|
147
|
+
let replace = defaultReplacePattern;
|
|
148
|
+
if (params) {
|
|
149
|
+
prefix = params.prefix ?? '';
|
|
150
|
+
replace = params.replace ?? defaultReplacePattern;
|
|
151
|
+
}
|
|
152
|
+
const targetClassValue = this.getProp(propKey);
|
|
153
|
+
if (!targetClassValue) {
|
|
154
|
+
// if (isClientEnv && isDevelopmentEnv) {
|
|
155
|
+
// window.__cache.cache_early_avoid_count += 1
|
|
156
|
+
// }
|
|
157
|
+
// If target key not exists in props and appearance config - return empty class
|
|
158
|
+
return '';
|
|
159
|
+
}
|
|
160
|
+
const stringifiedReplace = replace === defaultReplacePattern
|
|
161
|
+
? defaultStringifiedReplacePattern
|
|
162
|
+
: String(replace);
|
|
163
|
+
const cacheKey = `${prefix}_${stringifiedReplace}_${propKey}_${targetClassValue}`;
|
|
164
|
+
const cachedClassValue = cachedClassValueMapRef.current.get(cacheKey);
|
|
165
|
+
if (cachedClassValue !== undefined) {
|
|
166
|
+
// if (isClientEnv && isDevelopmentEnv) {
|
|
167
|
+
// window.__cache.cache_hit_count += 1
|
|
168
|
+
// }
|
|
169
|
+
return cachedClassValue;
|
|
170
|
+
}
|
|
171
|
+
// if (isClientEnv && isDevelopmentEnv) {
|
|
172
|
+
// window.__cache.cache_miss_count += 1
|
|
173
|
+
// }
|
|
174
|
+
if (styleAttributeKeysSet.has(propKey) &&
|
|
175
|
+
(typeof targetClassValue === 'number' ||
|
|
176
|
+
(typeof targetClassValue === 'string' &&
|
|
177
|
+
!isNaN(parseFloat(targetClassValue))))) {
|
|
178
|
+
const newClassValue = '';
|
|
179
|
+
cachedClassValueMapRef.current.set(cacheKey, newClassValue);
|
|
180
|
+
return newClassValue;
|
|
181
|
+
}
|
|
182
|
+
let cleanClassValue = String(targetClassValue);
|
|
183
|
+
if (!cleanClassValue.includes('.')) {
|
|
184
|
+
cleanClassValue = camelCase(cleanClassValue);
|
|
185
|
+
}
|
|
186
|
+
if (replace) {
|
|
187
|
+
const replaceList = castArray(replace);
|
|
188
|
+
cleanClassValue = cleanClassValue.replace(replaceList[0],
|
|
189
|
+
// @ts-expect-error
|
|
190
|
+
replaceList[1] || '');
|
|
191
|
+
}
|
|
192
|
+
const newClassValue = `${prefix}${cleanClassValue}`.toLowerCase();
|
|
193
|
+
cachedClassValueMapRef.current.set(cacheKey, newClassValue);
|
|
194
|
+
return newClassValue;
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
const generatorProxyHandler = {
|
|
198
|
+
get(target, propKey, receiver, ...args) {
|
|
199
|
+
if (typeof propKey === 'string') {
|
|
200
|
+
// If object does not have the property being retrieved
|
|
201
|
+
if (propKey !== 'getProp' && propKey !== 'getClassName') {
|
|
202
|
+
// if (isClientEnv && isDevelopmentEnv) {
|
|
203
|
+
// window.__cache.proxy_field_access_count += 1
|
|
204
|
+
// }
|
|
205
|
+
// And property ended on "Class" keyword
|
|
206
|
+
if (propKey.endsWith('Class')) {
|
|
207
|
+
// prettier-ignore
|
|
208
|
+
const shortProp = propKey.substring(0, propKey.lastIndexOf('Class'));
|
|
209
|
+
// Return prop from props for device as formatted class name
|
|
210
|
+
// prettier-ignore
|
|
211
|
+
return propsGenerator.getClassName(shortProp);
|
|
212
|
+
}
|
|
213
|
+
// Return prop from props for device
|
|
214
|
+
return propsGenerator.getProp(propKey);
|
|
215
|
+
}
|
|
216
|
+
// Return object property. Original "get".
|
|
217
|
+
// @ts-expect-error
|
|
218
|
+
return Reflect.get(target, propKey, receiver, ...args);
|
|
219
|
+
}
|
|
220
|
+
// In some cases, like in Chrome browser, sometime "prop" is not string.
|
|
221
|
+
// We return this object as is.
|
|
222
|
+
return propKey;
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
return new Proxy(propsGenerator, generatorProxyHandler);
|
|
226
|
+
// Proxy does not care about references, we can create proxy only once.
|
|
227
|
+
}, []);
|
|
228
|
+
return devicePropsGenerator;
|
|
229
|
+
}
|
|
230
|
+
const defaultReplacePattern = [/([A-Z])/g, '-$1'];
|
|
231
|
+
const defaultStringifiedReplacePattern = String(defaultReplacePattern);
|
|
232
|
+
const styleAttributeKeysSet = new Set(styleAttributes.map((attr) => getStyleAttributeKey(attr)));
|
|
233
|
+
|
|
234
|
+
export { useDevicePropsGenerator };
|
|
@@ -1 +1,62 @@
|
|
|
1
|
-
import{useMemo
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import camelCase from 'lodash/camelCase';
|
|
3
|
+
import castArray from 'lodash/castArray';
|
|
4
|
+
import '../context/Notifications.js';
|
|
5
|
+
import { useUserDeviceContext } from '../context/UIContext.js';
|
|
6
|
+
import '../context/UrlAssetPrefix.js';
|
|
7
|
+
import 'react/jsx-runtime';
|
|
8
|
+
import 'uuid';
|
|
9
|
+
import '@itcase/common';
|
|
10
|
+
import './useMediaQueries/useMediaQueries.js';
|
|
11
|
+
import 'react-responsive';
|
|
12
|
+
import '../utils/setViewportProperty.js';
|
|
13
|
+
|
|
14
|
+
/** TODO:
|
|
15
|
+
* Hook is still used in "itcase-forms".
|
|
16
|
+
* Need replace with "useDevicePropsGenerator" and delete this.
|
|
17
|
+
*/
|
|
18
|
+
function useDeviceTargetClass(componentProps, hookProps) {
|
|
19
|
+
/** Generate a class depending on the user's device.
|
|
20
|
+
*
|
|
21
|
+
* Usage:
|
|
22
|
+
* const sizeClass = useDeviceTargetClass(props, {
|
|
23
|
+
* prefix: 'some-item_size_',
|
|
24
|
+
* propsKey: 'size',
|
|
25
|
+
* })
|
|
26
|
+
* Return: "some-item_size_m" (or "s", or "l", or something else)
|
|
27
|
+
*
|
|
28
|
+
* "componentProps" - "props" from component
|
|
29
|
+
* "hookProps" - special props for generating class
|
|
30
|
+
**/
|
|
31
|
+
const {
|
|
32
|
+
prefix = '',
|
|
33
|
+
propsKey,
|
|
34
|
+
replace = [/([A-Z])/g, '-$1']
|
|
35
|
+
} = hookProps;
|
|
36
|
+
const {
|
|
37
|
+
isMobile,
|
|
38
|
+
isTablet,
|
|
39
|
+
isDesktop
|
|
40
|
+
} = useUserDeviceContext();
|
|
41
|
+
const targetClassValue = useMemo(() => {
|
|
42
|
+
// prettier-ignore
|
|
43
|
+
const deviceCurrentMainType = isMobile && 'Mobile' || isTablet && 'Tablet' || isDesktop && 'Desktop' || '';
|
|
44
|
+
const valueForDevice = componentProps[`${propsKey}${deviceCurrentMainType}`];
|
|
45
|
+
const valueDefault = componentProps[propsKey];
|
|
46
|
+
return valueForDevice || valueDefault;
|
|
47
|
+
}, [isMobile, isTablet, isDesktop, componentProps, propsKey]);
|
|
48
|
+
const targetClass = useMemo(() => {
|
|
49
|
+
if (targetClassValue) {
|
|
50
|
+
let cleanClassValue = camelCase(String(targetClassValue));
|
|
51
|
+
if (replace) {
|
|
52
|
+
const replaceList = castArray(replace);
|
|
53
|
+
cleanClassValue = cleanClassValue.replace(replaceList[0], replaceList[1] || '');
|
|
54
|
+
}
|
|
55
|
+
return `${prefix}${cleanClassValue}`.toLowerCase();
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}, [targetClassValue, prefix, replace]);
|
|
59
|
+
return targetClass;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { useDeviceTargetClass };
|
|
@@ -1 +1,122 @@
|
|
|
1
|
-
import{useMemo
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useMediaQuery } from 'react-responsive';
|
|
3
|
+
|
|
4
|
+
var tablet = "48em";
|
|
5
|
+
var mediaQueries = {
|
|
6
|
+
"mobile-tiny": "15em",
|
|
7
|
+
tablet: tablet,
|
|
8
|
+
"desktop-small": "60em",
|
|
9
|
+
"desktop-huge": "160em"
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const isSSR = typeof window === 'undefined';
|
|
13
|
+
function withUserDeviceOverride(hasOverride, userValue, matchedValue) {
|
|
14
|
+
return hasOverride ? Boolean(userValue) : matchedValue;
|
|
15
|
+
}
|
|
16
|
+
function useMediaQueries(userDevice = {}) {
|
|
17
|
+
const hasUserDeviceOverride = userDevice.isMobile === true || userDevice.isTablet === true || userDevice.isDesktop === true;
|
|
18
|
+
// const isWarning = useMediaQuery({ maxWidth: mediaQueries['mobile-tiny'] })
|
|
19
|
+
// prettier-ignore
|
|
20
|
+
const isMobile = withUserDeviceOverride(hasUserDeviceOverride, userDevice.isMobile, useMediaQuery({
|
|
21
|
+
minWidth: mediaQueries['mobile-tiny'],
|
|
22
|
+
maxWidth: mediaQueries['tablet']
|
|
23
|
+
}) || isSSR && Boolean(userDevice.isMobile));
|
|
24
|
+
// const isMobileTiny = useMediaQuery({
|
|
25
|
+
// minWidth: mediaQueries['mobile-tiny'],
|
|
26
|
+
// maxWidth: mediaQueries['mobile-small'],
|
|
27
|
+
// })
|
|
28
|
+
// const isMobileSmall = useMediaQuery({
|
|
29
|
+
// minWidth: mediaQueries['mobile-small'],
|
|
30
|
+
// maxWidth: mediaQueries['mobile-medium'],
|
|
31
|
+
// })
|
|
32
|
+
// const isMobileMedium = useMediaQuery({
|
|
33
|
+
// minWidth: mediaQueries['mobile-medium'],
|
|
34
|
+
// maxWidth: mediaQueries['mobile-normal'],
|
|
35
|
+
// })
|
|
36
|
+
// const isMobileNormal = useMediaQuery({
|
|
37
|
+
// minWidth: mediaQueries['mobile-normal'],
|
|
38
|
+
// maxWidth: mediaQueries['mobile-large'],
|
|
39
|
+
// })
|
|
40
|
+
// const isMobileStandart = useMediaQuery({
|
|
41
|
+
// minWidth: mediaQueries['mobile-large'],
|
|
42
|
+
// maxWidth: mediaQueries['mobile-extra-large'],
|
|
43
|
+
// })
|
|
44
|
+
// const isMobileLarge = useMediaQuery({
|
|
45
|
+
// minWidth: mediaQueries['mobile-extra-large'],
|
|
46
|
+
// maxWidth: mediaQueries['mobile-super-extra-large'],
|
|
47
|
+
// })
|
|
48
|
+
// const isMobileHuge = useMediaQuery({
|
|
49
|
+
// minWidth: mediaQueries['mobile-super-extra-large'],
|
|
50
|
+
// maxWidth: mediaQueries['tablet'],
|
|
51
|
+
// })
|
|
52
|
+
// prettier-ignore
|
|
53
|
+
const isTablet = withUserDeviceOverride(hasUserDeviceOverride, userDevice.isTablet, useMediaQuery({
|
|
54
|
+
minWidth: mediaQueries['tablet'],
|
|
55
|
+
maxWidth: mediaQueries['desktop-small']
|
|
56
|
+
}) || isSSR && Boolean(userDevice.isTablet));
|
|
57
|
+
// const isTabletSmall = useMediaQuery({
|
|
58
|
+
// minWidth: mediaQueries['tablet-small'],
|
|
59
|
+
// maxWidth: mediaQueries['tablet'],
|
|
60
|
+
// })
|
|
61
|
+
// const isTabletLarge = useMediaQuery({
|
|
62
|
+
// minWidth: mediaQueries['tablet'],
|
|
63
|
+
// maxWidth: mediaQueries['tablet-large'],
|
|
64
|
+
// })
|
|
65
|
+
// prettier-ignore
|
|
66
|
+
const isDesktop = withUserDeviceOverride(hasUserDeviceOverride, userDevice.isDesktop, useMediaQuery({
|
|
67
|
+
minWidth: mediaQueries['desktop-small'],
|
|
68
|
+
maxWidth: mediaQueries['desktop-super-huge']
|
|
69
|
+
}) || isSSR && Boolean(userDevice.isDesktop));
|
|
70
|
+
// const isDesktopSmall = useMediaQuery({
|
|
71
|
+
// minWidth: mediaQueries['desktop-small'],
|
|
72
|
+
// maxWidth: mediaQueries['desktop-medium'],
|
|
73
|
+
// })
|
|
74
|
+
// const isDesktopMedium = useMediaQuery({
|
|
75
|
+
// minWidth: mediaQueries['desktop-medium'],
|
|
76
|
+
// maxWidth: mediaQueries['desktop-normal'],
|
|
77
|
+
// })
|
|
78
|
+
// const isDesktopNormal = useMediaQuery({
|
|
79
|
+
// minWidth: mediaQueries['desktop-normal'],
|
|
80
|
+
// maxWidth: mediaQueries['desktop-large'],
|
|
81
|
+
// })
|
|
82
|
+
// const isDesktopStandart = useMediaQuery({
|
|
83
|
+
// minWidth: mediaQueries['desktop-large'],
|
|
84
|
+
// maxWidth: mediaQueries['desktop-extra-large'],
|
|
85
|
+
// })
|
|
86
|
+
// const isDesktopLarge = useMediaQuery({
|
|
87
|
+
// minWidth: mediaQueries['desktop-extra-large'],
|
|
88
|
+
// maxWidth: mediaQueries['desktop-super-extra-large'],
|
|
89
|
+
// })
|
|
90
|
+
// const isDesktopHuge = useMediaQuery({
|
|
91
|
+
// minWidth: mediaQueries['desktop-super-extra-large'],
|
|
92
|
+
// maxWidth: mediaQueries['desktop-huge'],
|
|
93
|
+
// })
|
|
94
|
+
const isDesktopMega = useMediaQuery({
|
|
95
|
+
minWidth: mediaQueries['desktop-huge']
|
|
96
|
+
});
|
|
97
|
+
const deviceTypes = useMemo(() => ({
|
|
98
|
+
// isWarning,
|
|
99
|
+
isMobile: isMobile,
|
|
100
|
+
// isMobileTiny,
|
|
101
|
+
// isMobileSmall,
|
|
102
|
+
// isMobileMedium,
|
|
103
|
+
// isMobileNormal,
|
|
104
|
+
// isMobileStandart,
|
|
105
|
+
// isMobileLarge,
|
|
106
|
+
isMobileHuge: isMobile,
|
|
107
|
+
isTablet: isTablet,
|
|
108
|
+
// isTabletSmall,
|
|
109
|
+
// isTabletLarge,
|
|
110
|
+
isDesktop: isDesktop,
|
|
111
|
+
// isDesktopSmall,
|
|
112
|
+
// isDesktopMedium,
|
|
113
|
+
// isDesktopNormal,
|
|
114
|
+
// isDesktopStandart,
|
|
115
|
+
// isDesktopLarge,
|
|
116
|
+
// isDesktopHuge,
|
|
117
|
+
isDesktopMega: isDesktopMega
|
|
118
|
+
}), [isMobile, isTablet, isDesktop, isDesktopMega]);
|
|
119
|
+
return deviceTypes;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { useMediaQueries };
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
export{getStyleAttributeKey}from
|
|
1
|
+
export { getStyleAttributeKey } from './styleAttributes.helpers.js';
|
|
2
|
+
export { useStyles } from './useStyles.js';
|
|
3
|
+
import 'react';
|
|
4
|
+
import 'lodash/camelCase';
|
|
5
|
+
import 'lodash/maxBy';
|
|
6
|
+
import 'lodash/upperFirst';
|
|
7
|
+
import '../../context/Notifications.js';
|
|
8
|
+
import 'react/jsx-runtime';
|
|
9
|
+
import 'uuid';
|
|
10
|
+
import '@itcase/common';
|
|
11
|
+
import '../../context/UIContext.js';
|
|
12
|
+
import '../useMediaQueries/useMediaQueries.js';
|
|
13
|
+
import 'react-responsive';
|
|
14
|
+
import '../../utils/setViewportProperty.js';
|
|
15
|
+
import '../../context/UrlAssetPrefix.js';
|
|
16
|
+
import './styleAttributes.js';
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const getStyleAttributeKey = (targetStyleAttribute) => {
|
|
2
|
+
return Array.isArray(targetStyleAttribute)
|
|
3
|
+
? targetStyleAttribute[0]
|
|
4
|
+
: targetStyleAttribute;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export { getStyleAttributeKey };
|