@etsoo/materialui 1.2.54 → 1.2.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/HiSelector.js CHANGED
@@ -44,7 +44,7 @@ export function HiSelector(props) {
44
44
  React.createElement(FormLabel, { required: required, sx: { fontSize: (theme) => theme.typography.caption } }, label))),
45
45
  React.createElement("input", { type: "hidden", name: name, value: `${currentValue !== null && currentValue !== void 0 ? currentValue : ""}` }),
46
46
  React.createElement(Grid, { item: true, ...breakPoints },
47
- React.createElement(SelectEx, { idField: idField, labelField: labelField, name: "tab1", search: search, fullWidth: true, loadData: () => loadData(), value: values[0], onChange: (event) => doChange(event, 0), onItemChange: doItemChange, inputRequired: required, error: error, helperText: helperText })),
47
+ React.createElement(SelectEx, { idField: idField, labelField: labelField, name: "tab1", search: search, fullWidth: true, loadData: () => loadData(), value: values[0], onChange: (event) => doChange(event, 0), onItemChange: doItemChange, required: required, error: error, helperText: helperText })),
48
48
  localValues[0] != null && (React.createElement(Grid, { item: true, ...breakPoints },
49
49
  React.createElement(SelectEx, { key: `${localValues[0]}`, idField: idField, labelField: labelField, name: "tab2", search: search, fullWidth: true, loadData: () => loadData(localValues[0]), value: values[1], onChange: (event) => doChange(event, 1), onItemChange: doItemChange }))),
50
50
  localValues[1] != null && (React.createElement(Grid, { item: true, ...breakPoints },
package/lib/SelectEx.d.ts CHANGED
@@ -13,10 +13,6 @@ export type SelectExProps<T extends object, D extends DataTypes.Keys<T> = IdDefa
13
13
  * The helper text content.
14
14
  */
15
15
  helperText?: React.ReactNode;
16
- /**
17
- * Input required
18
- */
19
- inputRequired?: boolean;
20
16
  /**
21
17
  * Id field
22
18
  */
package/lib/SelectEx.js CHANGED
@@ -12,7 +12,7 @@ import { ReactUtils } from "@etsoo/react";
12
12
  */
13
13
  export function SelectEx(props) {
14
14
  // Destruct
15
- const { defaultValue, idField = "id", error, helperText, inputRequired, itemIconRenderer, itemStyle, label, labelField = "label", loadData, onItemChange, onItemClick, onLoadData, multiple = false, name, options, refresh, search = false, autoAddBlankItem = search, value, onChange, fullWidth, ...rest } = props;
15
+ const { defaultValue, idField = "id", error, helperText, itemIconRenderer, itemStyle, label, labelField = "label", loadData, onItemChange, onItemClick, onLoadData, multiple = false, name, options, refresh, search = false, autoAddBlankItem = search, value, onChange, fullWidth, required, variant = "outlined", ...rest } = props;
16
16
  // Options state
17
17
  const [localOptions, setOptions] = React.useState([]);
18
18
  const isMounted = React.useRef(false);
@@ -128,12 +128,12 @@ export function SelectEx(props) {
128
128
  // Layout
129
129
  return (React.createElement(Stack, { direction: "row" },
130
130
  React.createElement(FormControl, { size: search ? MUGlobal.searchFieldSize : MUGlobal.inputFieldSize, fullWidth: fullWidth, error: error },
131
- React.createElement(InputLabel, { id: labelId, shrink: search ? MUGlobal.searchFieldShrink : MUGlobal.inputFieldShrink }, label),
131
+ React.createElement(InputLabel, { id: labelId, variant: variant, shrink: search ? MUGlobal.searchFieldShrink : MUGlobal.inputFieldShrink, required: required }, label),
132
132
  React.createElement(Select, { ref: divRef, value: multiple
133
133
  ? valueState
134
134
  : localOptions.some((o) => o[idField] === valueState)
135
135
  ? valueState
136
- : "", input: React.createElement(OutlinedInput, { notched: true, label: label, required: inputRequired }), labelId: labelId, name: name, multiple: multiple, onChange: (event, child) => {
136
+ : "", input: React.createElement(OutlinedInput, { notched: true, label: label, required: required }), labelId: labelId, name: name, multiple: multiple, onChange: (event, child) => {
137
137
  if (onChange) {
138
138
  onChange(event, child);
139
139
  // event.preventDefault() will block executing
@@ -159,7 +159,7 @@ export function SelectEx(props) {
159
159
  })
160
160
  .map((option) => getLabel(option))
161
161
  .join(", ");
162
- }, sx: { minWidth: "150px" }, fullWidth: fullWidth, ...rest }, localOptions.map((option) => {
162
+ }, sx: { minWidth: "150px" }, fullWidth: fullWidth, required: required, variant: variant, ...rest }, localOptions.map((option) => {
163
163
  // Option id
164
164
  const id = getId(option);
165
165
  // Option label
@@ -73,6 +73,10 @@ export interface ViewPageProps<T extends DataTypes.StringRecord> extends Omit<Co
73
73
  * Grid container reference
74
74
  */
75
75
  gridRef?: React.Ref<HTMLDivElement>;
76
+ /**
77
+ * Refresh seed
78
+ */
79
+ refreshSeed?: number;
76
80
  }
77
81
  /**
78
82
  * View page
@@ -78,7 +78,7 @@ function getItemField(field, data) {
78
78
  */
79
79
  export function ViewPage(props) {
80
80
  // Destruct
81
- const { actions, children, fields, loadData, paddings = MUGlobal.pagePaddings, spacing = MUGlobal.half(MUGlobal.pagePaddings), supportRefresh = true, fabColumnDirection = true, fabTop = true, supportBack = true, pullToRefresh = true, gridRef, ...rest } = props;
81
+ const { actions, children, fields, loadData, paddings = MUGlobal.pagePaddings, spacing = MUGlobal.half(MUGlobal.pagePaddings), supportRefresh = true, fabColumnDirection = true, fabTop = true, supportBack = true, pullToRefresh = true, gridRef, refreshSeed = 0, ...rest } = props;
82
82
  // Data
83
83
  const [data, setData] = React.useState();
84
84
  // Labels
@@ -86,12 +86,18 @@ export function ViewPage(props) {
86
86
  // Container
87
87
  const pullContainer = "#page-container";
88
88
  // Load data
89
- const refresh = async () => {
89
+ const refresh = React.useCallback(async () => {
90
90
  const result = await loadData();
91
91
  if (result == null)
92
92
  return;
93
93
  setData(result);
94
- };
94
+ }, [loadData]);
95
+ React.useEffect(() => {
96
+ // Only refresh after the first data load
97
+ if (refreshSeed === 0 || data == null)
98
+ return;
99
+ refresh();
100
+ }, [refreshSeed]);
95
101
  return (React.createElement(CommonPage, { paddings: paddings, onRefresh: supportRefresh ? refresh : undefined, onUpdate: supportRefresh ? undefined : refresh, ...rest, scrollContainer: globalThis, fabColumnDirection: fabColumnDirection, fabTop: fabTop, supportBack: supportBack }, data == null ? (React.createElement(LinearProgress, null)) : (React.createElement(React.Fragment, null,
96
102
  React.createElement(Grid, { container: true, justifyContent: "left", spacing: spacing, className: "ET-ViewPage", ref: gridRef, sx: {
97
103
  ".MuiTypography-subtitle2": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.2.54",
3
+ "version": "1.2.57",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,18 +50,18 @@
50
50
  "@emotion/css": "^11.11.0",
51
51
  "@emotion/react": "^11.11.1",
52
52
  "@emotion/styled": "^11.11.0",
53
- "@etsoo/appscript": "^1.4.15",
53
+ "@etsoo/appscript": "^1.4.19",
54
54
  "@etsoo/notificationbase": "^1.1.25",
55
55
  "@etsoo/react": "^1.6.90",
56
56
  "@etsoo/shared": "^1.2.5",
57
57
  "@mui/icons-material": "^5.11.16",
58
- "@mui/material": "^5.13.4",
58
+ "@mui/material": "^5.13.5",
59
59
  "@mui/x-data-grid": "^6.7.0",
60
60
  "@types/pica": "^9.0.1",
61
61
  "@types/pulltorefreshjs": "^0.1.5",
62
- "@types/react": "^18.2.11",
62
+ "@types/react": "^18.2.12",
63
63
  "@types/react-avatar-editor": "^13.0.0",
64
- "@types/react-dom": "^18.2.4",
64
+ "@types/react-dom": "^18.2.5",
65
65
  "@types/react-input-mask": "^3.0.2",
66
66
  "chart.js": "^4.3.0",
67
67
  "chartjs-plugin-datalabels": "^2.2.0",
@@ -85,8 +85,8 @@
85
85
  "@testing-library/jest-dom": "^5.16.5",
86
86
  "@testing-library/react": "^14.0.0",
87
87
  "@types/jest": "^29.5.2",
88
- "@typescript-eslint/eslint-plugin": "^5.59.9",
89
- "@typescript-eslint/parser": "^5.59.9",
88
+ "@typescript-eslint/eslint-plugin": "^5.59.11",
89
+ "@typescript-eslint/parser": "^5.59.11",
90
90
  "jest": "^29.5.0",
91
91
  "jest-environment-jsdom": "^29.5.0",
92
92
  "typescript": "^5.1.3"
@@ -175,7 +175,7 @@ export function HiSelector<
175
175
  value={values[0]}
176
176
  onChange={(event) => doChange(event, 0)}
177
177
  onItemChange={doItemChange}
178
- inputRequired={required}
178
+ required={required}
179
179
  error={error}
180
180
  helperText={helperText}
181
181
  />
package/src/SelectEx.tsx CHANGED
@@ -43,11 +43,6 @@ export type SelectExProps<
43
43
  */
44
44
  helperText?: React.ReactNode;
45
45
 
46
- /**
47
- * Input required
48
- */
49
- inputRequired?: boolean;
50
-
51
46
  /**
52
47
  * Id field
53
48
  */
@@ -120,7 +115,6 @@ export function SelectEx<
120
115
  idField = "id" as D,
121
116
  error,
122
117
  helperText,
123
- inputRequired,
124
118
  itemIconRenderer,
125
119
  itemStyle,
126
120
  label,
@@ -138,6 +132,8 @@ export function SelectEx<
138
132
  value,
139
133
  onChange,
140
134
  fullWidth,
135
+ required,
136
+ variant = "outlined",
141
137
  ...rest
142
138
  } = props;
143
139
 
@@ -278,9 +274,11 @@ export function SelectEx<
278
274
  >
279
275
  <InputLabel
280
276
  id={labelId}
277
+ variant={variant}
281
278
  shrink={
282
279
  search ? MUGlobal.searchFieldShrink : MUGlobal.inputFieldShrink
283
280
  }
281
+ required={required}
284
282
  >
285
283
  {label}
286
284
  </InputLabel>
@@ -293,9 +291,7 @@ export function SelectEx<
293
291
  ? valueState
294
292
  : ""
295
293
  }
296
- input={
297
- <OutlinedInput notched label={label} required={inputRequired} />
298
- }
294
+ input={<OutlinedInput notched label={label} required={required} />}
299
295
  labelId={labelId}
300
296
  name={name}
301
297
  multiple={multiple}
@@ -330,6 +326,8 @@ export function SelectEx<
330
326
  }}
331
327
  sx={{ minWidth: "150px" }}
332
328
  fullWidth={fullWidth}
329
+ required={required}
330
+ variant={variant}
333
331
  {...rest}
334
332
  >
335
333
  {localOptions.map((option) => {
@@ -115,6 +115,11 @@ export interface ViewPageProps<T extends DataTypes.StringRecord>
115
115
  * Grid container reference
116
116
  */
117
117
  gridRef?: React.Ref<HTMLDivElement>;
118
+
119
+ /**
120
+ * Refresh seed
121
+ */
122
+ refreshSeed?: number;
118
123
  }
119
124
 
120
125
  function formatItemData(fieldData: unknown): string | undefined {
@@ -214,6 +219,7 @@ export function ViewPage<T extends DataTypes.StringRecord>(
214
219
  supportBack = true,
215
220
  pullToRefresh = true,
216
221
  gridRef,
222
+ refreshSeed = 0,
217
223
  ...rest
218
224
  } = props;
219
225
 
@@ -227,11 +233,17 @@ export function ViewPage<T extends DataTypes.StringRecord>(
227
233
  const pullContainer = "#page-container";
228
234
 
229
235
  // Load data
230
- const refresh = async () => {
236
+ const refresh = React.useCallback(async () => {
231
237
  const result = await loadData();
232
238
  if (result == null) return;
233
239
  setData(result);
234
- };
240
+ }, [loadData]);
241
+
242
+ React.useEffect(() => {
243
+ // Only refresh after the first data load
244
+ if (refreshSeed === 0 || data == null) return;
245
+ refresh();
246
+ }, [refreshSeed]);
235
247
 
236
248
  return (
237
249
  <CommonPage