@etsoo/react 1.5.78 → 1.5.81
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/README.md +7 -2
- package/__tests__/ReactUtils.ts +6 -0
- package/lib/{mu → components}/DnDList.d.ts +1 -14
- package/lib/{mu → components}/DnDList.js +1 -24
- package/lib/components/GridMethodRef.d.ts +11 -0
- package/lib/{mu → components}/GridMethodRef.js +0 -0
- package/lib/components/ScrollerGrid.d.ts +6 -6
- package/lib/components/ScrollerList.d.ts +3 -3
- package/lib/index.d.ts +2 -74
- package/lib/index.js +2 -75
- package/lib/notifier/Notifier.d.ts +2 -3
- package/lib/uses/useWindowScroll.d.ts +10 -0
- package/lib/uses/useWindowScroll.js +46 -0
- package/lib/uses/useWindowSize.js +11 -5
- package/package.json +9 -21
- package/src/{mu → components}/DnDList.tsx +11 -34
- package/src/components/GridMethodRef.ts +12 -0
- package/src/components/ScrollerGrid.tsx +6 -6
- package/src/components/ScrollerList.tsx +5 -3
- package/src/index.ts +2 -78
- package/src/notifier/Notifier.ts +2 -3
- package/src/uses/useWindowScroll.ts +60 -0
- package/src/uses/useWindowSize.ts +14 -5
- package/__tests__/mu/MUGlobalTests.tsx +0 -58
- package/__tests__/mu/NotifierMUTests.tsx +0 -213
- package/lib/app/CommonApp.d.ts +0 -39
- package/lib/app/CommonApp.js +0 -149
- package/lib/app/IServiceAppSettings.d.ts +0 -11
- package/lib/app/IServiceAppSettings.js +0 -1
- package/lib/app/IServicePage.d.ts +0 -6
- package/lib/app/IServicePage.js +0 -1
- package/lib/app/IServiceUser.d.ts +0 -14
- package/lib/app/IServiceUser.js +0 -1
- package/lib/app/ISmartERPUser.d.ts +0 -14
- package/lib/app/ISmartERPUser.js +0 -1
- package/lib/app/Labels.d.ts +0 -65
- package/lib/app/Labels.js +0 -62
- package/lib/app/ReactApp.d.ts +0 -194
- package/lib/app/ReactApp.js +0 -298
- package/lib/app/ServiceApp.d.ts +0 -78
- package/lib/app/ServiceApp.js +0 -244
- package/lib/components/ShowDataComparison.d.ts +0 -20
- package/lib/components/ShowDataComparison.js +0 -60
- package/lib/mu/AuditDisplay.d.ts +0 -33
- package/lib/mu/AuditDisplay.js +0 -52
- package/lib/mu/AutocompleteExtendedProps.d.ts +0 -66
- package/lib/mu/AutocompleteExtendedProps.js +0 -1
- package/lib/mu/BackButton.d.ts +0 -13
- package/lib/mu/BackButton.js +0 -33
- package/lib/mu/BridgeCloseButton.d.ts +0 -23
- package/lib/mu/BridgeCloseButton.js +0 -32
- package/lib/mu/ButtonLink.d.ts +0 -17
- package/lib/mu/ButtonLink.js +0 -19
- package/lib/mu/ComboBox.d.ts +0 -40
- package/lib/mu/ComboBox.js +0 -108
- package/lib/mu/CountdownButton.d.ts +0 -23
- package/lib/mu/CountdownButton.js +0 -81
- package/lib/mu/CustomFabProps.d.ts +0 -27
- package/lib/mu/CustomFabProps.js +0 -1
- package/lib/mu/DataGridEx.d.ts +0 -96
- package/lib/mu/DataGridEx.js +0 -331
- package/lib/mu/DataGridRenderers.d.ts +0 -22
- package/lib/mu/DataGridRenderers.js +0 -99
- package/lib/mu/DialogButton.d.ts +0 -54
- package/lib/mu/DialogButton.js +0 -45
- package/lib/mu/DraggablePaperComponent.d.ts +0 -8
- package/lib/mu/DraggablePaperComponent.js +0 -12
- package/lib/mu/EmailInput.d.ts +0 -11
- package/lib/mu/EmailInput.js +0 -15
- package/lib/mu/FabBox.d.ts +0 -21
- package/lib/mu/FabBox.js +0 -31
- package/lib/mu/FlexBox.d.ts +0 -14
- package/lib/mu/FlexBox.js +0 -18
- package/lib/mu/GridDataFormat.d.ts +0 -10
- package/lib/mu/GridDataFormat.js +0 -43
- package/lib/mu/GridMethodRef.d.ts +0 -11
- package/lib/mu/IconButtonLink.d.ts +0 -17
- package/lib/mu/IconButtonLink.js +0 -16
- package/lib/mu/InputField.d.ts +0 -21
- package/lib/mu/InputField.js +0 -39
- package/lib/mu/ItemList.d.ts +0 -55
- package/lib/mu/ItemList.js +0 -77
- package/lib/mu/ListItemRightIcon.d.ts +0 -4
- package/lib/mu/ListItemRightIcon.js +0 -8
- package/lib/mu/ListMoreDisplay.d.ts +0 -35
- package/lib/mu/ListMoreDisplay.js +0 -99
- package/lib/mu/LoadingButton.d.ts +0 -16
- package/lib/mu/LoadingButton.js +0 -41
- package/lib/mu/MUGlobal.d.ts +0 -102
- package/lib/mu/MUGlobal.js +0 -184
- package/lib/mu/MaskInput.d.ts +0 -34
- package/lib/mu/MaskInput.js +0 -43
- package/lib/mu/MobileListItemRenderer.d.ts +0 -17
- package/lib/mu/MobileListItemRenderer.js +0 -35
- package/lib/mu/MoreFab.d.ts +0 -45
- package/lib/mu/MoreFab.js +0 -95
- package/lib/mu/NotifierMU.d.ts +0 -47
- package/lib/mu/NotifierMU.js +0 -387
- package/lib/mu/NotifierPromptProps.d.ts +0 -22
- package/lib/mu/NotifierPromptProps.js +0 -1
- package/lib/mu/OptionGroup.d.ts +0 -62
- package/lib/mu/OptionGroup.js +0 -81
- package/lib/mu/PList.d.ts +0 -15
- package/lib/mu/PList.js +0 -12
- package/lib/mu/ProgressCount.d.ts +0 -44
- package/lib/mu/ProgressCount.js +0 -79
- package/lib/mu/PullToRefreshUI.d.ts +0 -9
- package/lib/mu/PullToRefreshUI.js +0 -18
- package/lib/mu/RLink.d.ts +0 -14
- package/lib/mu/RLink.js +0 -37
- package/lib/mu/ResponsibleContainer.d.ts +0 -89
- package/lib/mu/ResponsibleContainer.js +0 -159
- package/lib/mu/ScrollTopFab.d.ts +0 -7
- package/lib/mu/ScrollTopFab.js +0 -25
- package/lib/mu/ScrollerListEx.d.ts +0 -81
- package/lib/mu/ScrollerListEx.js +0 -167
- package/lib/mu/SearchBar.d.ts +0 -29
- package/lib/mu/SearchBar.js +0 -262
- package/lib/mu/SearchField.d.ts +0 -21
- package/lib/mu/SearchField.js +0 -39
- package/lib/mu/SearchOptionGroup.d.ts +0 -9
- package/lib/mu/SearchOptionGroup.js +0 -14
- package/lib/mu/SelectBool.d.ts +0 -14
- package/lib/mu/SelectBool.js +0 -22
- package/lib/mu/SelectEx.d.ts +0 -54
- package/lib/mu/SelectEx.js +0 -156
- package/lib/mu/Switch.d.ts +0 -29
- package/lib/mu/Switch.js +0 -34
- package/lib/mu/SwitchAnt.d.ts +0 -25
- package/lib/mu/SwitchAnt.js +0 -40
- package/lib/mu/TabBox.d.ts +0 -54
- package/lib/mu/TabBox.js +0 -31
- package/lib/mu/TableEx.d.ts +0 -68
- package/lib/mu/TableEx.js +0 -271
- package/lib/mu/TextFieldEx.d.ts +0 -101
- package/lib/mu/TextFieldEx.js +0 -127
- package/lib/mu/Tiplist.d.ts +0 -18
- package/lib/mu/Tiplist.js +0 -158
- package/lib/mu/TooltipClick.d.ts +0 -15
- package/lib/mu/TooltipClick.js +0 -40
- package/lib/mu/UserAvatar.d.ts +0 -24
- package/lib/mu/UserAvatar.js +0 -25
- package/lib/mu/UserAvatarEditor.d.ts +0 -53
- package/lib/mu/UserAvatarEditor.js +0 -129
- package/lib/mu/pages/CommonPage.d.ts +0 -11
- package/lib/mu/pages/CommonPage.js +0 -60
- package/lib/mu/pages/CommonPageProps.d.ts +0 -60
- package/lib/mu/pages/CommonPageProps.js +0 -1
- package/lib/mu/pages/DataGridPage.d.ts +0 -9
- package/lib/mu/pages/DataGridPage.js +0 -81
- package/lib/mu/pages/DataGridPageProps.d.ts +0 -17
- package/lib/mu/pages/DataGridPageProps.js +0 -1
- package/lib/mu/pages/EditPage.d.ts +0 -33
- package/lib/mu/pages/EditPage.js +0 -29
- package/lib/mu/pages/FixedListPage.d.ts +0 -15
- package/lib/mu/pages/FixedListPage.js +0 -72
- package/lib/mu/pages/ListPage.d.ts +0 -9
- package/lib/mu/pages/ListPage.js +0 -51
- package/lib/mu/pages/ListPageProps.d.ts +0 -7
- package/lib/mu/pages/ListPageProps.js +0 -1
- package/lib/mu/pages/ResponsivePage.d.ts +0 -9
- package/lib/mu/pages/ResponsivePage.js +0 -45
- package/lib/mu/pages/ResponsivePageProps.d.ts +0 -39
- package/lib/mu/pages/ResponsivePageProps.js +0 -1
- package/lib/mu/pages/SearchPageProps.d.ts +0 -30
- package/lib/mu/pages/SearchPageProps.js +0 -1
- package/lib/mu/pages/TablePage.d.ts +0 -9
- package/lib/mu/pages/TablePage.js +0 -71
- package/lib/mu/pages/TablePageProps.d.ts +0 -7
- package/lib/mu/pages/TablePageProps.js +0 -1
- package/lib/mu/pages/ViewPage.d.ts +0 -66
- package/lib/mu/pages/ViewPage.js +0 -105
- package/lib/mu/texts/DateText.d.ts +0 -34
- package/lib/mu/texts/DateText.js +0 -25
- package/lib/mu/texts/MoneyText.d.ts +0 -21
- package/lib/mu/texts/MoneyText.js +0 -14
- package/lib/mu/texts/NumberText.d.ts +0 -25
- package/lib/mu/texts/NumberText.js +0 -14
- package/src/app/CommonApp.ts +0 -225
- package/src/app/IServiceAppSettings.ts +0 -13
- package/src/app/IServicePage.ts +0 -6
- package/src/app/IServiceUser.ts +0 -17
- package/src/app/ISmartERPUser.ts +0 -16
- package/src/app/Labels.ts +0 -77
- package/src/app/ReactApp.ts +0 -500
- package/src/app/ServiceApp.ts +0 -353
- package/src/components/ShowDataComparison.tsx +0 -108
- package/src/mu/AuditDisplay.tsx +0 -117
- package/src/mu/AutocompleteExtendedProps.ts +0 -84
- package/src/mu/BackButton.tsx +0 -55
- package/src/mu/BridgeCloseButton.tsx +0 -69
- package/src/mu/ButtonLink.tsx +0 -32
- package/src/mu/ComboBox.tsx +0 -244
- package/src/mu/CountdownButton.tsx +0 -119
- package/src/mu/CustomFabProps.ts +0 -32
- package/src/mu/DataGridEx.tsx +0 -712
- package/src/mu/DataGridRenderers.tsx +0 -140
- package/src/mu/DialogButton.tsx +0 -163
- package/src/mu/DraggablePaperComponent.tsx +0 -19
- package/src/mu/EmailInput.tsx +0 -24
- package/src/mu/FabBox.tsx +0 -51
- package/src/mu/FlexBox.tsx +0 -20
- package/src/mu/GridDataFormat.tsx +0 -77
- package/src/mu/GridMethodRef.ts +0 -12
- package/src/mu/IconButtonLink.tsx +0 -29
- package/src/mu/InputField.tsx +0 -82
- package/src/mu/ItemList.tsx +0 -201
- package/src/mu/ListItemRightIcon.tsx +0 -9
- package/src/mu/ListMoreDisplay.tsx +0 -205
- package/src/mu/LoadingButton.tsx +0 -75
- package/src/mu/MUGlobal.ts +0 -220
- package/src/mu/MaskInput.tsx +0 -107
- package/src/mu/MobileListItemRenderer.tsx +0 -79
- package/src/mu/MoreFab.tsx +0 -211
- package/src/mu/NotifierMU.tsx +0 -654
- package/src/mu/NotifierPromptProps.ts +0 -26
- package/src/mu/OptionGroup.tsx +0 -218
- package/src/mu/PList.tsx +0 -27
- package/src/mu/ProgressCount.tsx +0 -166
- package/src/mu/PullToRefreshUI.tsx +0 -21
- package/src/mu/RLink.tsx +0 -64
- package/src/mu/ResponsibleContainer.tsx +0 -394
- package/src/mu/ScrollTopFab.tsx +0 -34
- package/src/mu/ScrollerListEx.tsx +0 -387
- package/src/mu/SearchBar.tsx +0 -398
- package/src/mu/SearchField.tsx +0 -82
- package/src/mu/SearchOptionGroup.tsx +0 -25
- package/src/mu/SelectBool.tsx +0 -40
- package/src/mu/SelectEx.tsx +0 -285
- package/src/mu/Switch.tsx +0 -94
- package/src/mu/SwitchAnt.tsx +0 -95
- package/src/mu/TabBox.tsx +0 -118
- package/src/mu/TableEx.tsx +0 -561
- package/src/mu/TextFieldEx.tsx +0 -250
- package/src/mu/Tiplist.tsx +0 -304
- package/src/mu/TooltipClick.tsx +0 -84
- package/src/mu/UserAvatar.tsx +0 -64
- package/src/mu/UserAvatarEditor.tsx +0 -287
- package/src/mu/pages/CommonPage.tsx +0 -128
- package/src/mu/pages/CommonPageProps.ts +0 -71
- package/src/mu/pages/DataGridPage.tsx +0 -137
- package/src/mu/pages/DataGridPageProps.ts +0 -24
- package/src/mu/pages/EditPage.tsx +0 -114
- package/src/mu/pages/FixedListPage.tsx +0 -134
- package/src/mu/pages/ListPage.tsx +0 -86
- package/src/mu/pages/ListPageProps.ts +0 -11
- package/src/mu/pages/ResponsivePage.tsx +0 -68
- package/src/mu/pages/ResponsivePageProps.ts +0 -57
- package/src/mu/pages/SearchPageProps.ts +0 -39
- package/src/mu/pages/TablePage.tsx +0 -119
- package/src/mu/pages/TablePageProps.ts +0 -11
- package/src/mu/pages/ViewPage.tsx +0 -285
- package/src/mu/texts/DateText.tsx +0 -74
- package/src/mu/texts/MoneyText.tsx +0 -49
- package/src/mu/texts/NumberText.tsx +0 -40
package/src/mu/SearchBar.tsx
DELETED
|
@@ -1,398 +0,0 @@
|
|
|
1
|
-
import { Button, Drawer, IconButton, Stack, useTheme } from '@mui/material';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
|
4
|
-
import { useDimensions } from '../uses/useDimensions';
|
|
5
|
-
import { DomUtils } from '@etsoo/shared';
|
|
6
|
-
import { Labels } from '../app/Labels';
|
|
7
|
-
import { ReactUtils } from '../app/ReactUtils';
|
|
8
|
-
import { useDelayedExecutor } from '..';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Search bar props
|
|
12
|
-
*/
|
|
13
|
-
export interface SearchBarProps {
|
|
14
|
-
/**
|
|
15
|
-
* Style class name
|
|
16
|
-
*/
|
|
17
|
-
className?: string;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Fields
|
|
21
|
-
*/
|
|
22
|
-
fields: React.ReactElement[];
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Inner height
|
|
26
|
-
* @default 40
|
|
27
|
-
*/
|
|
28
|
-
innerHeight?: number;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* On submit callback
|
|
32
|
-
*/
|
|
33
|
-
onSubmit: (data: FormData, reset: boolean) => void | PromiseLike<void>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Cached width attribute name
|
|
37
|
-
const cachedWidthName: string = 'data-cached-width';
|
|
38
|
-
|
|
39
|
-
// Reset form
|
|
40
|
-
const resetForm = (form: HTMLFormElement) => {
|
|
41
|
-
for (const input of form.elements) {
|
|
42
|
-
// Ignore disabled inputs
|
|
43
|
-
if ('disabled' in input && (input as any).disabled) continue;
|
|
44
|
-
|
|
45
|
-
// All non hidden inputs
|
|
46
|
-
if (input instanceof HTMLInputElement) {
|
|
47
|
-
// Ignore hidden input
|
|
48
|
-
if (input.type === 'hidden') continue;
|
|
49
|
-
|
|
50
|
-
// Ignore readOnly without data-reset=true inputs
|
|
51
|
-
if (!input.readOnly || input.dataset.reset === 'true') {
|
|
52
|
-
ReactUtils.triggerChange(input, '', true);
|
|
53
|
-
}
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// All selects
|
|
58
|
-
if (input instanceof HTMLSelectElement) {
|
|
59
|
-
if (input.options.length > 0 && input.options[0].value === '') {
|
|
60
|
-
input.selectedIndex = 0;
|
|
61
|
-
} else {
|
|
62
|
-
input.selectedIndex = -1;
|
|
63
|
-
}
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Trigger reset event
|
|
69
|
-
const resetEvent = new Event('reset');
|
|
70
|
-
form.dispatchEvent(resetEvent);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// Disable inputs avoid auto trigger change events for them
|
|
74
|
-
const setChildState = (child: Element, enabled: boolean) => {
|
|
75
|
-
const inputs = child.getElementsByTagName('input');
|
|
76
|
-
for (const input of inputs) {
|
|
77
|
-
input.disabled = !enabled;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Search bar
|
|
83
|
-
* @param props Props
|
|
84
|
-
* @returns Component
|
|
85
|
-
*/
|
|
86
|
-
export function SearchBar(props: SearchBarProps) {
|
|
87
|
-
// Destruct
|
|
88
|
-
const { className, fields, innerHeight = 40, onSubmit } = props;
|
|
89
|
-
|
|
90
|
-
// Labels
|
|
91
|
-
const labels = Labels.CommonPage;
|
|
92
|
-
|
|
93
|
-
// Spacing
|
|
94
|
-
const theme = useTheme();
|
|
95
|
-
const gap = parseFloat(theme.spacing(1));
|
|
96
|
-
|
|
97
|
-
// Menu index
|
|
98
|
-
const [index, updateIndex] = React.useState<number>();
|
|
99
|
-
|
|
100
|
-
// Drawer open / close
|
|
101
|
-
const [open, updateOpen] = React.useState(false);
|
|
102
|
-
|
|
103
|
-
// State
|
|
104
|
-
const state = React.useRef<{
|
|
105
|
-
form?: HTMLFormElement;
|
|
106
|
-
moreForm?: HTMLFormElement;
|
|
107
|
-
lastMaxWidth: number;
|
|
108
|
-
hasMore: boolean;
|
|
109
|
-
}>({ hasMore: true, lastMaxWidth: 9999 }).current;
|
|
110
|
-
|
|
111
|
-
// Watch container
|
|
112
|
-
const { dimensions } = useDimensions(
|
|
113
|
-
1,
|
|
114
|
-
(target, rect) => {
|
|
115
|
-
// Same logic from resetButtonRef
|
|
116
|
-
if (
|
|
117
|
-
rect.width === state.lastMaxWidth ||
|
|
118
|
-
(!state.hasMore && rect.width > state.lastMaxWidth)
|
|
119
|
-
)
|
|
120
|
-
return false;
|
|
121
|
-
|
|
122
|
-
// Len
|
|
123
|
-
const len = target.children.length;
|
|
124
|
-
for (let i = 0; i < len; i++) {
|
|
125
|
-
var classList = target.children[i].classList;
|
|
126
|
-
classList.remove('showChild');
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
0
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
// Show or hide element
|
|
133
|
-
const setElementVisible = (element: Element, visible: boolean) => {
|
|
134
|
-
element.classList.remove(visible ? 'hiddenChild' : 'showChild');
|
|
135
|
-
element.classList.add(visible ? 'showChild' : 'hiddenChild');
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
// Reset button ref
|
|
139
|
-
const resetButtonRef = (instance: HTMLButtonElement) => {
|
|
140
|
-
// Reset button
|
|
141
|
-
const resetButton = instance;
|
|
142
|
-
if (resetButton == null) return;
|
|
143
|
-
|
|
144
|
-
// First
|
|
145
|
-
const [_, container, containerRect] = dimensions[0];
|
|
146
|
-
if (
|
|
147
|
-
container == null ||
|
|
148
|
-
containerRect == null ||
|
|
149
|
-
containerRect.width < 10
|
|
150
|
-
)
|
|
151
|
-
return;
|
|
152
|
-
|
|
153
|
-
// Container width
|
|
154
|
-
let maxWidth = containerRect.width;
|
|
155
|
-
if (
|
|
156
|
-
maxWidth === state.lastMaxWidth ||
|
|
157
|
-
(!state.hasMore && maxWidth > state.lastMaxWidth)
|
|
158
|
-
) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
state.lastMaxWidth = maxWidth;
|
|
162
|
-
|
|
163
|
-
// More button
|
|
164
|
-
const buttonMore = resetButton.previousElementSibling!;
|
|
165
|
-
|
|
166
|
-
// Cached button width
|
|
167
|
-
const cachedButtonWidth = container.getAttribute(cachedWidthName);
|
|
168
|
-
if (cachedButtonWidth) {
|
|
169
|
-
maxWidth -= Number.parseFloat(cachedButtonWidth);
|
|
170
|
-
} else {
|
|
171
|
-
// Reset button rect
|
|
172
|
-
const resetButtonRect = resetButton.getBoundingClientRect();
|
|
173
|
-
|
|
174
|
-
// More button rect
|
|
175
|
-
const buttonMoreRect = buttonMore.getBoundingClientRect();
|
|
176
|
-
|
|
177
|
-
// Total
|
|
178
|
-
const totalButtonWidth =
|
|
179
|
-
resetButtonRect.width + buttonMoreRect.width + 3 * gap;
|
|
180
|
-
|
|
181
|
-
// Cache
|
|
182
|
-
container.setAttribute(
|
|
183
|
-
cachedWidthName,
|
|
184
|
-
totalButtonWidth.toString()
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
maxWidth -= totalButtonWidth;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Children
|
|
191
|
-
const children = container.children;
|
|
192
|
-
|
|
193
|
-
// Len
|
|
194
|
-
const len = children.length;
|
|
195
|
-
|
|
196
|
-
// Other elements
|
|
197
|
-
const others = len - 2;
|
|
198
|
-
let hasMore = false;
|
|
199
|
-
let newIndex: number = others;
|
|
200
|
-
for (let c: number = 0; c < others; c++) {
|
|
201
|
-
const child = children[c];
|
|
202
|
-
const cachedWidth = child.getAttribute(cachedWidthName);
|
|
203
|
-
let childWidth: number;
|
|
204
|
-
if (cachedWidth) {
|
|
205
|
-
childWidth = Number.parseFloat(cachedWidth);
|
|
206
|
-
} else {
|
|
207
|
-
const childD = child.getBoundingClientRect();
|
|
208
|
-
childWidth = childD.width + gap;
|
|
209
|
-
child.setAttribute(cachedWidthName, childWidth.toString());
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// No gap here, child width includes the gap
|
|
213
|
-
if (childWidth <= maxWidth) {
|
|
214
|
-
maxWidth -= childWidth;
|
|
215
|
-
setChildState(child, true);
|
|
216
|
-
setElementVisible(child, true);
|
|
217
|
-
} else {
|
|
218
|
-
setChildState(child, false);
|
|
219
|
-
setElementVisible(child, false);
|
|
220
|
-
|
|
221
|
-
if (!hasMore) {
|
|
222
|
-
// Make sure coming logic to the block
|
|
223
|
-
maxWidth = 0;
|
|
224
|
-
|
|
225
|
-
// Keep the current index
|
|
226
|
-
newIndex = c;
|
|
227
|
-
|
|
228
|
-
// Indicates more
|
|
229
|
-
hasMore = true;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Show or hide more button
|
|
235
|
-
state.hasMore = hasMore;
|
|
236
|
-
setElementVisible(buttonMore, hasMore);
|
|
237
|
-
setElementVisible(resetButton, true);
|
|
238
|
-
|
|
239
|
-
// Update menu start index
|
|
240
|
-
updateIndex(newIndex);
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
// More items creator
|
|
244
|
-
const moreItems: React.ReactElement[] = [];
|
|
245
|
-
if (index != null) {
|
|
246
|
-
for (let i: number = index; i < fields.length; i++) {
|
|
247
|
-
moreItems.push(
|
|
248
|
-
<React.Fragment key={i}>{fields[i]}</React.Fragment>
|
|
249
|
-
);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Handle main form
|
|
254
|
-
const handleForm = (event: React.FormEvent<HTMLFormElement>) => {
|
|
255
|
-
if (event.nativeEvent.cancelable && !event.nativeEvent.composed) return;
|
|
256
|
-
|
|
257
|
-
if (state.form == null) state.form = event.currentTarget;
|
|
258
|
-
|
|
259
|
-
delayed.call();
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
// Handle more button click
|
|
263
|
-
const handleMore = () => {
|
|
264
|
-
updateOpen(!open);
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
// More form change
|
|
268
|
-
const moreFormChange = (event: React.FormEvent<HTMLFormElement>) => {
|
|
269
|
-
if (event.nativeEvent.cancelable && !event.nativeEvent.composed) return;
|
|
270
|
-
|
|
271
|
-
if (state.moreForm == null) state.moreForm = event.currentTarget;
|
|
272
|
-
|
|
273
|
-
delayed.call();
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
// Submit at once
|
|
277
|
-
const handleSubmitInstant = (reset: boolean = false) => {
|
|
278
|
-
// Prepare data
|
|
279
|
-
const data = new FormData(state.form);
|
|
280
|
-
if (state.moreForm != null) {
|
|
281
|
-
DomUtils.mergeFormData(data, new FormData(state.moreForm));
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
onSubmit(data, reset);
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
const delayed = useDelayedExecutor(handleSubmitInstant, 480);
|
|
288
|
-
|
|
289
|
-
// Reset
|
|
290
|
-
const handleReset = () => {
|
|
291
|
-
// Clear form values
|
|
292
|
-
if (state.form != null) resetForm(state.form);
|
|
293
|
-
if (state.moreForm != null) resetForm(state.moreForm);
|
|
294
|
-
|
|
295
|
-
// Resubmit
|
|
296
|
-
handleSubmitInstant(true);
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
React.useEffect(() => {
|
|
300
|
-
// Delayed way
|
|
301
|
-
delayed.call(100);
|
|
302
|
-
|
|
303
|
-
return () => {
|
|
304
|
-
delayed.clear();
|
|
305
|
-
};
|
|
306
|
-
}, [className]);
|
|
307
|
-
|
|
308
|
-
// Layout
|
|
309
|
-
return (
|
|
310
|
-
<React.Fragment>
|
|
311
|
-
<form
|
|
312
|
-
id="SearchBarForm"
|
|
313
|
-
className={className}
|
|
314
|
-
onChange={handleForm}
|
|
315
|
-
ref={(form) => {
|
|
316
|
-
if (form) state.form = form;
|
|
317
|
-
}}
|
|
318
|
-
>
|
|
319
|
-
<Stack
|
|
320
|
-
ref={dimensions[0][0]}
|
|
321
|
-
justifyContent="center"
|
|
322
|
-
alignItems="center"
|
|
323
|
-
direction="row"
|
|
324
|
-
spacing={1}
|
|
325
|
-
height={innerHeight}
|
|
326
|
-
sx={{
|
|
327
|
-
'& > :not(style)': {
|
|
328
|
-
flexBasis: 'auto',
|
|
329
|
-
flexGrow: 0,
|
|
330
|
-
flexShrink: 0,
|
|
331
|
-
maxWidth: '180px',
|
|
332
|
-
visibility: 'hidden'
|
|
333
|
-
},
|
|
334
|
-
'& > .hiddenChild': {
|
|
335
|
-
display: 'none'
|
|
336
|
-
},
|
|
337
|
-
'& > .showChild': {
|
|
338
|
-
display: 'block',
|
|
339
|
-
visibility: 'visible'
|
|
340
|
-
}
|
|
341
|
-
}}
|
|
342
|
-
>
|
|
343
|
-
{fields.map((item, index) => (
|
|
344
|
-
<React.Fragment key={index}>{item}</React.Fragment>
|
|
345
|
-
))}
|
|
346
|
-
|
|
347
|
-
<IconButton
|
|
348
|
-
aria-label="delete"
|
|
349
|
-
size="medium"
|
|
350
|
-
onClick={handleMore}
|
|
351
|
-
>
|
|
352
|
-
<MoreHorizIcon />
|
|
353
|
-
</IconButton>
|
|
354
|
-
<Button
|
|
355
|
-
variant="contained"
|
|
356
|
-
size="medium"
|
|
357
|
-
ref={resetButtonRef}
|
|
358
|
-
onClick={handleReset}
|
|
359
|
-
>
|
|
360
|
-
{labels.reset}
|
|
361
|
-
</Button>
|
|
362
|
-
</Stack>
|
|
363
|
-
</form>
|
|
364
|
-
{index != null && index < fields.length && (
|
|
365
|
-
<Drawer
|
|
366
|
-
anchor="right"
|
|
367
|
-
sx={{ minWidth: '250px' }}
|
|
368
|
-
ModalProps={{
|
|
369
|
-
keepMounted: true // Better open performance on mobile.
|
|
370
|
-
}}
|
|
371
|
-
open={open}
|
|
372
|
-
onClose={() => updateOpen(false)}
|
|
373
|
-
>
|
|
374
|
-
<form
|
|
375
|
-
onChange={moreFormChange}
|
|
376
|
-
ref={(form) => {
|
|
377
|
-
if (form) state.moreForm = form;
|
|
378
|
-
}}
|
|
379
|
-
>
|
|
380
|
-
<Stack
|
|
381
|
-
direction="column"
|
|
382
|
-
alignItems="stretch"
|
|
383
|
-
spacing={2}
|
|
384
|
-
padding={2}
|
|
385
|
-
sx={{
|
|
386
|
-
'& > :not(style)': {
|
|
387
|
-
minWidth: '100px'
|
|
388
|
-
}
|
|
389
|
-
}}
|
|
390
|
-
>
|
|
391
|
-
{moreItems}
|
|
392
|
-
</Stack>
|
|
393
|
-
</form>
|
|
394
|
-
</Drawer>
|
|
395
|
-
)}
|
|
396
|
-
</React.Fragment>
|
|
397
|
-
);
|
|
398
|
-
}
|
package/src/mu/SearchField.tsx
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { TextField, TextFieldProps } from '@mui/material';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { useDelayedExecutor } from '../uses/useDelayedExecutor';
|
|
4
|
-
import { MUGlobal } from './MUGlobal';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Search field props
|
|
8
|
-
*/
|
|
9
|
-
export type SearchFieldProps = TextFieldProps & {
|
|
10
|
-
/**
|
|
11
|
-
* Change delay (ms) to avoid repeatly dispatch onChange
|
|
12
|
-
*/
|
|
13
|
-
changeDelay?: number;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Is the field read only?
|
|
17
|
-
*/
|
|
18
|
-
readOnly?: boolean;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Search field
|
|
23
|
-
* @param props Props
|
|
24
|
-
* @returns Component
|
|
25
|
-
*/
|
|
26
|
-
export function SearchField(props: SearchFieldProps) {
|
|
27
|
-
// Destruct
|
|
28
|
-
const {
|
|
29
|
-
changeDelay,
|
|
30
|
-
InputLabelProps = {},
|
|
31
|
-
InputProps = {},
|
|
32
|
-
onChange,
|
|
33
|
-
readOnly,
|
|
34
|
-
size = MUGlobal.searchFieldSize,
|
|
35
|
-
variant = MUGlobal.searchFieldVariant,
|
|
36
|
-
...rest
|
|
37
|
-
} = props;
|
|
38
|
-
|
|
39
|
-
// Shrink
|
|
40
|
-
InputLabelProps.shrink = MUGlobal.searchFieldShrink;
|
|
41
|
-
|
|
42
|
-
// Read only
|
|
43
|
-
if (readOnly != null) InputProps.readOnly = readOnly;
|
|
44
|
-
|
|
45
|
-
const isMounted = React.useRef(true);
|
|
46
|
-
const delayed =
|
|
47
|
-
onChange != null && changeDelay != null && changeDelay >= 1
|
|
48
|
-
? useDelayedExecutor(onChange, changeDelay)
|
|
49
|
-
: undefined;
|
|
50
|
-
|
|
51
|
-
const onChangeEx = (
|
|
52
|
-
event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
|
|
53
|
-
) => {
|
|
54
|
-
if (onChange == null) return;
|
|
55
|
-
|
|
56
|
-
if (changeDelay == null || changeDelay < 1) {
|
|
57
|
-
onChange(event);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
delayed?.call(undefined, event);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
React.useEffect(() => {
|
|
65
|
-
return () => {
|
|
66
|
-
isMounted.current = false;
|
|
67
|
-
delayed?.clear();
|
|
68
|
-
};
|
|
69
|
-
}, []);
|
|
70
|
-
|
|
71
|
-
// Layout
|
|
72
|
-
return (
|
|
73
|
-
<TextField
|
|
74
|
-
InputLabelProps={InputLabelProps}
|
|
75
|
-
InputProps={InputProps}
|
|
76
|
-
onChange={onChangeEx}
|
|
77
|
-
size={size}
|
|
78
|
-
variant={variant}
|
|
79
|
-
{...rest}
|
|
80
|
-
/>
|
|
81
|
-
);
|
|
82
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { DataTypes } from '@etsoo/shared';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { MUGlobal } from './MUGlobal';
|
|
4
|
-
import { OptionGroup, OptionGroupProps } from './OptionGroup';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Search OptionGroup
|
|
8
|
-
* @param props Props
|
|
9
|
-
* @returns Component
|
|
10
|
-
*/
|
|
11
|
-
export function SearchOptionGroup<
|
|
12
|
-
T extends object = DataTypes.IdLabelItem,
|
|
13
|
-
D extends DataTypes.Keys<T> = DataTypes.Keys<T>
|
|
14
|
-
>(props: OptionGroupProps<T, D>) {
|
|
15
|
-
// Destruct
|
|
16
|
-
const {
|
|
17
|
-
row = true,
|
|
18
|
-
size = MUGlobal.searchFieldSize,
|
|
19
|
-
sx = { '& .MuiFormLabel-root': { fontSize: '0.75em' } },
|
|
20
|
-
...rest
|
|
21
|
-
} = props;
|
|
22
|
-
|
|
23
|
-
// Layout
|
|
24
|
-
return <OptionGroup<T, D> row={row} size={size} sx={sx} {...rest} />;
|
|
25
|
-
}
|
package/src/mu/SelectBool.tsx
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { DataTypes, Utils } from '@etsoo/shared';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { globalApp } from '..';
|
|
4
|
-
import { SelectEx, SelectExProps } from './SelectEx';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* SelectBool props
|
|
8
|
-
*/
|
|
9
|
-
export interface SelectBoolProps
|
|
10
|
-
extends Omit<
|
|
11
|
-
SelectExProps<DataTypes.IdLabelItem<string>>,
|
|
12
|
-
'options' | 'loadData'
|
|
13
|
-
> {}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* SelectBool (yes/no)
|
|
17
|
-
* @param props Props
|
|
18
|
-
* @returns Component
|
|
19
|
-
*/
|
|
20
|
-
export function SelectBool(props: SelectBoolProps) {
|
|
21
|
-
// Destruct
|
|
22
|
-
const { search = true, autoAddBlankItem = search, ...rest } = props;
|
|
23
|
-
|
|
24
|
-
// Options
|
|
25
|
-
const options: DataTypes.IdLabelItem<string>[] = [
|
|
26
|
-
{ id: 'false', label: globalApp.get('no')! },
|
|
27
|
-
{ id: 'true', label: globalApp.get('yes')! }
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
if (autoAddBlankItem) Utils.addBlankItem(options);
|
|
31
|
-
|
|
32
|
-
// Layout
|
|
33
|
-
return (
|
|
34
|
-
<SelectEx<DataTypes.IdLabelItem<string>>
|
|
35
|
-
options={options}
|
|
36
|
-
search={search}
|
|
37
|
-
{...rest}
|
|
38
|
-
/>
|
|
39
|
-
);
|
|
40
|
-
}
|