@etsoo/react 1.2.56 → 1.2.60
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/mu/ComboBox.js +10 -3
- package/lib/mu/MaskInput.js +9 -2
- package/lib/mu/SelectEx.d.ts +2 -2
- package/lib/mu/SelectEx.js +5 -1
- package/lib/mu/Tiplist.js +8 -2
- package/package.json +3 -3
- package/src/mu/ComboBox.tsx +10 -3
- package/src/mu/MaskInput.tsx +9 -1
- package/src/mu/SelectEx.tsx +7 -5
- package/src/mu/Tiplist.tsx +7 -2
package/lib/mu/ComboBox.js
CHANGED
|
@@ -10,21 +10,28 @@ import { SearchField } from './SearchField';
|
|
|
10
10
|
*/
|
|
11
11
|
export function ComboBox(props) {
|
|
12
12
|
// Destruct
|
|
13
|
-
const { search = false, idField = 'id', idValue,
|
|
13
|
+
const { search = false, idField = 'id', idValue, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, defaultValue, label, labelField = 'label', loadData, onLoadData, name, inputAutoComplete = 'off', options = [], readOnly = true, onChange, value, getOptionLabel = (option) => String(Reflect.get(option, labelField)), sx = { minWidth: '150px' }, ...rest } = props;
|
|
14
14
|
// Value input ref
|
|
15
15
|
const inputRef = React.createRef();
|
|
16
16
|
// Options state
|
|
17
17
|
const [localOptions, setOptions] = React.useState(options);
|
|
18
18
|
const isMounted = React.useRef(true);
|
|
19
19
|
// Local default value
|
|
20
|
-
|
|
20
|
+
let localValue = idValue != null
|
|
21
21
|
? localOptions.find((o) => Reflect.get(o, idField) === idValue)
|
|
22
22
|
: defaultValue !== null && defaultValue !== void 0 ? defaultValue : value;
|
|
23
|
+
if (localValue === undefined)
|
|
24
|
+
localValue = null;
|
|
23
25
|
// Current id value
|
|
24
26
|
// One time calculation for input's default value (uncontrolled)
|
|
25
27
|
const localIdValue = localValue && Reflect.get(localValue, idField);
|
|
26
28
|
// State
|
|
27
|
-
|
|
29
|
+
// null for controlled
|
|
30
|
+
const [stateValue, setStateValue] = React.useState(null);
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
if (localValue != null)
|
|
33
|
+
setStateValue(localValue);
|
|
34
|
+
}, [localValue]);
|
|
28
35
|
// Add readOnly
|
|
29
36
|
const addReadOnly = (params) => {
|
|
30
37
|
if (readOnly != null) {
|
package/lib/mu/MaskInput.js
CHANGED
|
@@ -9,11 +9,14 @@ import { useIMask } from 'react-imask';
|
|
|
9
9
|
* @returns Component
|
|
10
10
|
*/
|
|
11
11
|
export function MaskInput(props) {
|
|
12
|
+
var _a;
|
|
12
13
|
// Destruct
|
|
13
|
-
const { mask, InputLabelProps = {}, InputProps = {}, readOnly, search = false, size = search ? MUGlobal.searchFieldSize : MUGlobal.inputFieldSize, variant = search
|
|
14
|
+
const { defaultValue, mask, InputLabelProps = {}, InputProps = {}, readOnly, search = false, size = search ? MUGlobal.searchFieldSize : MUGlobal.inputFieldSize, value, variant = search
|
|
14
15
|
? MUGlobal.searchFieldVariant
|
|
15
16
|
: MUGlobal.inputFieldVariant, ...rest } = props;
|
|
16
|
-
const { ref } = useIMask(mask);
|
|
17
|
+
const { ref, maskRef } = useIMask(mask);
|
|
18
|
+
const localValue = (_a = defaultValue !== null && defaultValue !== void 0 ? defaultValue : value) !== null && _a !== void 0 ? _a : '';
|
|
19
|
+
const maskObj = maskRef.current;
|
|
17
20
|
// Shrink
|
|
18
21
|
InputLabelProps.shrink = search
|
|
19
22
|
? MUGlobal.searchFieldShrink
|
|
@@ -22,6 +25,10 @@ export function MaskInput(props) {
|
|
|
22
25
|
if (readOnly != null)
|
|
23
26
|
InputProps.readOnly = readOnly;
|
|
24
27
|
InputProps.inputRef = ref;
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
if (maskObj != null)
|
|
30
|
+
maskObj.value = String(localValue);
|
|
31
|
+
}, [maskObj, localValue]);
|
|
25
32
|
// Layout
|
|
26
33
|
return (React.createElement(TextField, { InputLabelProps: InputLabelProps, InputProps: InputProps, size: size, variant: variant, ...rest }));
|
|
27
34
|
}
|
package/lib/mu/SelectEx.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { IdLabelDto } from '@etsoo/appscript';
|
|
|
4
4
|
/**
|
|
5
5
|
* Extended select component props
|
|
6
6
|
*/
|
|
7
|
-
export interface SelectExProps<T extends
|
|
7
|
+
export interface SelectExProps<T extends {}> extends Omit<SelectProps, 'labelId' | 'input' | 'native'> {
|
|
8
8
|
/**
|
|
9
9
|
* Id field, default is id
|
|
10
10
|
*/
|
|
@@ -43,4 +43,4 @@ export interface SelectExProps<T extends Record<string, any> = IdLabelDto> exten
|
|
|
43
43
|
* @param props Props
|
|
44
44
|
* @returns Component
|
|
45
45
|
*/
|
|
46
|
-
export declare function SelectEx<T extends
|
|
46
|
+
export declare function SelectEx<T extends {} = IdLabelDto>(props: SelectExProps<T>): JSX.Element;
|
package/lib/mu/SelectEx.js
CHANGED
|
@@ -28,7 +28,11 @@ export function SelectEx(props) {
|
|
|
28
28
|
localValue = valueSource;
|
|
29
29
|
}
|
|
30
30
|
// Value state
|
|
31
|
-
const [valueState, setValueState] = React.useState(
|
|
31
|
+
const [valueState, setValueState] = React.useState(null);
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
if (localValue != null)
|
|
34
|
+
setValueState(localValue);
|
|
35
|
+
}, [localValue]);
|
|
32
36
|
// Label id
|
|
33
37
|
const labelId = `selectex-label-${name}`;
|
|
34
38
|
// Item checked or not
|
package/lib/mu/Tiplist.js
CHANGED
|
@@ -14,7 +14,9 @@ export function Tiplist(props) {
|
|
|
14
14
|
// Value input ref
|
|
15
15
|
const inputRef = React.createRef();
|
|
16
16
|
// Local value
|
|
17
|
-
|
|
17
|
+
let localValue = value !== null && value !== void 0 ? value : defaultValue;
|
|
18
|
+
if (localValue === undefined)
|
|
19
|
+
localValue = null;
|
|
18
20
|
// One time calculation for input's default value (uncontrolled)
|
|
19
21
|
const localIdValue = idValue !== null && idValue !== void 0 ? idValue : (localValue && Reflect.get(localValue, idField));
|
|
20
22
|
// Changable states
|
|
@@ -24,8 +26,12 @@ export function Tiplist(props) {
|
|
|
24
26
|
// Loading unknown
|
|
25
27
|
open: false,
|
|
26
28
|
options: [],
|
|
27
|
-
value:
|
|
29
|
+
value: null
|
|
28
30
|
});
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
if (localValue != null)
|
|
33
|
+
stateUpdate({ value: localValue });
|
|
34
|
+
}, [localValue]);
|
|
29
35
|
// State
|
|
30
36
|
const [state] = React.useState({});
|
|
31
37
|
const isMounted = React.useRef(true);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/react",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.60",
|
|
4
4
|
"description": "TypeScript ReactJs framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"@emotion/react": "^11.5.0",
|
|
51
51
|
"@emotion/style": "^0.8.0",
|
|
52
52
|
"@emotion/styled": "^11.3.0",
|
|
53
|
-
"@etsoo/appscript": "^1.1.
|
|
53
|
+
"@etsoo/appscript": "^1.1.18",
|
|
54
54
|
"@etsoo/notificationbase": "^1.0.88",
|
|
55
|
-
"@etsoo/shared": "^1.0.
|
|
55
|
+
"@etsoo/shared": "^1.0.56",
|
|
56
56
|
"@mui/icons-material": "^5.0.4",
|
|
57
57
|
"@mui/material": "^5.0.4",
|
|
58
58
|
"@reach/router": "^1.3.4",
|
package/src/mu/ComboBox.tsx
CHANGED
|
@@ -43,7 +43,6 @@ export function ComboBox<T extends {} = IdLabelDto>(props: ComboBoxProps<T>) {
|
|
|
43
43
|
search = false,
|
|
44
44
|
idField = 'id',
|
|
45
45
|
idValue,
|
|
46
|
-
inputAutoComplete = 'new-region',
|
|
47
46
|
inputError,
|
|
48
47
|
inputHelperText,
|
|
49
48
|
inputMargin,
|
|
@@ -56,6 +55,7 @@ export function ComboBox<T extends {} = IdLabelDto>(props: ComboBoxProps<T>) {
|
|
|
56
55
|
loadData,
|
|
57
56
|
onLoadData,
|
|
58
57
|
name,
|
|
58
|
+
inputAutoComplete = 'off',
|
|
59
59
|
options = [],
|
|
60
60
|
readOnly = true,
|
|
61
61
|
onChange,
|
|
@@ -73,17 +73,24 @@ export function ComboBox<T extends {} = IdLabelDto>(props: ComboBoxProps<T>) {
|
|
|
73
73
|
const isMounted = React.useRef(true);
|
|
74
74
|
|
|
75
75
|
// Local default value
|
|
76
|
-
|
|
76
|
+
let localValue =
|
|
77
77
|
idValue != null
|
|
78
78
|
? localOptions.find((o) => Reflect.get(o, idField) === idValue)
|
|
79
79
|
: defaultValue ?? value;
|
|
80
80
|
|
|
81
|
+
if (localValue === undefined) localValue = null;
|
|
82
|
+
|
|
81
83
|
// Current id value
|
|
82
84
|
// One time calculation for input's default value (uncontrolled)
|
|
83
85
|
const localIdValue = localValue && Reflect.get(localValue, idField);
|
|
84
86
|
|
|
85
87
|
// State
|
|
86
|
-
|
|
88
|
+
// null for controlled
|
|
89
|
+
const [stateValue, setStateValue] = React.useState<T | null>(null);
|
|
90
|
+
|
|
91
|
+
React.useEffect(() => {
|
|
92
|
+
if (localValue != null) setStateValue(localValue);
|
|
93
|
+
}, [localValue]);
|
|
87
94
|
|
|
88
95
|
// Add readOnly
|
|
89
96
|
const addReadOnly = (params: AutocompleteRenderInputParams) => {
|
package/src/mu/MaskInput.tsx
CHANGED
|
@@ -32,19 +32,23 @@ export type MaskInputProps = TextFieldProps & {
|
|
|
32
32
|
export function MaskInput(props: MaskInputProps) {
|
|
33
33
|
// Destruct
|
|
34
34
|
const {
|
|
35
|
+
defaultValue,
|
|
35
36
|
mask,
|
|
36
37
|
InputLabelProps = {},
|
|
37
38
|
InputProps = {},
|
|
38
39
|
readOnly,
|
|
39
40
|
search = false,
|
|
40
41
|
size = search ? MUGlobal.searchFieldSize : MUGlobal.inputFieldSize,
|
|
42
|
+
value,
|
|
41
43
|
variant = search
|
|
42
44
|
? MUGlobal.searchFieldVariant
|
|
43
45
|
: MUGlobal.inputFieldVariant,
|
|
44
46
|
...rest
|
|
45
47
|
} = props;
|
|
46
48
|
|
|
47
|
-
const { ref } = useIMask(mask);
|
|
49
|
+
const { ref, maskRef } = useIMask(mask);
|
|
50
|
+
const localValue = defaultValue ?? value ?? '';
|
|
51
|
+
const maskObj = maskRef.current;
|
|
48
52
|
|
|
49
53
|
// Shrink
|
|
50
54
|
InputLabelProps.shrink = search
|
|
@@ -55,6 +59,10 @@ export function MaskInput(props: MaskInputProps) {
|
|
|
55
59
|
if (readOnly != null) InputProps.readOnly = readOnly;
|
|
56
60
|
InputProps.inputRef = ref;
|
|
57
61
|
|
|
62
|
+
React.useEffect(() => {
|
|
63
|
+
if (maskObj != null) maskObj.value = String(localValue);
|
|
64
|
+
}, [maskObj, localValue]);
|
|
65
|
+
|
|
58
66
|
// Layout
|
|
59
67
|
return (
|
|
60
68
|
<TextField
|
package/src/mu/SelectEx.tsx
CHANGED
|
@@ -18,7 +18,7 @@ import { ListItemRightIcon } from './ListItemRightIcon';
|
|
|
18
18
|
/**
|
|
19
19
|
* Extended select component props
|
|
20
20
|
*/
|
|
21
|
-
export interface SelectExProps<T extends
|
|
21
|
+
export interface SelectExProps<T extends {}>
|
|
22
22
|
extends Omit<SelectProps, 'labelId' | 'input' | 'native'> {
|
|
23
23
|
/**
|
|
24
24
|
* Id field, default is id
|
|
@@ -66,9 +66,7 @@ export interface SelectExProps<T extends Record<string, any> = IdLabelDto>
|
|
|
66
66
|
* @param props Props
|
|
67
67
|
* @returns Component
|
|
68
68
|
*/
|
|
69
|
-
export function SelectEx<T extends
|
|
70
|
-
props: SelectExProps<T>
|
|
71
|
-
) {
|
|
69
|
+
export function SelectEx<T extends {} = IdLabelDto>(props: SelectExProps<T>) {
|
|
72
70
|
// Destruct
|
|
73
71
|
const {
|
|
74
72
|
defaultValue,
|
|
@@ -103,7 +101,11 @@ export function SelectEx<T extends Record<string, any> = IdLabelDto>(
|
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
// Value state
|
|
106
|
-
const [valueState, setValueState] = React.useState(
|
|
104
|
+
const [valueState, setValueState] = React.useState<unknown | null>(null);
|
|
105
|
+
|
|
106
|
+
React.useEffect(() => {
|
|
107
|
+
if (localValue != null) setValueState(localValue);
|
|
108
|
+
}, [localValue]);
|
|
107
109
|
|
|
108
110
|
// Label id
|
|
109
111
|
const labelId = `selectex-label-${name}`;
|
package/src/mu/Tiplist.tsx
CHANGED
|
@@ -62,7 +62,8 @@ export function Tiplist<T extends {} = IdLabelDto>(props: TiplistProps<T>) {
|
|
|
62
62
|
const inputRef = React.createRef<HTMLInputElement>();
|
|
63
63
|
|
|
64
64
|
// Local value
|
|
65
|
-
|
|
65
|
+
let localValue = value ?? defaultValue;
|
|
66
|
+
if (localValue === undefined) localValue = null;
|
|
66
67
|
|
|
67
68
|
// One time calculation for input's default value (uncontrolled)
|
|
68
69
|
const localIdValue =
|
|
@@ -77,10 +78,14 @@ export function Tiplist<T extends {} = IdLabelDto>(props: TiplistProps<T>) {
|
|
|
77
78
|
// Loading unknown
|
|
78
79
|
open: false,
|
|
79
80
|
options: [],
|
|
80
|
-
value:
|
|
81
|
+
value: null
|
|
81
82
|
}
|
|
82
83
|
);
|
|
83
84
|
|
|
85
|
+
React.useEffect(() => {
|
|
86
|
+
if (localValue != null) stateUpdate({ value: localValue });
|
|
87
|
+
}, [localValue]);
|
|
88
|
+
|
|
84
89
|
// State
|
|
85
90
|
const [state] = React.useState<{
|
|
86
91
|
loadDataSeed?: number;
|