@etsoo/materialui 1.0.1
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/.eslintignore +3 -0
- package/.eslintrc.json +38 -0
- package/.gitattributes +2 -0
- package/.github/workflows/main.yml +48 -0
- package/.prettierignore +5 -0
- package/.prettierrc +6 -0
- package/LICENSE +21 -0
- package/README.md +16 -0
- package/__tests__/ComboBox.tsx +30 -0
- package/__tests__/MUGlobalTests.tsx +58 -0
- package/__tests__/NotifierMUTests.tsx +217 -0
- package/__tests__/SelectEx.tsx +26 -0
- package/__tests__/tsconfig.json +19 -0
- package/babel.config.json +11 -0
- package/lib/AuditDisplay.d.ts +33 -0
- package/lib/AuditDisplay.js +52 -0
- package/lib/AutocompleteExtendedProps.d.ts +64 -0
- package/lib/AutocompleteExtendedProps.js +1 -0
- package/lib/BackButton.d.ts +13 -0
- package/lib/BackButton.js +33 -0
- package/lib/BridgeCloseButton.d.ts +23 -0
- package/lib/BridgeCloseButton.js +32 -0
- package/lib/ButtonLink.d.ts +17 -0
- package/lib/ButtonLink.js +19 -0
- package/lib/ComboBox.d.ts +38 -0
- package/lib/ComboBox.js +108 -0
- package/lib/CountdownButton.d.ts +23 -0
- package/lib/CountdownButton.js +81 -0
- package/lib/CustomFabProps.d.ts +27 -0
- package/lib/CustomFabProps.js +1 -0
- package/lib/DataGridEx.d.ts +94 -0
- package/lib/DataGridEx.js +329 -0
- package/lib/DataGridRenderers.d.ts +22 -0
- package/lib/DataGridRenderers.js +99 -0
- package/lib/DialogButton.d.ts +54 -0
- package/lib/DialogButton.js +45 -0
- package/lib/DnDList.d.ts +87 -0
- package/lib/DnDList.js +153 -0
- package/lib/DraggablePaperComponent.d.ts +8 -0
- package/lib/DraggablePaperComponent.js +12 -0
- package/lib/EmailInput.d.ts +11 -0
- package/lib/EmailInput.js +15 -0
- package/lib/FabBox.d.ts +21 -0
- package/lib/FabBox.js +31 -0
- package/lib/FlexBox.d.ts +14 -0
- package/lib/FlexBox.js +18 -0
- package/lib/GridDataFormat.d.ts +10 -0
- package/lib/GridDataFormat.js +43 -0
- package/lib/IconButtonLink.d.ts +17 -0
- package/lib/IconButtonLink.js +16 -0
- package/lib/InputField.d.ts +21 -0
- package/lib/InputField.js +39 -0
- package/lib/ItemList.d.ts +56 -0
- package/lib/ItemList.js +69 -0
- package/lib/ListItemRightIcon.d.ts +4 -0
- package/lib/ListItemRightIcon.js +8 -0
- package/lib/ListMoreDisplay.d.ts +35 -0
- package/lib/ListMoreDisplay.js +99 -0
- package/lib/LoadingButton.d.ts +16 -0
- package/lib/LoadingButton.js +41 -0
- package/lib/MUGlobal.d.ts +102 -0
- package/lib/MUGlobal.js +184 -0
- package/lib/MaskInput.d.ts +34 -0
- package/lib/MaskInput.js +43 -0
- package/lib/MobileListItemRenderer.d.ts +17 -0
- package/lib/MobileListItemRenderer.js +35 -0
- package/lib/MoreFab.d.ts +45 -0
- package/lib/MoreFab.js +95 -0
- package/lib/NotifierMU.d.ts +47 -0
- package/lib/NotifierMU.js +387 -0
- package/lib/NotifierPromptProps.d.ts +22 -0
- package/lib/NotifierPromptProps.js +1 -0
- package/lib/OptionGroup.d.ts +58 -0
- package/lib/OptionGroup.js +81 -0
- package/lib/PList.d.ts +15 -0
- package/lib/PList.js +12 -0
- package/lib/ProgressCount.d.ts +44 -0
- package/lib/ProgressCount.js +79 -0
- package/lib/PullToRefreshUI.d.ts +9 -0
- package/lib/PullToRefreshUI.js +18 -0
- package/lib/RLink.d.ts +14 -0
- package/lib/RLink.js +37 -0
- package/lib/ResponsibleContainer.d.ts +87 -0
- package/lib/ResponsibleContainer.js +156 -0
- package/lib/ScrollTopFab.d.ts +7 -0
- package/lib/ScrollTopFab.js +25 -0
- package/lib/ScrollerListEx.d.ts +81 -0
- package/lib/ScrollerListEx.js +167 -0
- package/lib/SearchBar.d.ts +29 -0
- package/lib/SearchBar.js +260 -0
- package/lib/SearchField.d.ts +21 -0
- package/lib/SearchField.js +39 -0
- package/lib/SearchOptionGroup.d.ts +9 -0
- package/lib/SearchOptionGroup.js +14 -0
- package/lib/SelectBool.d.ts +13 -0
- package/lib/SelectBool.js +22 -0
- package/lib/SelectEx.d.ts +50 -0
- package/lib/SelectEx.js +156 -0
- package/lib/ShowDataComparison.d.ts +20 -0
- package/lib/ShowDataComparison.js +58 -0
- package/lib/Switch.d.ts +29 -0
- package/lib/Switch.js +34 -0
- package/lib/SwitchAnt.d.ts +25 -0
- package/lib/SwitchAnt.js +40 -0
- package/lib/TabBox.d.ts +54 -0
- package/lib/TabBox.js +31 -0
- package/lib/TableEx.d.ts +65 -0
- package/lib/TableEx.js +270 -0
- package/lib/TextFieldEx.d.ts +101 -0
- package/lib/TextFieldEx.js +126 -0
- package/lib/Tiplist.d.ts +18 -0
- package/lib/Tiplist.js +157 -0
- package/lib/TooltipClick.d.ts +15 -0
- package/lib/TooltipClick.js +40 -0
- package/lib/UserAvatar.d.ts +24 -0
- package/lib/UserAvatar.js +25 -0
- package/lib/UserAvatarEditor.d.ts +53 -0
- package/lib/UserAvatarEditor.js +129 -0
- package/lib/app/CommonApp.d.ts +38 -0
- package/lib/app/CommonApp.js +149 -0
- package/lib/app/IServiceAppSettings.d.ts +11 -0
- package/lib/app/IServiceAppSettings.js +1 -0
- package/lib/app/IServicePage.d.ts +6 -0
- package/lib/app/IServicePage.js +1 -0
- package/lib/app/IServiceUser.d.ts +14 -0
- package/lib/app/IServiceUser.js +1 -0
- package/lib/app/ISmartERPUser.d.ts +14 -0
- package/lib/app/ISmartERPUser.js +1 -0
- package/lib/app/Labels.d.ts +65 -0
- package/lib/app/Labels.js +62 -0
- package/lib/app/ReactApp.d.ts +195 -0
- package/lib/app/ReactApp.js +296 -0
- package/lib/app/ServiceApp.d.ts +78 -0
- package/lib/app/ServiceApp.js +244 -0
- package/lib/index.d.ts +74 -0
- package/lib/index.js +74 -0
- package/lib/pages/CommonPage.d.ts +11 -0
- package/lib/pages/CommonPage.js +60 -0
- package/lib/pages/CommonPageProps.d.ts +59 -0
- package/lib/pages/CommonPageProps.js +1 -0
- package/lib/pages/DataGridPage.d.ts +9 -0
- package/lib/pages/DataGridPage.js +79 -0
- package/lib/pages/DataGridPageProps.d.ts +17 -0
- package/lib/pages/DataGridPageProps.js +1 -0
- package/lib/pages/EditPage.d.ts +33 -0
- package/lib/pages/EditPage.js +29 -0
- package/lib/pages/FixedListPage.d.ts +15 -0
- package/lib/pages/FixedListPage.js +70 -0
- package/lib/pages/ListPage.d.ts +9 -0
- package/lib/pages/ListPage.js +50 -0
- package/lib/pages/ListPageProps.d.ts +7 -0
- package/lib/pages/ListPageProps.js +1 -0
- package/lib/pages/ResponsivePage.d.ts +9 -0
- package/lib/pages/ResponsivePage.js +45 -0
- package/lib/pages/ResponsivePageProps.d.ts +39 -0
- package/lib/pages/ResponsivePageProps.js +1 -0
- package/lib/pages/SearchPageProps.d.ts +30 -0
- package/lib/pages/SearchPageProps.js +1 -0
- package/lib/pages/TablePage.d.ts +9 -0
- package/lib/pages/TablePage.js +69 -0
- package/lib/pages/TablePageProps.d.ts +7 -0
- package/lib/pages/TablePageProps.js +1 -0
- package/lib/pages/ViewPage.d.ts +66 -0
- package/lib/pages/ViewPage.js +105 -0
- package/lib/texts/DateText.d.ts +34 -0
- package/lib/texts/DateText.js +25 -0
- package/lib/texts/MoneyText.d.ts +21 -0
- package/lib/texts/MoneyText.js +14 -0
- package/lib/texts/NumberText.d.ts +25 -0
- package/lib/texts/NumberText.js +14 -0
- package/package.json +97 -0
- package/src/AuditDisplay.tsx +114 -0
- package/src/AutocompleteExtendedProps.ts +83 -0
- package/src/BackButton.tsx +55 -0
- package/src/BridgeCloseButton.tsx +69 -0
- package/src/ButtonLink.tsx +32 -0
- package/src/ComboBox.tsx +251 -0
- package/src/CountdownButton.tsx +119 -0
- package/src/CustomFabProps.ts +32 -0
- package/src/DataGridEx.tsx +713 -0
- package/src/DataGridRenderers.tsx +140 -0
- package/src/DialogButton.tsx +163 -0
- package/src/DnDList.tsx +344 -0
- package/src/DraggablePaperComponent.tsx +19 -0
- package/src/EmailInput.tsx +24 -0
- package/src/FabBox.tsx +51 -0
- package/src/FlexBox.tsx +20 -0
- package/src/GridDataFormat.tsx +77 -0
- package/src/IconButtonLink.tsx +29 -0
- package/src/InputField.tsx +82 -0
- package/src/ItemList.tsx +204 -0
- package/src/ListItemRightIcon.tsx +9 -0
- package/src/ListMoreDisplay.tsx +205 -0
- package/src/LoadingButton.tsx +75 -0
- package/src/MUGlobal.ts +220 -0
- package/src/MaskInput.tsx +107 -0
- package/src/MobileListItemRenderer.tsx +79 -0
- package/src/MoreFab.tsx +211 -0
- package/src/NotifierMU.tsx +654 -0
- package/src/NotifierPromptProps.ts +24 -0
- package/src/OptionGroup.tsx +223 -0
- package/src/PList.tsx +27 -0
- package/src/ProgressCount.tsx +166 -0
- package/src/PullToRefreshUI.tsx +21 -0
- package/src/RLink.tsx +64 -0
- package/src/ResponsibleContainer.tsx +394 -0
- package/src/ScrollTopFab.tsx +34 -0
- package/src/ScrollerListEx.tsx +387 -0
- package/src/SearchBar.tsx +396 -0
- package/src/SearchField.tsx +82 -0
- package/src/SearchOptionGroup.tsx +31 -0
- package/src/SelectBool.tsx +33 -0
- package/src/SelectEx.tsx +290 -0
- package/src/ShowDataComparison.tsx +106 -0
- package/src/Switch.tsx +94 -0
- package/src/SwitchAnt.tsx +95 -0
- package/src/TabBox.tsx +118 -0
- package/src/TableEx.tsx +558 -0
- package/src/TextFieldEx.tsx +249 -0
- package/src/Tiplist.tsx +303 -0
- package/src/TooltipClick.tsx +84 -0
- package/src/UserAvatar.tsx +64 -0
- package/src/UserAvatarEditor.tsx +287 -0
- package/src/app/CommonApp.ts +223 -0
- package/src/app/IServiceAppSettings.ts +13 -0
- package/src/app/IServicePage.ts +6 -0
- package/src/app/IServiceUser.ts +17 -0
- package/src/app/ISmartERPUser.ts +16 -0
- package/src/app/Labels.ts +77 -0
- package/src/app/ReactApp.ts +504 -0
- package/src/app/ServiceApp.ts +352 -0
- package/src/index.ts +77 -0
- package/src/pages/CommonPage.tsx +128 -0
- package/src/pages/CommonPageProps.ts +70 -0
- package/src/pages/DataGridPage.tsx +140 -0
- package/src/pages/DataGridPageProps.ts +24 -0
- package/src/pages/EditPage.tsx +114 -0
- package/src/pages/FixedListPage.tsx +141 -0
- package/src/pages/ListPage.tsx +90 -0
- package/src/pages/ListPageProps.ts +12 -0
- package/src/pages/ResponsivePage.tsx +68 -0
- package/src/pages/ResponsivePageProps.ts +57 -0
- package/src/pages/SearchPageProps.ts +39 -0
- package/src/pages/TablePage.tsx +126 -0
- package/src/pages/TablePageProps.ts +12 -0
- package/src/pages/ViewPage.tsx +282 -0
- package/src/texts/DateText.tsx +74 -0
- package/src/texts/MoneyText.tsx +49 -0
- package/src/texts/NumberText.tsx +40 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Button, ButtonProps } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useNavigate } from 'react-router-dom';
|
|
4
|
+
/**
|
|
5
|
+
* ButtonLink props
|
|
6
|
+
*/
|
|
7
|
+
export type ButtonLinkProps = Omit<ButtonProps, 'href' | 'onClick'> & {
|
|
8
|
+
/**
|
|
9
|
+
* To href
|
|
10
|
+
*/
|
|
11
|
+
href: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* ButtonLink
|
|
16
|
+
* @param props Props
|
|
17
|
+
* @returns Component
|
|
18
|
+
*/
|
|
19
|
+
export function ButtonLink(props: ButtonLinkProps) {
|
|
20
|
+
// Destruct
|
|
21
|
+
const { href, ...rest } = props;
|
|
22
|
+
|
|
23
|
+
// Navigate
|
|
24
|
+
const navigate = useNavigate();
|
|
25
|
+
|
|
26
|
+
const onClick = href.includes('://')
|
|
27
|
+
? () => window.open(href, '_blank')
|
|
28
|
+
: () => navigate(href);
|
|
29
|
+
|
|
30
|
+
// Layout
|
|
31
|
+
return <Button {...rest} onClick={onClick} />;
|
|
32
|
+
}
|
package/src/ComboBox.tsx
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DataTypes,
|
|
3
|
+
IdDefaultType,
|
|
4
|
+
Keyboard,
|
|
5
|
+
LabelDefaultType,
|
|
6
|
+
ListType
|
|
7
|
+
} from '@etsoo/shared';
|
|
8
|
+
import { Autocomplete, AutocompleteRenderInputParams } from '@mui/material';
|
|
9
|
+
import React from 'react';
|
|
10
|
+
import { Utils as SharedUtils } from '@etsoo/shared';
|
|
11
|
+
import { AutocompleteExtendedProps } from './AutocompleteExtendedProps';
|
|
12
|
+
import { InputField } from './InputField';
|
|
13
|
+
import { SearchField } from './SearchField';
|
|
14
|
+
import { ReactUtils } from '@etsoo/react';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* ComboBox props
|
|
18
|
+
*/
|
|
19
|
+
export type ComboBoxProps<
|
|
20
|
+
T extends object,
|
|
21
|
+
D extends DataTypes.Keys<T>,
|
|
22
|
+
L extends DataTypes.Keys<T, string>
|
|
23
|
+
> = AutocompleteExtendedProps<T, D> & {
|
|
24
|
+
/**
|
|
25
|
+
* Auto add blank item
|
|
26
|
+
*/
|
|
27
|
+
autoAddBlankItem?: boolean;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Data readonly
|
|
31
|
+
*/
|
|
32
|
+
dataReadonly?: boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Label field
|
|
36
|
+
*/
|
|
37
|
+
labelField?: L;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Load data callback
|
|
41
|
+
*/
|
|
42
|
+
loadData?: () => PromiseLike<T[] | null | undefined>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* On load data handler
|
|
46
|
+
*/
|
|
47
|
+
onLoadData?: (options: T[]) => void;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Array of options.
|
|
51
|
+
*/
|
|
52
|
+
options?: ReadonlyArray<T>;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* ComboBox
|
|
57
|
+
* @param props Props
|
|
58
|
+
* @returns Component
|
|
59
|
+
*/
|
|
60
|
+
export function ComboBox<
|
|
61
|
+
T extends object = ListType,
|
|
62
|
+
D extends DataTypes.Keys<T> = IdDefaultType<T>,
|
|
63
|
+
L extends DataTypes.Keys<T, string> = LabelDefaultType<T>
|
|
64
|
+
>(props: ComboBoxProps<T, D, L>) {
|
|
65
|
+
// Destruct
|
|
66
|
+
const {
|
|
67
|
+
search = false,
|
|
68
|
+
autoAddBlankItem = search,
|
|
69
|
+
idField = 'id' as D,
|
|
70
|
+
idValue,
|
|
71
|
+
inputError,
|
|
72
|
+
inputHelperText,
|
|
73
|
+
inputMargin,
|
|
74
|
+
inputOnChange,
|
|
75
|
+
inputRequired,
|
|
76
|
+
inputVariant,
|
|
77
|
+
defaultValue,
|
|
78
|
+
label,
|
|
79
|
+
labelField = 'label' as L,
|
|
80
|
+
loadData,
|
|
81
|
+
onLoadData,
|
|
82
|
+
name,
|
|
83
|
+
inputAutoComplete = 'off',
|
|
84
|
+
options,
|
|
85
|
+
dataReadonly = true,
|
|
86
|
+
readOnly,
|
|
87
|
+
onChange,
|
|
88
|
+
openOnFocus = true,
|
|
89
|
+
value,
|
|
90
|
+
getOptionLabel = (option: T) => `${option[labelField]}`,
|
|
91
|
+
sx = { minWidth: '150px' },
|
|
92
|
+
...rest
|
|
93
|
+
} = props;
|
|
94
|
+
|
|
95
|
+
// Value input ref
|
|
96
|
+
const inputRef = React.createRef<HTMLInputElement>();
|
|
97
|
+
|
|
98
|
+
// Options state
|
|
99
|
+
const [localOptions, setOptions] = React.useState(options ?? []);
|
|
100
|
+
const isMounted = React.useRef(true);
|
|
101
|
+
|
|
102
|
+
// When options change
|
|
103
|
+
// [options] will cause infinite loop
|
|
104
|
+
const propertyWay = loadData == null;
|
|
105
|
+
React.useEffect(() => {
|
|
106
|
+
if (propertyWay && options != null) setOptions(options);
|
|
107
|
+
}, [JSON.stringify(options), propertyWay]);
|
|
108
|
+
|
|
109
|
+
// Local default value
|
|
110
|
+
let localValue =
|
|
111
|
+
idValue != null
|
|
112
|
+
? localOptions.find((o) => o[idField] === idValue)
|
|
113
|
+
: defaultValue ?? value;
|
|
114
|
+
|
|
115
|
+
if (localValue === undefined) localValue = null;
|
|
116
|
+
|
|
117
|
+
// State
|
|
118
|
+
// null for controlled
|
|
119
|
+
const [stateValue, setStateValue] = React.useState<T | null>(null);
|
|
120
|
+
|
|
121
|
+
// Current id value
|
|
122
|
+
// One time calculation for input's default value (uncontrolled)
|
|
123
|
+
const localIdValue = stateValue && stateValue[idField];
|
|
124
|
+
|
|
125
|
+
React.useEffect(() => {
|
|
126
|
+
if (localValue != null) setStateValue(localValue);
|
|
127
|
+
}, [localValue]);
|
|
128
|
+
|
|
129
|
+
// Add readOnly
|
|
130
|
+
const addReadOnly = (params: AutocompleteRenderInputParams) => {
|
|
131
|
+
if (readOnly != null) {
|
|
132
|
+
Object.assign(params, { readOnly });
|
|
133
|
+
|
|
134
|
+
if (readOnly) {
|
|
135
|
+
Object.assign(params.inputProps, { 'data-reset': true });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (dataReadonly) {
|
|
140
|
+
params.inputProps.onKeyDown = (event) => {
|
|
141
|
+
if (Keyboard.isTypingContent(event.key)) {
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// https://stackoverflow.com/questions/15738259/disabling-chrome-autofill
|
|
148
|
+
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html
|
|
149
|
+
Object.assign(params.inputProps, { autoComplete: inputAutoComplete });
|
|
150
|
+
|
|
151
|
+
return params;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const setInputValue = (value: T | null) => {
|
|
155
|
+
// Set state
|
|
156
|
+
setStateValue(value);
|
|
157
|
+
|
|
158
|
+
// Input value
|
|
159
|
+
const input = inputRef.current;
|
|
160
|
+
if (input) {
|
|
161
|
+
// Update value
|
|
162
|
+
const newValue = value != null ? `${value[idField]}` : '';
|
|
163
|
+
|
|
164
|
+
if (newValue !== input.value) {
|
|
165
|
+
// Different value, trigger change event
|
|
166
|
+
ReactUtils.triggerChange(input, newValue, false);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// When value change
|
|
172
|
+
React.useEffect(() => {
|
|
173
|
+
if (loadData) {
|
|
174
|
+
loadData().then((result) => {
|
|
175
|
+
if (result == null || !isMounted.current) return;
|
|
176
|
+
if (onLoadData) onLoadData(result);
|
|
177
|
+
if (autoAddBlankItem) {
|
|
178
|
+
SharedUtils.addBlankItem(result, idField, labelField);
|
|
179
|
+
}
|
|
180
|
+
setOptions(result);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}, [localValue]);
|
|
184
|
+
|
|
185
|
+
React.useEffect(() => {
|
|
186
|
+
return () => {
|
|
187
|
+
isMounted.current = false;
|
|
188
|
+
};
|
|
189
|
+
}, []);
|
|
190
|
+
|
|
191
|
+
// Layout
|
|
192
|
+
return (
|
|
193
|
+
<div>
|
|
194
|
+
<input
|
|
195
|
+
ref={inputRef}
|
|
196
|
+
data-reset="true"
|
|
197
|
+
type="text"
|
|
198
|
+
style={{ display: 'none' }}
|
|
199
|
+
name={name}
|
|
200
|
+
value={`${localIdValue ?? ''}`}
|
|
201
|
+
readOnly
|
|
202
|
+
onChange={inputOnChange}
|
|
203
|
+
/>
|
|
204
|
+
{/* Previous input will reset first with "disableClearable = false", next input trigger change works */}
|
|
205
|
+
<Autocomplete<T, undefined, false, false>
|
|
206
|
+
value={stateValue}
|
|
207
|
+
getOptionLabel={getOptionLabel}
|
|
208
|
+
isOptionEqualToValue={(option: T, value: T) =>
|
|
209
|
+
option[idField] === value[idField]
|
|
210
|
+
}
|
|
211
|
+
onChange={(event, value, reason, details) => {
|
|
212
|
+
// Set value
|
|
213
|
+
setInputValue(value);
|
|
214
|
+
|
|
215
|
+
// Custom
|
|
216
|
+
if (onChange != null)
|
|
217
|
+
onChange(event, value, reason, details);
|
|
218
|
+
}}
|
|
219
|
+
openOnFocus={openOnFocus}
|
|
220
|
+
sx={sx}
|
|
221
|
+
renderInput={(params) =>
|
|
222
|
+
search ? (
|
|
223
|
+
<SearchField
|
|
224
|
+
{...addReadOnly(params)}
|
|
225
|
+
label={label}
|
|
226
|
+
name={name + 'Input'}
|
|
227
|
+
margin={inputMargin}
|
|
228
|
+
variant={inputVariant}
|
|
229
|
+
required={inputRequired}
|
|
230
|
+
error={inputError}
|
|
231
|
+
helperText={inputHelperText}
|
|
232
|
+
/>
|
|
233
|
+
) : (
|
|
234
|
+
<InputField
|
|
235
|
+
{...addReadOnly(params)}
|
|
236
|
+
label={label}
|
|
237
|
+
name={name + 'Input'}
|
|
238
|
+
margin={inputMargin}
|
|
239
|
+
variant={inputVariant}
|
|
240
|
+
required={inputRequired}
|
|
241
|
+
error={inputError}
|
|
242
|
+
helperText={inputHelperText}
|
|
243
|
+
/>
|
|
244
|
+
)
|
|
245
|
+
}
|
|
246
|
+
options={localOptions}
|
|
247
|
+
{...rest}
|
|
248
|
+
/>
|
|
249
|
+
</div>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Button, ButtonProps, CircularProgress } from '@mui/material';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Countdown button action
|
|
6
|
+
*/
|
|
7
|
+
export interface CountdownButtonAction {
|
|
8
|
+
(): Promise<number>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Countdown button props
|
|
13
|
+
*/
|
|
14
|
+
export type CountdownButtonProps = Omit<ButtonProps, 'endIcon' | 'disabled'> & {
|
|
15
|
+
/**
|
|
16
|
+
* Action, required
|
|
17
|
+
*/
|
|
18
|
+
onAction: CountdownButtonAction;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Countdown button
|
|
23
|
+
* @param props Props
|
|
24
|
+
* @returns Button
|
|
25
|
+
*/
|
|
26
|
+
export const CountdownButton = React.forwardRef<
|
|
27
|
+
HTMLButtonElement,
|
|
28
|
+
CountdownButtonProps
|
|
29
|
+
>((props, ref) => {
|
|
30
|
+
// Destructure
|
|
31
|
+
const { onAction, onClick, ...rest } = props;
|
|
32
|
+
|
|
33
|
+
// State
|
|
34
|
+
// 0 - normal
|
|
35
|
+
// 1 - loading
|
|
36
|
+
// 2 - countdown
|
|
37
|
+
const [state, updateState] = React.useState(0);
|
|
38
|
+
|
|
39
|
+
// Ignore seconds
|
|
40
|
+
const seconds = 2;
|
|
41
|
+
|
|
42
|
+
// Countdown length
|
|
43
|
+
const [shared] = React.useState({ maxLength: 0 });
|
|
44
|
+
|
|
45
|
+
const isMounted = React.useRef(true);
|
|
46
|
+
|
|
47
|
+
// endIcon
|
|
48
|
+
let endIcon: React.ReactNode;
|
|
49
|
+
if (state === 0) {
|
|
50
|
+
endIcon = undefined;
|
|
51
|
+
} else if (state === 1) {
|
|
52
|
+
endIcon = <CircularProgress size={12} />;
|
|
53
|
+
} else {
|
|
54
|
+
const countdown = (state - seconds)
|
|
55
|
+
.toString()
|
|
56
|
+
.padStart(shared.maxLength, '0');
|
|
57
|
+
endIcon = <span style={{ fontSize: 'smaller' }}>{countdown}</span>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Disabled?
|
|
61
|
+
const disabled = state > 0;
|
|
62
|
+
|
|
63
|
+
// Action
|
|
64
|
+
const doAction = (result: number) => {
|
|
65
|
+
// Seconds to wait, 120
|
|
66
|
+
if (result > seconds) {
|
|
67
|
+
// Here 122
|
|
68
|
+
result += seconds;
|
|
69
|
+
updateState(result);
|
|
70
|
+
|
|
71
|
+
// Update max length
|
|
72
|
+
shared.maxLength = result.toString().length;
|
|
73
|
+
|
|
74
|
+
const seed = setInterval(() => {
|
|
75
|
+
// Mounted?
|
|
76
|
+
if (!isMounted.current) return;
|
|
77
|
+
|
|
78
|
+
// Last 1 second and then complete
|
|
79
|
+
if (result > seconds + 1) {
|
|
80
|
+
result--;
|
|
81
|
+
updateState(result);
|
|
82
|
+
} else {
|
|
83
|
+
clearInterval(seed);
|
|
84
|
+
updateState(0);
|
|
85
|
+
}
|
|
86
|
+
}, 1000);
|
|
87
|
+
} else {
|
|
88
|
+
updateState(0);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// Local click
|
|
93
|
+
const localClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
94
|
+
// Show loading
|
|
95
|
+
updateState(1);
|
|
96
|
+
|
|
97
|
+
// Callback
|
|
98
|
+
if (onClick != null) onClick(event);
|
|
99
|
+
|
|
100
|
+
// Return any countdown
|
|
101
|
+
onAction().then(doAction);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
React.useEffect(() => {
|
|
105
|
+
return () => {
|
|
106
|
+
isMounted.current = false;
|
|
107
|
+
};
|
|
108
|
+
}, []);
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<Button
|
|
112
|
+
disabled={disabled}
|
|
113
|
+
endIcon={endIcon}
|
|
114
|
+
onClick={localClick}
|
|
115
|
+
ref={ref}
|
|
116
|
+
{...rest}
|
|
117
|
+
/>
|
|
118
|
+
);
|
|
119
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { FabPropsColorOverrides, PropTypes } from '@mui/material';
|
|
2
|
+
import { OverridableStringUnion } from '@mui/types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Custom fab size
|
|
6
|
+
*/
|
|
7
|
+
export type CustomFabSize = 'small' | 'medium' | 'large';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Custom fab props
|
|
11
|
+
*/
|
|
12
|
+
export interface CustomFabProps {
|
|
13
|
+
/**
|
|
14
|
+
* Color
|
|
15
|
+
*/
|
|
16
|
+
color?: OverridableStringUnion<PropTypes.Color, FabPropsColorOverrides>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Fab size
|
|
20
|
+
*/
|
|
21
|
+
size?: CustomFabSize;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Scroll target
|
|
25
|
+
*/
|
|
26
|
+
target?: any;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Fab title
|
|
30
|
+
*/
|
|
31
|
+
title?: string;
|
|
32
|
+
}
|