@etsoo/react 1.4.39 → 1.4.40
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/lib/mu/MUGlobal.d.ts +7 -0
- package/lib/mu/MUGlobal.js +12 -3
- package/lib/mu/ScrollerListEx.js +29 -23
- package/package.json +1 -1
- package/src/mu/MUGlobal.ts +14 -5
- package/src/mu/ScrollerListEx.tsx +43 -35
package/lib/mu/MUGlobal.d.ts
CHANGED
|
@@ -63,8 +63,15 @@ export declare class MUGlobal {
|
|
|
63
63
|
* @returns Updated object
|
|
64
64
|
*/
|
|
65
65
|
static adjustWithTheme(size: number, adjust: {}, updateFunc: (value: number) => string): {};
|
|
66
|
+
/**
|
|
67
|
+
* Break points defined
|
|
68
|
+
*/
|
|
69
|
+
static breakpoints: readonly ["xs", "sm", "md", "lg", "xl"];
|
|
66
70
|
/**
|
|
67
71
|
* Get multple medias theme space
|
|
72
|
+
* Responsive values and Breakpoints as an object
|
|
73
|
+
* xs = theme.breakpoints.up('xs')
|
|
74
|
+
* https://mui.com/system/basics/
|
|
68
75
|
* @param spaces Spaces
|
|
69
76
|
* @param theme Theme
|
|
70
77
|
* @returns Result
|
package/lib/mu/MUGlobal.js
CHANGED
|
@@ -72,14 +72,19 @@ export class MUGlobal {
|
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* Get multple medias theme space
|
|
75
|
+
* Responsive values and Breakpoints as an object
|
|
76
|
+
* xs = theme.breakpoints.up('xs')
|
|
77
|
+
* https://mui.com/system/basics/
|
|
75
78
|
* @param spaces Spaces
|
|
76
79
|
* @param theme Theme
|
|
77
80
|
* @returns Result
|
|
78
81
|
*/
|
|
79
82
|
static getSpace(spaces, theme) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
const start = this.breakpoints.length - 1;
|
|
84
|
+
for (let i = start; i >= 0; i--) {
|
|
85
|
+
const key = this.breakpoints[i];
|
|
86
|
+
const value = Reflect.get(spaces, key);
|
|
87
|
+
if (typeof value === 'number') {
|
|
83
88
|
const mediaRaw = theme.breakpoints.up(key);
|
|
84
89
|
const mediaQuery = mediaRaw.substring(mediaRaw.indexOf('('));
|
|
85
90
|
if (window.matchMedia(mediaQuery).matches) {
|
|
@@ -137,3 +142,7 @@ MUGlobal.textFieldVariant = 'filled';
|
|
|
137
142
|
* Page default paddings
|
|
138
143
|
*/
|
|
139
144
|
MUGlobal.pagePaddings = { xs: 2, sm: 3 };
|
|
145
|
+
/**
|
|
146
|
+
* Break points defined
|
|
147
|
+
*/
|
|
148
|
+
MUGlobal.breakpoints = ['xs', 'sm', 'md', 'lg', 'xl'];
|
package/lib/mu/ScrollerListEx.js
CHANGED
|
@@ -111,18 +111,25 @@ export function ScrollerListEx(props) {
|
|
|
111
111
|
: false;
|
|
112
112
|
return selected;
|
|
113
113
|
};
|
|
114
|
+
// Destruct
|
|
115
|
+
const { alternatingColors = [undefined, undefined], className, idField = 'id', innerItemRenderer, itemSize, itemKey = (index, data) => { var _a; return (_a = DataTypes.getIdValue(data, idField)) !== null && _a !== void 0 ? _a : index; }, itemRenderer = (itemProps) => {
|
|
116
|
+
const [itemHeight, space, margins] = calculateItemSize(itemProps.index);
|
|
117
|
+
return defaultItemRenderer({
|
|
118
|
+
itemHeight,
|
|
119
|
+
innerItemRenderer,
|
|
120
|
+
onMouseDown,
|
|
121
|
+
space,
|
|
122
|
+
margins,
|
|
123
|
+
selected: isSelected(itemProps.data),
|
|
124
|
+
...itemProps
|
|
125
|
+
});
|
|
126
|
+
}, onSelectChange, selectedColor = '#edf4fb', ...rest } = props;
|
|
114
127
|
// Theme
|
|
115
128
|
const theme = useTheme();
|
|
116
|
-
//
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const result = itemSize(index);
|
|
121
|
-
if (result.length == 2)
|
|
122
|
-
return [...result, defaultMargin(MUGlobal.pagePaddings)];
|
|
123
|
-
return result;
|
|
124
|
-
}
|
|
125
|
-
// Calculation
|
|
129
|
+
// Cache calculation
|
|
130
|
+
const itemSizeResult = React.useMemo(() => {
|
|
131
|
+
if (typeof itemSize === 'function')
|
|
132
|
+
return undefined;
|
|
126
133
|
const [size, spaces, isNarrow] = itemSize;
|
|
127
134
|
if (typeof spaces === 'number')
|
|
128
135
|
return [
|
|
@@ -135,25 +142,24 @@ export function ScrollerListEx(props) {
|
|
|
135
142
|
MUGlobal.getSpace(spaces, theme),
|
|
136
143
|
defaultMargin(spaces, isNarrow)
|
|
137
144
|
];
|
|
145
|
+
}, [itemSize]);
|
|
146
|
+
// Calculate size
|
|
147
|
+
const calculateItemSize = (index) => {
|
|
148
|
+
// Callback function
|
|
149
|
+
if (typeof itemSize === 'function') {
|
|
150
|
+
const result = itemSize(index);
|
|
151
|
+
if (result.length == 2)
|
|
152
|
+
return [...result, defaultMargin(MUGlobal.pagePaddings)];
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
// Calculation
|
|
156
|
+
return itemSizeResult;
|
|
138
157
|
};
|
|
139
158
|
// Local item size
|
|
140
159
|
const itemSizeLocal = (index) => {
|
|
141
160
|
const [size, space] = calculateItemSize(index);
|
|
142
161
|
return size + space;
|
|
143
162
|
};
|
|
144
|
-
// Destruct
|
|
145
|
-
const { alternatingColors = [undefined, undefined], className, idField = 'id', innerItemRenderer, itemSize, itemKey = (index, data) => { var _a; return (_a = DataTypes.getIdValue(data, idField)) !== null && _a !== void 0 ? _a : index; }, itemRenderer = (itemProps) => {
|
|
146
|
-
const [itemHeight, space, margins] = calculateItemSize(itemProps.index);
|
|
147
|
-
return defaultItemRenderer({
|
|
148
|
-
itemHeight,
|
|
149
|
-
innerItemRenderer,
|
|
150
|
-
onMouseDown,
|
|
151
|
-
space,
|
|
152
|
-
margins,
|
|
153
|
-
selected: isSelected(itemProps.data),
|
|
154
|
-
...itemProps
|
|
155
|
-
});
|
|
156
|
-
}, onSelectChange, selectedColor = '#edf4fb', ...rest } = props;
|
|
157
163
|
// Layout
|
|
158
164
|
return (React.createElement(ScrollerList, { className: Utils.mergeClasses('ScrollerListEx-Body', className, createGridStyle(alternatingColors, selectedColor)), itemKey: itemKey, itemRenderer: itemRenderer, itemSize: itemSizeLocal, ...rest }));
|
|
159
165
|
}
|
package/package.json
CHANGED
package/src/mu/MUGlobal.ts
CHANGED
|
@@ -126,18 +126,26 @@ export class MUGlobal {
|
|
|
126
126
|
return newObj;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Break points defined
|
|
131
|
+
*/
|
|
132
|
+
static breakpoints = ['xs', 'sm', 'md', 'lg', 'xl'] as const;
|
|
133
|
+
|
|
129
134
|
/**
|
|
130
135
|
* Get multple medias theme space
|
|
136
|
+
* Responsive values and Breakpoints as an object
|
|
137
|
+
* xs = theme.breakpoints.up('xs')
|
|
138
|
+
* https://mui.com/system/basics/
|
|
131
139
|
* @param spaces Spaces
|
|
132
140
|
* @param theme Theme
|
|
133
141
|
* @returns Result
|
|
134
142
|
*/
|
|
135
143
|
static getSpace(spaces: {}, theme: Theme) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
) {
|
|
144
|
+
const start = this.breakpoints.length - 1;
|
|
145
|
+
for (let i = start; i >= 0; i--) {
|
|
146
|
+
const key = this.breakpoints[i];
|
|
147
|
+
const value = Reflect.get(spaces, key);
|
|
148
|
+
if (typeof value === 'number') {
|
|
141
149
|
const mediaRaw = theme.breakpoints.up(key as Breakpoint);
|
|
142
150
|
const mediaQuery = mediaRaw.substring(mediaRaw.indexOf('('));
|
|
143
151
|
if (window.matchMedia(mediaQuery).matches) {
|
|
@@ -145,6 +153,7 @@ export class MUGlobal {
|
|
|
145
153
|
}
|
|
146
154
|
}
|
|
147
155
|
}
|
|
156
|
+
|
|
148
157
|
return 0;
|
|
149
158
|
}
|
|
150
159
|
|
|
@@ -265,41 +265,6 @@ export function ScrollerListEx<T extends Record<string, unknown>>(
|
|
|
265
265
|
return selected;
|
|
266
266
|
};
|
|
267
267
|
|
|
268
|
-
// Theme
|
|
269
|
-
const theme = useTheme();
|
|
270
|
-
|
|
271
|
-
// Calculate size
|
|
272
|
-
const calculateItemSize = (index: number): [number, number, {}] => {
|
|
273
|
-
// Callback function
|
|
274
|
-
if (typeof itemSize === 'function') {
|
|
275
|
-
const result = itemSize(index);
|
|
276
|
-
if (result.length == 2)
|
|
277
|
-
return [...result, defaultMargin(MUGlobal.pagePaddings)];
|
|
278
|
-
return result;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// Calculation
|
|
282
|
-
const [size, spaces, isNarrow] = itemSize;
|
|
283
|
-
if (typeof spaces === 'number')
|
|
284
|
-
return [
|
|
285
|
-
size,
|
|
286
|
-
spaces,
|
|
287
|
-
defaultMargin(MUGlobal.pagePaddings, undefined)
|
|
288
|
-
];
|
|
289
|
-
|
|
290
|
-
return [
|
|
291
|
-
size,
|
|
292
|
-
MUGlobal.getSpace(spaces, theme),
|
|
293
|
-
defaultMargin(spaces, isNarrow)
|
|
294
|
-
];
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
// Local item size
|
|
298
|
-
const itemSizeLocal = (index: number) => {
|
|
299
|
-
const [size, space] = calculateItemSize(index);
|
|
300
|
-
return size + space;
|
|
301
|
-
};
|
|
302
|
-
|
|
303
268
|
// Destruct
|
|
304
269
|
const {
|
|
305
270
|
alternatingColors = [undefined, undefined],
|
|
@@ -328,6 +293,49 @@ export function ScrollerListEx<T extends Record<string, unknown>>(
|
|
|
328
293
|
...rest
|
|
329
294
|
} = props;
|
|
330
295
|
|
|
296
|
+
// Theme
|
|
297
|
+
const theme = useTheme();
|
|
298
|
+
|
|
299
|
+
// Cache calculation
|
|
300
|
+
const itemSizeResult = React.useMemo(():
|
|
301
|
+
| [number, number, {}]
|
|
302
|
+
| undefined => {
|
|
303
|
+
if (typeof itemSize === 'function') return undefined;
|
|
304
|
+
const [size, spaces, isNarrow] = itemSize;
|
|
305
|
+
if (typeof spaces === 'number')
|
|
306
|
+
return [
|
|
307
|
+
size,
|
|
308
|
+
spaces,
|
|
309
|
+
defaultMargin(MUGlobal.pagePaddings, undefined)
|
|
310
|
+
];
|
|
311
|
+
|
|
312
|
+
return [
|
|
313
|
+
size,
|
|
314
|
+
MUGlobal.getSpace(spaces, theme),
|
|
315
|
+
defaultMargin(spaces, isNarrow)
|
|
316
|
+
];
|
|
317
|
+
}, [itemSize]);
|
|
318
|
+
|
|
319
|
+
// Calculate size
|
|
320
|
+
const calculateItemSize = (index: number): [number, number, {}] => {
|
|
321
|
+
// Callback function
|
|
322
|
+
if (typeof itemSize === 'function') {
|
|
323
|
+
const result = itemSize(index);
|
|
324
|
+
if (result.length == 2)
|
|
325
|
+
return [...result, defaultMargin(MUGlobal.pagePaddings)];
|
|
326
|
+
return result;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Calculation
|
|
330
|
+
return itemSizeResult!;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
// Local item size
|
|
334
|
+
const itemSizeLocal = (index: number) => {
|
|
335
|
+
const [size, space] = calculateItemSize(index);
|
|
336
|
+
return size + space;
|
|
337
|
+
};
|
|
338
|
+
|
|
331
339
|
// Layout
|
|
332
340
|
return (
|
|
333
341
|
<ScrollerList<T>
|