@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
package/lib/TableEx.js
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { GridAlignGet, GridSizeGet } from '@etsoo/react';
|
|
2
|
+
import { DataTypes } from '@etsoo/shared';
|
|
3
|
+
import { Checkbox, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TablePagination, TableRow, TableSortLabel, useTheme } from '@mui/material';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { DataGridRenderers } from './DataGridRenderers';
|
|
6
|
+
/**
|
|
7
|
+
* Extended table min width for width-unset column
|
|
8
|
+
*/
|
|
9
|
+
export const TableExMinWidth = 180;
|
|
10
|
+
/**
|
|
11
|
+
* Extended Table
|
|
12
|
+
* @param props Props
|
|
13
|
+
* @returns Component
|
|
14
|
+
*/
|
|
15
|
+
export function TableEx(props) {
|
|
16
|
+
var _a;
|
|
17
|
+
// Theme
|
|
18
|
+
const theme = useTheme();
|
|
19
|
+
// Destruct
|
|
20
|
+
const { alternatingColors = [theme.palette.action.hover, undefined], autoLoad = true, columns, defaultOrderBy, headerColors = [undefined, undefined], idField = 'id', loadBatchSize, loadData, maxHeight, mRef, onSelectChange, rowHeight = 53, otherHeight = 110, threshold, ...rest } = props;
|
|
21
|
+
const selectable = onSelectChange != null;
|
|
22
|
+
// Rows per page
|
|
23
|
+
let rowsPerPageLocal;
|
|
24
|
+
if (maxHeight != null) {
|
|
25
|
+
if (loadBatchSize != null)
|
|
26
|
+
rowsPerPageLocal = GridSizeGet(loadBatchSize, maxHeight);
|
|
27
|
+
else
|
|
28
|
+
rowsPerPageLocal = Math.floor((maxHeight - otherHeight) / rowHeight);
|
|
29
|
+
}
|
|
30
|
+
else if (typeof loadBatchSize === 'number') {
|
|
31
|
+
rowsPerPageLocal = loadBatchSize;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
rowsPerPageLocal = 10;
|
|
35
|
+
}
|
|
36
|
+
// Rows
|
|
37
|
+
const [rows, updateRows] = React.useState([]);
|
|
38
|
+
const setRows = (rows) => {
|
|
39
|
+
state.loadedItems = rows.length;
|
|
40
|
+
updateRows(rows);
|
|
41
|
+
};
|
|
42
|
+
// States
|
|
43
|
+
const stateRefs = React.useRef({
|
|
44
|
+
autoLoad,
|
|
45
|
+
currentPage: 0,
|
|
46
|
+
loadedItems: 0,
|
|
47
|
+
hasNextPage: true,
|
|
48
|
+
isNextPageLoading: false,
|
|
49
|
+
orderBy: defaultOrderBy,
|
|
50
|
+
orderByAsc: defaultOrderBy
|
|
51
|
+
? (_a = columns.find((column) => column.field === defaultOrderBy)) === null || _a === void 0 ? void 0 : _a.sortAsc
|
|
52
|
+
: undefined,
|
|
53
|
+
batchSize: rowsPerPageLocal,
|
|
54
|
+
selectedItems: []
|
|
55
|
+
});
|
|
56
|
+
const state = stateRefs.current;
|
|
57
|
+
// Reset the state and load again
|
|
58
|
+
const reset = (add) => {
|
|
59
|
+
const resetState = {
|
|
60
|
+
autoLoad: true,
|
|
61
|
+
currentPage: 0,
|
|
62
|
+
loadedItems: 0,
|
|
63
|
+
hasNextPage: true,
|
|
64
|
+
isNextPageLoading: false,
|
|
65
|
+
lastLoadedItems: undefined,
|
|
66
|
+
...add
|
|
67
|
+
};
|
|
68
|
+
Object.assign(state, resetState);
|
|
69
|
+
};
|
|
70
|
+
React.useImperativeHandle(mRef, () => ({
|
|
71
|
+
/**
|
|
72
|
+
* Refresh data
|
|
73
|
+
*/
|
|
74
|
+
refresh() {
|
|
75
|
+
loadDataLocal();
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* Reset
|
|
79
|
+
*/
|
|
80
|
+
reset
|
|
81
|
+
}), []);
|
|
82
|
+
// Load data
|
|
83
|
+
const loadDataLocal = () => {
|
|
84
|
+
// Prevent multiple loadings
|
|
85
|
+
if (!state.hasNextPage || state.isNextPageLoading)
|
|
86
|
+
return;
|
|
87
|
+
// Update state
|
|
88
|
+
state.isNextPageLoading = true;
|
|
89
|
+
// Parameters
|
|
90
|
+
const { currentPage, batchSize, orderBy, orderByAsc, data, isMounted } = state;
|
|
91
|
+
const loadProps = {
|
|
92
|
+
currentPage,
|
|
93
|
+
batchSize,
|
|
94
|
+
orderBy,
|
|
95
|
+
orderByAsc,
|
|
96
|
+
data
|
|
97
|
+
};
|
|
98
|
+
loadData(loadProps).then((result) => {
|
|
99
|
+
state.isMounted = true;
|
|
100
|
+
if (result == null || isMounted === false) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const newItems = result.length;
|
|
104
|
+
state.lastLoadedItems = newItems;
|
|
105
|
+
state.hasNextPage = newItems >= batchSize;
|
|
106
|
+
state.isNextPageLoading = false;
|
|
107
|
+
// Update rows
|
|
108
|
+
setRows(result);
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
const handleChangePage = (_event, newPage) => {
|
|
112
|
+
state.hasNextPage = true;
|
|
113
|
+
state.currentPage = newPage;
|
|
114
|
+
loadDataLocal();
|
|
115
|
+
};
|
|
116
|
+
const handleChangeRowsPerPage = (event) => {
|
|
117
|
+
const batchSize = parseInt(event.target.value);
|
|
118
|
+
reset({ batchSize });
|
|
119
|
+
};
|
|
120
|
+
const handleSelect = (item, checked) => {
|
|
121
|
+
const selectedItems = state.selectedItems;
|
|
122
|
+
const index = selectedItems.findIndex((selectedItem) => selectedItem[idField] === item[idField]);
|
|
123
|
+
if (checked) {
|
|
124
|
+
if (index === -1)
|
|
125
|
+
selectedItems.push(item);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
if (index !== -1)
|
|
129
|
+
selectedItems.splice(index, 1);
|
|
130
|
+
}
|
|
131
|
+
if (onSelectChange != null) {
|
|
132
|
+
onSelectChange(selectedItems);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const handleSelectAll = (checked) => {
|
|
136
|
+
const selectedItems = state.selectedItems;
|
|
137
|
+
rows.forEach((row) => {
|
|
138
|
+
const index = selectedItems.findIndex((selectedItem) => selectedItem[idField] === row[idField]);
|
|
139
|
+
if (checked) {
|
|
140
|
+
if (index === -1)
|
|
141
|
+
selectedItems.push(row);
|
|
142
|
+
}
|
|
143
|
+
else if (index !== -1) {
|
|
144
|
+
selectedItems.splice(index, 1);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
if (onSelectChange != null) {
|
|
148
|
+
onSelectChange(selectedItems);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
// New sort
|
|
152
|
+
const handleSort = (field, asc) => {
|
|
153
|
+
reset({ orderBy: field, orderByAsc: asc });
|
|
154
|
+
};
|
|
155
|
+
// Destruct states
|
|
156
|
+
const { autoLoad: stateAutoLoad, currentPage, hasNextPage, lastLoadedItems, orderBy, batchSize, selectedItems } = state;
|
|
157
|
+
// Current page selected items
|
|
158
|
+
const pageSelectedItems = selectable
|
|
159
|
+
? rows.reduce((previousValue, currentItem) => {
|
|
160
|
+
if (selectedItems.some((item) => item[idField] === currentItem[idField]))
|
|
161
|
+
return previousValue + 1;
|
|
162
|
+
return previousValue;
|
|
163
|
+
}, 0)
|
|
164
|
+
: 0;
|
|
165
|
+
// Total rows
|
|
166
|
+
const totalRows = hasNextPage
|
|
167
|
+
? -1
|
|
168
|
+
: currentPage * batchSize + (lastLoadedItems !== null && lastLoadedItems !== void 0 ? lastLoadedItems : 0);
|
|
169
|
+
// Auto load data when current page is 0
|
|
170
|
+
if (currentPage === 0 && stateAutoLoad && lastLoadedItems == null)
|
|
171
|
+
loadDataLocal();
|
|
172
|
+
React.useEffect(() => {
|
|
173
|
+
return () => {
|
|
174
|
+
state.isMounted = false;
|
|
175
|
+
};
|
|
176
|
+
}, []);
|
|
177
|
+
// Layout
|
|
178
|
+
return (React.createElement(Paper, null,
|
|
179
|
+
React.createElement(TableContainer, { sx: { maxHeight } },
|
|
180
|
+
React.createElement(Table, { ...rest },
|
|
181
|
+
React.createElement(TableHead, null,
|
|
182
|
+
React.createElement(TableRow, { sx: {
|
|
183
|
+
'& th': {
|
|
184
|
+
backgroundColor: headerColors[0],
|
|
185
|
+
color: headerColors[1]
|
|
186
|
+
}
|
|
187
|
+
} },
|
|
188
|
+
selectable && (React.createElement(TableCell, { padding: "checkbox" },
|
|
189
|
+
React.createElement(Checkbox, { color: "primary", indeterminate: pageSelectedItems > 0 &&
|
|
190
|
+
pageSelectedItems < rows.length, checked: pageSelectedItems > 0, onChange: (_event, checked) => handleSelectAll(checked) }))),
|
|
191
|
+
columns.map((column, index) => {
|
|
192
|
+
// Destruct
|
|
193
|
+
const { align, field, header, minWidth, sortable, sortAsc = true, type, width } = column;
|
|
194
|
+
// Header text
|
|
195
|
+
const headerText = header !== null && header !== void 0 ? header : field;
|
|
196
|
+
// Sortable
|
|
197
|
+
let sortLabel;
|
|
198
|
+
if (sortable && field != null) {
|
|
199
|
+
const active = orderBy === field;
|
|
200
|
+
sortLabel = (React.createElement(TableSortLabel, { active: active, direction: sortAsc ? 'asc' : 'desc', onClick: (_event) => {
|
|
201
|
+
if (active)
|
|
202
|
+
column.sortAsc = !sortAsc;
|
|
203
|
+
handleSort(field, column.sortAsc);
|
|
204
|
+
} }, headerText));
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
sortLabel = headerText;
|
|
208
|
+
}
|
|
209
|
+
return (React.createElement(TableCell, { align: GridAlignGet(align, type), key: field !== null && field !== void 0 ? field : index.toString(), width: width, sx: {
|
|
210
|
+
minWidth: minWidth == null
|
|
211
|
+
? width == null
|
|
212
|
+
? TableExMinWidth
|
|
213
|
+
: undefined
|
|
214
|
+
: minWidth
|
|
215
|
+
} }, sortLabel));
|
|
216
|
+
}))),
|
|
217
|
+
React.createElement(TableBody, { sx: {
|
|
218
|
+
'& tr:nth-of-type(odd):not(.Mui-selected)': {
|
|
219
|
+
backgroundColor: alternatingColors[0]
|
|
220
|
+
},
|
|
221
|
+
'& tr:nth-of-type(even):not(.Mui-selected)': {
|
|
222
|
+
backgroundColor: alternatingColors[1]
|
|
223
|
+
}
|
|
224
|
+
} }, [...Array(batchSize)].map((_item, rowIndex) => {
|
|
225
|
+
var _a;
|
|
226
|
+
// Row
|
|
227
|
+
const row = rowIndex < rows.length
|
|
228
|
+
? rows[rowIndex]
|
|
229
|
+
: undefined;
|
|
230
|
+
// Row id field value
|
|
231
|
+
const rowId = (_a = DataTypes.getValue(row, idField)) !== null && _a !== void 0 ? _a : rowIndex;
|
|
232
|
+
// Selected or not
|
|
233
|
+
const isItemSelected = selectable
|
|
234
|
+
? selectedItems.some((item) => item[idField] === rowId)
|
|
235
|
+
: false;
|
|
236
|
+
return (React.createElement(TableRow, { key: rowId, selected: isItemSelected },
|
|
237
|
+
selectable && (React.createElement(TableCell, { padding: "checkbox" }, row && (React.createElement(Checkbox, { color: "primary", checked: isItemSelected, onChange: (_event, checked) => handleSelect(row, checked) })))),
|
|
238
|
+
columns.map(({ align, cellRenderer = DataGridRenderers.defaultCellRenderer, field, type, valueFormatter }, columnIndex) => {
|
|
239
|
+
const formatProps = {
|
|
240
|
+
data: row,
|
|
241
|
+
field,
|
|
242
|
+
rowIndex,
|
|
243
|
+
columnIndex
|
|
244
|
+
};
|
|
245
|
+
const cellProps = {
|
|
246
|
+
align: GridAlignGet(align, type),
|
|
247
|
+
valign: 'middle'
|
|
248
|
+
};
|
|
249
|
+
const child = row ? (cellRenderer({
|
|
250
|
+
data: row,
|
|
251
|
+
field,
|
|
252
|
+
formattedValue: valueFormatter
|
|
253
|
+
? valueFormatter(formatProps)
|
|
254
|
+
: undefined,
|
|
255
|
+
selected: isItemSelected,
|
|
256
|
+
type,
|
|
257
|
+
rowIndex,
|
|
258
|
+
columnIndex,
|
|
259
|
+
cellProps
|
|
260
|
+
})) : (React.createElement(React.Fragment, null, "\u00A0"));
|
|
261
|
+
return (React.createElement(TableCell, { key: `${rowId}${columnIndex}`, ...cellProps }, child));
|
|
262
|
+
})));
|
|
263
|
+
})))),
|
|
264
|
+
React.createElement(TablePagination, { component: "div", showFirstButton: true, count: totalRows, rowsPerPage: batchSize, page: currentPage, onPageChange: handleChangePage, onRowsPerPageChange: handleChangeRowsPerPage, rowsPerPageOptions: [
|
|
265
|
+
batchSize,
|
|
266
|
+
2 * batchSize,
|
|
267
|
+
5 * batchSize,
|
|
268
|
+
10 * batchSize
|
|
269
|
+
] })));
|
|
270
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TextFieldProps } from '@mui/material';
|
|
3
|
+
/**
|
|
4
|
+
* Extended text field props
|
|
5
|
+
*/
|
|
6
|
+
export declare type TextFieldExProps = TextFieldProps & {
|
|
7
|
+
/**
|
|
8
|
+
* Change delay (ms) to avoid repeatly dispatch onChange
|
|
9
|
+
*/
|
|
10
|
+
changeDelay?: number;
|
|
11
|
+
/**
|
|
12
|
+
* On enter click
|
|
13
|
+
*/
|
|
14
|
+
onEnter?: React.KeyboardEventHandler<HTMLDivElement>;
|
|
15
|
+
/**
|
|
16
|
+
* Is the field read only?
|
|
17
|
+
*/
|
|
18
|
+
readOnly?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Show clear button
|
|
21
|
+
*/
|
|
22
|
+
showClear?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Show password button
|
|
25
|
+
*/
|
|
26
|
+
showPassword?: boolean;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Extended text field methods
|
|
30
|
+
*/
|
|
31
|
+
export interface TextFieldExMethods {
|
|
32
|
+
/**
|
|
33
|
+
* Set error
|
|
34
|
+
* @param error Error
|
|
35
|
+
*/
|
|
36
|
+
setError(error: React.ReactNode): void;
|
|
37
|
+
}
|
|
38
|
+
export declare const TextFieldEx: React.ForwardRefExoticComponent<(Pick<import("@mui/material").StandardTextFieldProps & {
|
|
39
|
+
/**
|
|
40
|
+
* Change delay (ms) to avoid repeatly dispatch onChange
|
|
41
|
+
*/
|
|
42
|
+
changeDelay?: number | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* On enter click
|
|
45
|
+
*/
|
|
46
|
+
onEnter?: React.KeyboardEventHandler<HTMLDivElement> | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Is the field read only?
|
|
49
|
+
*/
|
|
50
|
+
readOnly?: boolean | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Show clear button
|
|
53
|
+
*/
|
|
54
|
+
showClear?: boolean | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Show password button
|
|
57
|
+
*/
|
|
58
|
+
showPassword?: boolean | undefined;
|
|
59
|
+
}, "className" | "style" | "classes" | "children" | "sx" | "variant" | "label" | "slot" | "select" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "disabled" | "type" | "margin" | "size" | "name" | "autoFocus" | "value" | "autoComplete" | "readOnly" | "required" | "rows" | "fullWidth" | "error" | "inputProps" | "onEnter" | "inputRef" | "focused" | "hiddenLabel" | "multiline" | "maxRows" | "minRows" | "changeDelay" | "InputLabelProps" | "InputProps" | "FormHelperTextProps" | "helperText" | "SelectProps" | "showClear" | "showPassword"> | Pick<import("@mui/material").FilledTextFieldProps & {
|
|
60
|
+
/**
|
|
61
|
+
* Change delay (ms) to avoid repeatly dispatch onChange
|
|
62
|
+
*/
|
|
63
|
+
changeDelay?: number | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* On enter click
|
|
66
|
+
*/
|
|
67
|
+
onEnter?: React.KeyboardEventHandler<HTMLDivElement> | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Is the field read only?
|
|
70
|
+
*/
|
|
71
|
+
readOnly?: boolean | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Show clear button
|
|
74
|
+
*/
|
|
75
|
+
showClear?: boolean | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Show password button
|
|
78
|
+
*/
|
|
79
|
+
showPassword?: boolean | undefined;
|
|
80
|
+
}, "className" | "style" | "classes" | "children" | "sx" | "variant" | "label" | "slot" | "select" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "disabled" | "type" | "margin" | "size" | "name" | "autoFocus" | "value" | "autoComplete" | "readOnly" | "required" | "rows" | "fullWidth" | "error" | "inputProps" | "onEnter" | "inputRef" | "focused" | "hiddenLabel" | "multiline" | "maxRows" | "minRows" | "changeDelay" | "InputLabelProps" | "InputProps" | "FormHelperTextProps" | "helperText" | "SelectProps" | "showClear" | "showPassword"> | Pick<import("@mui/material").OutlinedTextFieldProps & {
|
|
81
|
+
/**
|
|
82
|
+
* Change delay (ms) to avoid repeatly dispatch onChange
|
|
83
|
+
*/
|
|
84
|
+
changeDelay?: number | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* On enter click
|
|
87
|
+
*/
|
|
88
|
+
onEnter?: React.KeyboardEventHandler<HTMLDivElement> | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Is the field read only?
|
|
91
|
+
*/
|
|
92
|
+
readOnly?: boolean | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Show clear button
|
|
95
|
+
*/
|
|
96
|
+
showClear?: boolean | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Show password button
|
|
99
|
+
*/
|
|
100
|
+
showPassword?: boolean | undefined;
|
|
101
|
+
}, "className" | "style" | "classes" | "children" | "sx" | "variant" | "label" | "slot" | "select" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "disabled" | "type" | "margin" | "size" | "name" | "autoFocus" | "value" | "autoComplete" | "readOnly" | "required" | "rows" | "fullWidth" | "error" | "inputProps" | "onEnter" | "inputRef" | "focused" | "hiddenLabel" | "multiline" | "maxRows" | "minRows" | "changeDelay" | "InputLabelProps" | "InputProps" | "FormHelperTextProps" | "helperText" | "SelectProps" | "showClear" | "showPassword">) & React.RefAttributes<TextFieldExMethods>>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IconButton, InputAdornment, TextField } from '@mui/material';
|
|
3
|
+
import { MUGlobal } from './MUGlobal';
|
|
4
|
+
import { Clear, Visibility } from '@mui/icons-material';
|
|
5
|
+
import { Keyboard } from '@etsoo/shared';
|
|
6
|
+
import { useCombinedRefs, useDelayedExecutor } from '@etsoo/react';
|
|
7
|
+
export const TextFieldEx = React.forwardRef((props, ref) => {
|
|
8
|
+
// Destructure
|
|
9
|
+
const { changeDelay, error, fullWidth = true, helperText, InputProps = {}, onChange, onKeyPress, onEnter, inputRef, readOnly, showClear, showPassword, type, variant = MUGlobal.textFieldVariant, ...rest } = props;
|
|
10
|
+
// State
|
|
11
|
+
const [errorText, updateErrorText] = React.useState();
|
|
12
|
+
const [empty, updateEmpty] = React.useState(true);
|
|
13
|
+
// Read only
|
|
14
|
+
if (readOnly != null)
|
|
15
|
+
InputProps.readOnly = readOnly;
|
|
16
|
+
// Calculate
|
|
17
|
+
let errorEx = error;
|
|
18
|
+
let helperTextEx = helperText;
|
|
19
|
+
if (errorText != null) {
|
|
20
|
+
errorEx = true;
|
|
21
|
+
helperTextEx = errorText;
|
|
22
|
+
}
|
|
23
|
+
let typeEx = showPassword ? 'password' : type;
|
|
24
|
+
let input;
|
|
25
|
+
const localRef = (ref) => {
|
|
26
|
+
input = ref;
|
|
27
|
+
if (input.value !== '') {
|
|
28
|
+
updateEmpty(false);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const clearClick = () => {
|
|
32
|
+
if (input != null) {
|
|
33
|
+
input.value = '';
|
|
34
|
+
input.focus();
|
|
35
|
+
}
|
|
36
|
+
if (errorText != null) {
|
|
37
|
+
// Reset
|
|
38
|
+
updateErrorText(undefined);
|
|
39
|
+
}
|
|
40
|
+
updateEmpty(true);
|
|
41
|
+
};
|
|
42
|
+
const preventDefault = (e) => {
|
|
43
|
+
// Prevent long press
|
|
44
|
+
if (e.isPropagationStopped())
|
|
45
|
+
e.stopPropagation();
|
|
46
|
+
if (e.isDefaultPrevented())
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
};
|
|
49
|
+
const touchStart = (e) => {
|
|
50
|
+
// Show the password
|
|
51
|
+
if (input) {
|
|
52
|
+
input.blur();
|
|
53
|
+
input.type = 'text';
|
|
54
|
+
}
|
|
55
|
+
preventDefault(e);
|
|
56
|
+
};
|
|
57
|
+
const touchEnd = (e) => {
|
|
58
|
+
// Show the password
|
|
59
|
+
if (input)
|
|
60
|
+
input.type = 'password';
|
|
61
|
+
preventDefault(e);
|
|
62
|
+
};
|
|
63
|
+
// Show password and/or clear button
|
|
64
|
+
if (!empty && (showPassword || showClear)) {
|
|
65
|
+
InputProps.endAdornment = (React.createElement(InputAdornment, { position: "end" },
|
|
66
|
+
showPassword && (React.createElement(IconButton, { tabIndex: -1, onContextMenu: (event) => event.preventDefault(), onMouseDown: touchStart, onMouseUp: touchEnd, onTouchStart: touchStart, onTouchCancel: touchEnd, onTouchEnd: touchEnd },
|
|
67
|
+
React.createElement(Visibility, null))),
|
|
68
|
+
showClear && (React.createElement(IconButton, { onClick: clearClick, tabIndex: -1 },
|
|
69
|
+
React.createElement(Clear, null)))));
|
|
70
|
+
}
|
|
71
|
+
// Extend key precess
|
|
72
|
+
const onKeyPressEx = onEnter == null
|
|
73
|
+
? onKeyPress
|
|
74
|
+
: (e) => {
|
|
75
|
+
if (e.key === Keyboard.Keys.Enter) {
|
|
76
|
+
// Enter press callback
|
|
77
|
+
onEnter(e);
|
|
78
|
+
}
|
|
79
|
+
if (!e.isDefaultPrevented && onKeyPress != null) {
|
|
80
|
+
// Common press callback
|
|
81
|
+
onKeyPress(e);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
React.useImperativeHandle(ref, () => ({
|
|
85
|
+
/**
|
|
86
|
+
* Set error
|
|
87
|
+
* @param error Error
|
|
88
|
+
*/
|
|
89
|
+
setError(error) {
|
|
90
|
+
updateErrorText(error);
|
|
91
|
+
}
|
|
92
|
+
}), []);
|
|
93
|
+
const isMounted = React.useRef(true);
|
|
94
|
+
const delayed = onChange != null && changeDelay != null && changeDelay >= 1
|
|
95
|
+
? useDelayedExecutor(onChange, changeDelay)
|
|
96
|
+
: undefined;
|
|
97
|
+
const onChangeEx = (event) => {
|
|
98
|
+
if (errorText != null) {
|
|
99
|
+
// Reset
|
|
100
|
+
updateErrorText(undefined);
|
|
101
|
+
}
|
|
102
|
+
if (showClear || showPassword) {
|
|
103
|
+
if (event.target.value === '') {
|
|
104
|
+
updateEmpty(true);
|
|
105
|
+
}
|
|
106
|
+
else if (empty) {
|
|
107
|
+
updateEmpty(false);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (onChange == null)
|
|
111
|
+
return;
|
|
112
|
+
if (changeDelay == null || changeDelay < 1) {
|
|
113
|
+
onChange(event);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
delayed === null || delayed === void 0 ? void 0 : delayed.call(undefined, event);
|
|
117
|
+
};
|
|
118
|
+
React.useEffect(() => {
|
|
119
|
+
return () => {
|
|
120
|
+
isMounted.current = false;
|
|
121
|
+
delayed === null || delayed === void 0 ? void 0 : delayed.clear();
|
|
122
|
+
};
|
|
123
|
+
}, []);
|
|
124
|
+
// Textfield
|
|
125
|
+
return (React.createElement(TextField, { error: errorEx, fullWidth: fullWidth, helperText: helperTextEx, inputRef: useCombinedRefs(inputRef, localRef), InputProps: InputProps, onChange: onChangeEx, onKeyPress: onKeyPressEx, type: typeEx, variant: variant, ...rest }));
|
|
126
|
+
});
|
package/lib/Tiplist.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { DataTypes, IdDefaultType, ListType } from '@etsoo/shared';
|
|
3
|
+
import { AutocompleteExtendedProps } from './AutocompleteExtendedProps';
|
|
4
|
+
/**
|
|
5
|
+
* Tiplist props
|
|
6
|
+
*/
|
|
7
|
+
export declare type TiplistProps<T extends object, D extends DataTypes.Keys<T>> = Omit<AutocompleteExtendedProps<T, D>, 'open'> & {
|
|
8
|
+
/**
|
|
9
|
+
* Load data callback
|
|
10
|
+
*/
|
|
11
|
+
loadData: (keyword?: string, id?: T[D]) => PromiseLike<T[] | null | undefined>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Tiplist
|
|
15
|
+
* @param props Props
|
|
16
|
+
* @returns Component
|
|
17
|
+
*/
|
|
18
|
+
export declare function Tiplist<T extends object = ListType, D extends DataTypes.Keys<T> = IdDefaultType<T>>(props: TiplistProps<T, D>): JSX.Element;
|