@etsoo/materialui 1.1.39 → 1.1.42

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.
Files changed (42) hide show
  1. package/lib/AuditDisplay.d.ts +5 -5
  2. package/lib/AuditDisplay.js +17 -19
  3. package/lib/BridgeCloseButton.d.ts +2 -2
  4. package/lib/BridgeCloseButton.js +7 -8
  5. package/lib/DataSteps.d.ts +4 -4
  6. package/lib/DataSteps.js +17 -14
  7. package/lib/DataTable.d.ts +33 -0
  8. package/lib/DataTable.js +56 -0
  9. package/lib/ListMoreDisplay.d.ts +5 -5
  10. package/lib/ListMoreDisplay.js +8 -10
  11. package/lib/OptionBool.js +2 -1
  12. package/lib/SelectBool.js +2 -1
  13. package/lib/ShowDataComparison.d.ts +1 -1
  14. package/lib/ShowDataComparison.js +27 -20
  15. package/lib/SwitchAnt.d.ts +3 -3
  16. package/lib/SwitchAnt.js +11 -8
  17. package/lib/SwitchField.d.ts +45 -0
  18. package/lib/SwitchField.js +33 -0
  19. package/lib/Tiplist.js +4 -4
  20. package/lib/UserAvatar.js +7 -8
  21. package/lib/app/ReactApp.d.ts +7 -7
  22. package/lib/app/ReactApp.js +26 -26
  23. package/lib/index.d.ts +2 -0
  24. package/lib/index.js +2 -0
  25. package/lib/pages/ViewPage.d.ts +7 -7
  26. package/lib/pages/ViewPage.js +30 -29
  27. package/package.json +3 -2
  28. package/src/AuditDisplay.tsx +92 -99
  29. package/src/BridgeCloseButton.tsx +48 -50
  30. package/src/DataSteps.tsx +188 -185
  31. package/src/DataTable.tsx +124 -0
  32. package/src/ListMoreDisplay.tsx +184 -188
  33. package/src/OptionBool.tsx +1 -1
  34. package/src/SelectBool.tsx +1 -1
  35. package/src/ShowDataComparison.tsx +88 -76
  36. package/src/SwitchAnt.tsx +82 -78
  37. package/src/SwitchField.tsx +133 -0
  38. package/src/Tiplist.tsx +5 -4
  39. package/src/UserAvatar.tsx +43 -45
  40. package/src/app/ReactApp.ts +485 -489
  41. package/src/index.ts +2 -0
  42. package/src/pages/ViewPage.tsx +272 -277
package/src/index.ts CHANGED
@@ -41,6 +41,7 @@ export * from "./CustomFabProps";
41
41
  export * from "./DataGridEx";
42
42
  export * from "./DataGridRenderers";
43
43
  export * from "./DataSteps";
44
+ export * from "./DataTable";
44
45
  export * from "./DialogButton";
45
46
  export * from "./DnDList";
46
47
  export * from "./DraggablePaperComponent";
@@ -80,6 +81,7 @@ export * from "./SelectEx";
80
81
  export * from "./ShowDataComparison";
81
82
  export * from "./Switch";
82
83
  export * from "./SwitchAnt";
84
+ export * from "./SwitchField";
83
85
  export * from "./TabBox";
84
86
  export * from "./TableEx";
85
87
  export * from "./TextFieldEx";
@@ -1,184 +1,187 @@
1
- import { GridColumnRenderProps, GridDataType } from '@etsoo/react';
2
- import { DataTypes, Utils } from '@etsoo/shared';
1
+ import { GridColumnRenderProps, GridDataType } from "@etsoo/react";
2
+ import { DataTypes, DateUtils, Utils } from "@etsoo/shared";
3
3
  import {
4
- Grid,
5
- GridProps,
6
- LinearProgress,
7
- Stack,
8
- Typography
9
- } from '@mui/material';
10
- import React from 'react';
11
- import { Labels } from '../app/Labels';
12
- import { globalApp } from '../app/ReactApp';
13
- import { GridDataFormat } from '../GridDataFormat';
14
- import { MUGlobal } from '../MUGlobal';
15
- import { PullToRefreshUI } from '../PullToRefreshUI';
16
- import { CommonPage } from './CommonPage';
17
- import { CommonPageProps } from './CommonPageProps';
4
+ Grid,
5
+ GridProps,
6
+ LinearProgress,
7
+ Stack,
8
+ Typography
9
+ } from "@mui/material";
10
+ import React from "react";
11
+ import { Labels } from "../app/Labels";
12
+ import { globalApp } from "../app/ReactApp";
13
+ import { GridDataFormat } from "../GridDataFormat";
14
+ import { MUGlobal } from "../MUGlobal";
15
+ import { PullToRefreshUI } from "../PullToRefreshUI";
16
+ import { CommonPage } from "./CommonPage";
17
+ import { CommonPageProps } from "./CommonPageProps";
18
18
 
19
19
  /**
20
20
  * View page row width type
21
21
  */
22
- export type ViewPageRowType = boolean | 'default' | 'small' | object;
22
+ export type ViewPageRowType = boolean | "default" | "small" | object;
23
23
 
24
24
  /**
25
25
  * View page display field
26
26
  */
27
27
  export interface ViewPageField<T extends object> extends GridProps {
28
- /**
29
- * Data field
30
- */
31
- data: (string & keyof T) | ((item: T) => React.ReactNode);
32
-
33
- /**
34
- * Data type
35
- */
36
- dataType?: GridDataType;
37
-
38
- /**
39
- * Label field
40
- */
41
- label?: string | (() => React.ReactNode);
42
-
43
- /**
44
- * Display as single row
45
- */
46
- singleRow?: ViewPageRowType;
47
-
48
- /**
49
- * Render props
50
- */
51
- renderProps?: GridColumnRenderProps;
28
+ /**
29
+ * Data field
30
+ */
31
+ data: (string & keyof T) | ((item: T) => React.ReactNode);
32
+
33
+ /**
34
+ * Data type
35
+ */
36
+ dataType?: GridDataType;
37
+
38
+ /**
39
+ * Label field
40
+ */
41
+ label?: string | (() => React.ReactNode);
42
+
43
+ /**
44
+ * Display as single row
45
+ */
46
+ singleRow?: ViewPageRowType;
47
+
48
+ /**
49
+ * Render props
50
+ */
51
+ renderProps?: GridColumnRenderProps;
52
52
  }
53
53
 
54
54
  type ViewPageFieldTypeNarrow<T extends object> =
55
- | (string & keyof T)
56
- | [string & keyof T, GridDataType, GridColumnRenderProps?, ViewPageRowType?]
57
- | ViewPageField<T>;
55
+ | (string & keyof T)
56
+ | [string & keyof T, GridDataType, GridColumnRenderProps?, ViewPageRowType?]
57
+ | ViewPageField<T>;
58
58
 
59
59
  /**
60
60
  * View page field type
61
61
  */
62
62
  export type ViewPageFieldType<T extends object> =
63
- | ViewPageFieldTypeNarrow<T>
64
- | ((data: T) => React.ReactNode);
63
+ | ViewPageFieldTypeNarrow<T>
64
+ | ((data: T) => React.ReactNode);
65
65
 
66
66
  /**
67
67
  * View page props
68
68
  */
69
69
  export interface ViewPageProps<T extends DataTypes.StringRecord>
70
- extends Omit<CommonPageProps, 'children'> {
71
- /**
72
- * Actions
73
- */
74
- actions?:
75
- | React.ReactNode
76
- | ((data: T, refresh: () => PromiseLike<void>) => React.ReactNode);
77
-
78
- /**
79
- * Children
80
- */
81
- children?:
82
- | React.ReactNode
83
- | ((data: T, refresh: () => PromiseLike<void>) => React.ReactNode);
84
-
85
- /**
86
- * Fields to display
87
- */
88
- fields: ViewPageFieldType<T>[];
89
-
90
- /**
91
- * Load data
92
- */
93
- loadData: () => PromiseLike<T | undefined>;
94
-
95
- /**
96
- * Pull to refresh data
97
- */
98
- pullToRefresh?: boolean;
99
-
100
- /**
101
- * Support refresh
102
- */
103
- supportRefresh?: boolean;
104
-
105
- /**
106
- * Grid container reference
107
- */
108
- gridRef?: React.Ref<HTMLDivElement>;
70
+ extends Omit<CommonPageProps, "children"> {
71
+ /**
72
+ * Actions
73
+ */
74
+ actions?:
75
+ | React.ReactNode
76
+ | ((data: T, refresh: () => PromiseLike<void>) => React.ReactNode);
77
+
78
+ /**
79
+ * Children
80
+ */
81
+ children?:
82
+ | React.ReactNode
83
+ | ((data: T, refresh: () => PromiseLike<void>) => React.ReactNode);
84
+
85
+ /**
86
+ * Fields to display
87
+ */
88
+ fields: ViewPageFieldType<T>[];
89
+
90
+ /**
91
+ * Load data
92
+ */
93
+ loadData: () => PromiseLike<T | undefined>;
94
+
95
+ /**
96
+ * Pull to refresh data
97
+ */
98
+ pullToRefresh?: boolean;
99
+
100
+ /**
101
+ * Support refresh
102
+ */
103
+ supportRefresh?: boolean;
104
+
105
+ /**
106
+ * Grid container reference
107
+ */
108
+ gridRef?: React.Ref<HTMLDivElement>;
109
109
  }
110
110
 
111
111
  function formatItemData(fieldData: unknown): string | undefined {
112
- if (fieldData == null) return undefined;
113
- if (typeof fieldData === 'string') return fieldData;
114
- if (fieldData instanceof Date) return globalApp.formatDate(fieldData, 'd');
115
- return `${fieldData}`;
112
+ if (fieldData == null) return undefined;
113
+ if (typeof fieldData === "string") return fieldData;
114
+ if (fieldData instanceof Date)
115
+ return globalApp
116
+ ? globalApp.formatDate(fieldData, "d")
117
+ : DateUtils.format(fieldData, "d");
118
+ return `${fieldData}`;
116
119
  }
117
120
 
118
121
  function getResp(singleRow: ViewPageRowType) {
119
- return typeof singleRow === 'object'
120
- ? singleRow
121
- : singleRow === 'default'
122
- ? { xs: 12, sm: 12, md: 12, lg: 6, xl: 6 }
123
- : singleRow === true
124
- ? { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }
125
- : {
126
- xs: singleRow === false ? 12 : 6,
127
- sm: 6,
128
- md: 6,
129
- lg: 4,
130
- xl: 3
131
- };
122
+ return typeof singleRow === "object"
123
+ ? singleRow
124
+ : singleRow === "default"
125
+ ? { xs: 12, sm: 12, md: 12, lg: 6, xl: 6 }
126
+ : singleRow === true
127
+ ? { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 }
128
+ : {
129
+ xs: singleRow === false ? 12 : 6,
130
+ sm: 6,
131
+ md: 6,
132
+ lg: 4,
133
+ xl: 3
134
+ };
132
135
  }
133
136
 
134
137
  function getItemField<T extends object>(
135
- field: ViewPageFieldTypeNarrow<T>,
136
- data: T
138
+ field: ViewPageFieldTypeNarrow<T>,
139
+ data: T
137
140
  ): [React.ReactNode, React.ReactNode, GridProps] {
138
- // Item data and label
139
- let itemData: React.ReactNode,
140
- itemLabel: React.ReactNode,
141
- gridProps: GridProps = {};
142
-
143
- if (Array.isArray(field)) {
144
- const [fieldData, fieldType, renderProps, singleRow = 'small'] = field;
145
- itemData = GridDataFormat(data[fieldData], fieldType, renderProps);
146
- itemLabel = globalApp.get<string>(fieldData) ?? fieldData;
147
- gridProps = { ...getResp(singleRow) };
148
- } else if (typeof field === 'object') {
149
- // Destruct
150
- const {
151
- data: fieldData,
152
- dataType,
153
- label: fieldLabel,
154
- renderProps,
155
- singleRow = 'default',
156
- ...rest
157
- } = field;
158
-
159
- gridProps = {
160
- ...rest,
161
- ...getResp(singleRow)
162
- };
163
-
164
- // Field data
165
- if (typeof fieldData === 'function') itemData = fieldData(data);
166
- else if (dataType == null) itemData = formatItemData(data[fieldData]);
167
- else itemData = GridDataFormat(data[fieldData], dataType, renderProps);
168
-
169
- // Field label
170
- itemLabel =
171
- typeof fieldLabel === 'function'
172
- ? fieldLabel()
173
- : fieldLabel != null
174
- ? globalApp.get<string>(fieldLabel) ?? fieldLabel
175
- : fieldLabel;
176
- } else {
177
- itemData = formatItemData(data[field]);
178
- itemLabel = globalApp.get<string>(field) ?? field;
179
- }
180
-
181
- return [itemData, itemLabel, gridProps];
141
+ // Item data and label
142
+ let itemData: React.ReactNode,
143
+ itemLabel: React.ReactNode,
144
+ gridProps: GridProps = {};
145
+
146
+ if (Array.isArray(field)) {
147
+ const [fieldData, fieldType, renderProps, singleRow = "small"] = field;
148
+ itemData = GridDataFormat(data[fieldData], fieldType, renderProps);
149
+ itemLabel = globalApp?.get<string>(fieldData) ?? fieldData;
150
+ gridProps = { ...getResp(singleRow) };
151
+ } else if (typeof field === "object") {
152
+ // Destruct
153
+ const {
154
+ data: fieldData,
155
+ dataType,
156
+ label: fieldLabel,
157
+ renderProps,
158
+ singleRow = "default",
159
+ ...rest
160
+ } = field;
161
+
162
+ gridProps = {
163
+ ...rest,
164
+ ...getResp(singleRow)
165
+ };
166
+
167
+ // Field data
168
+ if (typeof fieldData === "function") itemData = fieldData(data);
169
+ else if (dataType == null) itemData = formatItemData(data[fieldData]);
170
+ else itemData = GridDataFormat(data[fieldData], dataType, renderProps);
171
+
172
+ // Field label
173
+ itemLabel =
174
+ typeof fieldLabel === "function"
175
+ ? fieldLabel()
176
+ : fieldLabel != null
177
+ ? globalApp?.get<string>(fieldLabel) ?? fieldLabel
178
+ : fieldLabel;
179
+ } else {
180
+ itemData = formatItemData(data[field]);
181
+ itemLabel = globalApp?.get<string>(field) ?? field;
182
+ }
183
+
184
+ return [itemData, itemLabel, gridProps];
182
185
  }
183
186
 
184
187
  /**
@@ -186,134 +189,126 @@ function getItemField<T extends object>(
186
189
  * @param props Props
187
190
  */
188
191
  export function ViewPage<T extends DataTypes.StringRecord>(
189
- props: ViewPageProps<T>
192
+ props: ViewPageProps<T>
190
193
  ) {
191
- // Destruct
192
- const {
193
- actions,
194
- children,
195
- fields,
196
- loadData,
197
- paddings = MUGlobal.pagePaddings,
198
- supportRefresh = true,
199
- fabColumnDirection = true,
200
- supportBack = true,
201
- pullToRefresh = true,
202
- gridRef,
203
- ...rest
204
- } = props;
205
-
206
- // Data
207
- const [data, setData] = React.useState<T>();
208
-
209
- // Labels
210
- const labels = Labels.CommonPage;
211
-
212
- // Container
213
- const pullContainer = '#page-container';
214
-
215
- // Load data
216
- const refresh = async () => {
217
- const result = await loadData();
218
- if (result == null) return;
219
- setData(result);
220
- };
221
-
222
- return (
223
- <CommonPage
224
- paddings={paddings}
225
- onRefresh={supportRefresh ? refresh : undefined}
226
- onUpdate={supportRefresh ? undefined : refresh}
227
- {...rest}
228
- scrollContainer={globalThis}
229
- fabColumnDirection={fabColumnDirection}
230
- supportBack={supportBack}
231
- >
232
- {data == null ? (
233
- <LinearProgress />
234
- ) : (
235
- <React.Fragment>
236
- <Grid
237
- container
238
- justifyContent="left"
239
- spacing={paddings}
240
- className="ET-ViewPage"
241
- ref={gridRef}
242
- sx={{
243
- '.MuiTypography-subtitle2': {
244
- fontWeight: 'bold'
245
- }
246
- }}
247
- >
248
- {fields.map((field, index) => {
249
- // Get data
250
- if (typeof field === 'function') {
251
- // Most flexible way, do whatever you want
252
- return field(data);
253
- }
254
-
255
- const [itemData, itemLabel, gridProps] =
256
- getItemField(field, data);
257
-
258
- // Some callback function may return '' instead of undefined
259
- if (itemData == null || itemData === '')
260
- return undefined;
261
-
262
- // Layout
263
- return (
264
- <Grid item {...gridProps} key={index}>
265
- {itemLabel != null && (
266
- <Typography
267
- variant="caption"
268
- component="div"
269
- >
270
- {itemLabel}:
271
- </Typography>
272
- )}
273
- {typeof itemData === 'object' ? (
274
- itemData
275
- ) : (
276
- <Typography variant="subtitle2">
277
- {itemData}
278
- </Typography>
279
- )}
280
- </Grid>
281
- );
282
- })}
283
- </Grid>
284
- <Stack
285
- className="ET-ViewPage-Actions"
286
- direction="row"
287
- width="100%"
288
- flexWrap="wrap"
289
- justifyContent="flex-end"
290
- paddingTop={actions == null ? undefined : paddings}
291
- paddingBottom={paddings}
292
- gap={paddings}
293
- >
294
- {actions != null &&
295
- Utils.getResult(actions, data, refresh)}
296
- </Stack>
297
- {Utils.getResult(children, data, refresh)}
298
- {pullToRefresh && (
299
- <PullToRefreshUI
300
- mainElement={pullContainer}
301
- triggerElement={pullContainer}
302
- instructionsPullToRefresh={labels.pullToRefresh}
303
- instructionsReleaseToRefresh={
304
- labels.releaseToRefresh
305
- }
306
- instructionsRefreshing={labels.refreshing}
307
- onRefresh={refresh}
308
- shouldPullToRefresh={() => {
309
- const container =
310
- document.querySelector(pullContainer);
311
- return !container?.scrollTop;
312
- }}
313
- />
314
- )}
315
- </React.Fragment>
316
- )}
317
- </CommonPage>
318
- );
194
+ // Destruct
195
+ const {
196
+ actions,
197
+ children,
198
+ fields,
199
+ loadData,
200
+ paddings = MUGlobal.pagePaddings,
201
+ supportRefresh = true,
202
+ fabColumnDirection = true,
203
+ supportBack = true,
204
+ pullToRefresh = true,
205
+ gridRef,
206
+ ...rest
207
+ } = props;
208
+
209
+ // Data
210
+ const [data, setData] = React.useState<T>();
211
+
212
+ // Labels
213
+ const labels = Labels.CommonPage;
214
+
215
+ // Container
216
+ const pullContainer = "#page-container";
217
+
218
+ // Load data
219
+ const refresh = async () => {
220
+ const result = await loadData();
221
+ if (result == null) return;
222
+ setData(result);
223
+ };
224
+
225
+ return (
226
+ <CommonPage
227
+ paddings={paddings}
228
+ onRefresh={supportRefresh ? refresh : undefined}
229
+ onUpdate={supportRefresh ? undefined : refresh}
230
+ {...rest}
231
+ scrollContainer={globalThis}
232
+ fabColumnDirection={fabColumnDirection}
233
+ supportBack={supportBack}
234
+ >
235
+ {data == null ? (
236
+ <LinearProgress />
237
+ ) : (
238
+ <React.Fragment>
239
+ <Grid
240
+ container
241
+ justifyContent="left"
242
+ spacing={paddings}
243
+ className="ET-ViewPage"
244
+ ref={gridRef}
245
+ sx={{
246
+ ".MuiTypography-subtitle2": {
247
+ fontWeight: "bold"
248
+ }
249
+ }}
250
+ >
251
+ {fields.map((field, index) => {
252
+ // Get data
253
+ if (typeof field === "function") {
254
+ // Most flexible way, do whatever you want
255
+ return field(data);
256
+ }
257
+
258
+ const [itemData, itemLabel, gridProps] = getItemField(
259
+ field,
260
+ data
261
+ );
262
+
263
+ // Some callback function may return '' instead of undefined
264
+ if (itemData == null || itemData === "") return undefined;
265
+
266
+ // Layout
267
+ return (
268
+ <Grid item {...gridProps} key={index}>
269
+ {itemLabel != null && (
270
+ <Typography variant="caption" component="div">
271
+ {itemLabel}:
272
+ </Typography>
273
+ )}
274
+ {typeof itemData === "object" ? (
275
+ itemData
276
+ ) : (
277
+ <Typography variant="subtitle2">{itemData}</Typography>
278
+ )}
279
+ </Grid>
280
+ );
281
+ })}
282
+ </Grid>
283
+ <Stack
284
+ className="ET-ViewPage-Actions"
285
+ direction="row"
286
+ width="100%"
287
+ flexWrap="wrap"
288
+ justifyContent="flex-end"
289
+ paddingTop={actions == null ? undefined : paddings}
290
+ paddingBottom={paddings}
291
+ gap={paddings}
292
+ >
293
+ {actions != null && Utils.getResult(actions, data, refresh)}
294
+ </Stack>
295
+ {Utils.getResult(children, data, refresh)}
296
+ {pullToRefresh && (
297
+ <PullToRefreshUI
298
+ mainElement={pullContainer}
299
+ triggerElement={pullContainer}
300
+ instructionsPullToRefresh={labels.pullToRefresh}
301
+ instructionsReleaseToRefresh={labels.releaseToRefresh}
302
+ instructionsRefreshing={labels.refreshing}
303
+ onRefresh={refresh}
304
+ shouldPullToRefresh={() => {
305
+ const container = document.querySelector(pullContainer);
306
+ return !container?.scrollTop;
307
+ }}
308
+ />
309
+ )}
310
+ </React.Fragment>
311
+ )}
312
+ </CommonPage>
313
+ );
319
314
  }