@etsoo/materialui 1.0.4 → 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 +8 -0
- package/lib/SelectEx.js +6 -5
- package/package.json +1 -1
- package/src/SelectEx.tsx +25 -1
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
|
*/
|
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, itemStyle, 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)
|
|
@@ -154,5 +154,6 @@ export function SelectEx(props) {
|
|
|
154
154
|
multiple && React.createElement(Checkbox, { checked: itemChecked(id) }),
|
|
155
155
|
React.createElement(ListItemText, { primary: label }),
|
|
156
156
|
itemIconRenderer && (React.createElement(ListItemRightIcon, null, itemIconRenderer(option[idField])))));
|
|
157
|
-
}))
|
|
157
|
+
})),
|
|
158
|
+
helperText != null && (React.createElement(FormHelperText, null, helperText))));
|
|
158
159
|
}
|
package/package.json
CHANGED
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
|
*/
|
|
@@ -94,6 +105,9 @@ export function SelectEx<
|
|
|
94
105
|
const {
|
|
95
106
|
defaultValue,
|
|
96
107
|
idField = 'id' as D,
|
|
108
|
+
error,
|
|
109
|
+
helperText,
|
|
110
|
+
inputRequired,
|
|
97
111
|
itemIconRenderer,
|
|
98
112
|
itemStyle,
|
|
99
113
|
label,
|
|
@@ -218,6 +232,7 @@ export function SelectEx<
|
|
|
218
232
|
<FormControl
|
|
219
233
|
size={search ? MUGlobal.searchFieldSize : MUGlobal.inputFieldSize}
|
|
220
234
|
fullWidth={fullWidth}
|
|
235
|
+
error={error}
|
|
221
236
|
>
|
|
222
237
|
<InputLabel
|
|
223
238
|
id={labelId}
|
|
@@ -236,7 +251,13 @@ export function SelectEx<
|
|
|
236
251
|
? valueState ?? ''
|
|
237
252
|
: ''
|
|
238
253
|
}
|
|
239
|
-
input={
|
|
254
|
+
input={
|
|
255
|
+
<OutlinedInput
|
|
256
|
+
notched
|
|
257
|
+
label={label}
|
|
258
|
+
required={inputRequired}
|
|
259
|
+
/>
|
|
260
|
+
}
|
|
240
261
|
labelId={labelId}
|
|
241
262
|
name={name}
|
|
242
263
|
multiple={multiple}
|
|
@@ -296,6 +317,9 @@ export function SelectEx<
|
|
|
296
317
|
);
|
|
297
318
|
})}
|
|
298
319
|
</Select>
|
|
320
|
+
{helperText != null && (
|
|
321
|
+
<FormHelperText>{helperText}</FormHelperText>
|
|
322
|
+
)}
|
|
299
323
|
</FormControl>
|
|
300
324
|
);
|
|
301
325
|
}
|