@etsoo/materialui 1.0.2 → 1.0.5

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/SelectEx.d.ts CHANGED
@@ -9,6 +9,14 @@ export declare type SelectExProps<T extends object, D extends DataTypes.Keys<T>
9
9
  * Auto add blank item
10
10
  */
11
11
  autoAddBlankItem?: boolean;
12
+ /**
13
+ * The helper text content.
14
+ */
15
+ helperText?: React.ReactNode;
16
+ /**
17
+ * Input required
18
+ */
19
+ inputRequired?: boolean;
12
20
  /**
13
21
  * Id field
14
22
  */
@@ -17,6 +25,10 @@ export declare type SelectExProps<T extends object, D extends DataTypes.Keys<T>
17
25
  * Item icon renderer
18
26
  */
19
27
  itemIconRenderer?: (id: T[D]) => React.ReactNode;
28
+ /**
29
+ * Item style
30
+ */
31
+ itemStyle?: (option: T) => React.CSSProperties;
20
32
  /**
21
33
  * Label field
22
34
  */
package/lib/SelectEx.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Checkbox, FormControl, InputLabel, ListItemText, MenuItem, OutlinedInput, Select } from '@mui/material';
1
+ import { Checkbox, FormControl, FormHelperText, InputLabel, ListItemText, MenuItem, OutlinedInput, Select } from '@mui/material';
2
2
  import React from 'react';
3
3
  import { MUGlobal } from './MUGlobal';
4
4
  import { ListItemRightIcon } from './ListItemRightIcon';
@@ -12,7 +12,7 @@ import { ReactUtils } from '@etsoo/react';
12
12
  export function SelectEx(props) {
13
13
  var _a;
14
14
  // Destruct
15
- const { defaultValue, idField = 'id', itemIconRenderer, label, labelField = 'label', loadData, onItemClick, onLoadData, multiple = false, name, options = [], search = false, autoAddBlankItem = search, value, onChange, fullWidth, ...rest } = props;
15
+ const { defaultValue, idField = 'id', error, helperText, inputRequired, itemIconRenderer, itemStyle, label, labelField = 'label', loadData, onItemClick, onLoadData, multiple = false, name, options = [], search = false, autoAddBlankItem = search, value, onChange, fullWidth, ...rest } = props;
16
16
  // Options state
17
17
  const [localOptions, setOptions] = React.useState(options);
18
18
  const isMounted = React.useRef(true);
@@ -112,13 +112,13 @@ export function SelectEx(props) {
112
112
  };
113
113
  }, []);
114
114
  // Layout
115
- return (React.createElement(FormControl, { size: search ? MUGlobal.searchFieldSize : MUGlobal.inputFieldSize, fullWidth: fullWidth },
115
+ return (React.createElement(FormControl, { size: search ? MUGlobal.searchFieldSize : MUGlobal.inputFieldSize, fullWidth: fullWidth, error: error },
116
116
  React.createElement(InputLabel, { id: labelId, shrink: search
117
117
  ? MUGlobal.searchFieldShrink
118
118
  : MUGlobal.inputFieldShrink }, label),
119
119
  React.createElement(Select, { ref: divRef, value: localOptions.some((option) => itemChecked(getId(option)))
120
120
  ? valueState !== null && valueState !== void 0 ? valueState : ''
121
- : '', input: React.createElement(OutlinedInput, { notched: true, label: label }), labelId: labelId, name: name, multiple: multiple, onChange: (event, child) => {
121
+ : '', input: React.createElement(OutlinedInput, { notched: true, label: label, required: inputRequired }), labelId: labelId, name: name, multiple: multiple, onChange: (event, child) => {
122
122
  if (onChange)
123
123
  onChange(event, child);
124
124
  if (multiple)
@@ -148,9 +148,12 @@ export function SelectEx(props) {
148
148
  }
149
149
  if (!multiple)
150
150
  setItemValue(id);
151
- } },
151
+ }, style: itemStyle == null
152
+ ? undefined
153
+ : itemStyle(option) },
152
154
  multiple && React.createElement(Checkbox, { checked: itemChecked(id) }),
153
155
  React.createElement(ListItemText, { primary: label }),
154
156
  itemIconRenderer && (React.createElement(ListItemRightIcon, null, itemIconRenderer(option[idField])))));
155
- }))));
157
+ })),
158
+ helperText != null && (React.createElement(FormHelperText, null, helperText))));
156
159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -49,17 +49,17 @@
49
49
  "@dnd-kit/core": "^6.0.5",
50
50
  "@dnd-kit/sortable": "^7.0.1",
51
51
  "@emotion/css": "^11.10.0",
52
- "@emotion/react": "^11.10.0",
53
- "@emotion/styled": "^11.10.0",
52
+ "@emotion/react": "^11.10.4",
53
+ "@emotion/styled": "^11.10.4",
54
54
  "@etsoo/appscript": "^1.2.88",
55
55
  "@etsoo/notificationbase": "^1.1.7",
56
- "@etsoo/react": "^1.5.85",
56
+ "@etsoo/react": "^1.5.86",
57
57
  "@etsoo/shared": "^1.1.51",
58
58
  "@mui/icons-material": "^5.10.3",
59
59
  "@mui/material": "^5.10.3",
60
60
  "@types/pica": "^9.0.1",
61
61
  "@types/pulltorefreshjs": "^0.1.5",
62
- "@types/react": "^18.0.17",
62
+ "@types/react": "^18.0.18",
63
63
  "@types/react-avatar-editor": "^13.0.0",
64
64
  "@types/react-dom": "^18.0.6",
65
65
  "@types/react-input-mask": "^3.0.1",
@@ -83,8 +83,8 @@
83
83
  "@testing-library/jest-dom": "^5.16.5",
84
84
  "@testing-library/react": "^13.3.0",
85
85
  "@types/jest": "^29.0.0",
86
- "@typescript-eslint/eslint-plugin": "^5.36.0",
87
- "@typescript-eslint/parser": "^5.36.0",
86
+ "@typescript-eslint/eslint-plugin": "^5.36.1",
87
+ "@typescript-eslint/parser": "^5.36.1",
88
88
  "eslint": "^8.23.0",
89
89
  "eslint-config-airbnb-base": "^15.0.0",
90
90
  "eslint-plugin-import": "^2.26.0",
package/src/SelectEx.tsx CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  Checkbox,
3
3
  FormControl,
4
+ FormHelperText,
4
5
  InputLabel,
5
6
  ListItemText,
6
7
  MenuItem,
@@ -34,6 +35,16 @@ export type SelectExProps<
34
35
  */
35
36
  autoAddBlankItem?: boolean;
36
37
 
38
+ /**
39
+ * The helper text content.
40
+ */
41
+ helperText?: React.ReactNode;
42
+
43
+ /**
44
+ * Input required
45
+ */
46
+ inputRequired?: boolean;
47
+
37
48
  /**
38
49
  * Id field
39
50
  */
@@ -44,6 +55,11 @@ export type SelectExProps<
44
55
  */
45
56
  itemIconRenderer?: (id: T[D]) => React.ReactNode;
46
57
 
58
+ /**
59
+ * Item style
60
+ */
61
+ itemStyle?: (option: T) => React.CSSProperties;
62
+
47
63
  /**
48
64
  * Label field
49
65
  */
@@ -89,7 +105,11 @@ export function SelectEx<
89
105
  const {
90
106
  defaultValue,
91
107
  idField = 'id' as D,
108
+ error,
109
+ helperText,
110
+ inputRequired,
92
111
  itemIconRenderer,
112
+ itemStyle,
93
113
  label,
94
114
  labelField = 'label' as L,
95
115
  loadData,
@@ -212,6 +232,7 @@ export function SelectEx<
212
232
  <FormControl
213
233
  size={search ? MUGlobal.searchFieldSize : MUGlobal.inputFieldSize}
214
234
  fullWidth={fullWidth}
235
+ error={error}
215
236
  >
216
237
  <InputLabel
217
238
  id={labelId}
@@ -230,7 +251,13 @@ export function SelectEx<
230
251
  ? valueState ?? ''
231
252
  : ''
232
253
  }
233
- input={<OutlinedInput notched label={label} />}
254
+ input={
255
+ <OutlinedInput
256
+ notched
257
+ label={label}
258
+ required={inputRequired}
259
+ />
260
+ }
234
261
  labelId={labelId}
235
262
  name={name}
236
263
  multiple={multiple}
@@ -273,6 +300,11 @@ export function SelectEx<
273
300
  }
274
301
  if (!multiple) setItemValue(id);
275
302
  }}
303
+ style={
304
+ itemStyle == null
305
+ ? undefined
306
+ : itemStyle(option)
307
+ }
276
308
  >
277
309
  {multiple && <Checkbox checked={itemChecked(id)} />}
278
310
  <ListItemText primary={label} />
@@ -285,6 +317,9 @@ export function SelectEx<
285
317
  );
286
318
  })}
287
319
  </Select>
320
+ {helperText != null && (
321
+ <FormHelperText>{helperText}</FormHelperText>
322
+ )}
288
323
  </FormControl>
289
324
  );
290
325
  }