@etsoo/materialui 1.6.2 → 1.6.3
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/cjs/IntInputField.js +23 -5
- package/lib/mjs/IntInputField.js +23 -5
- package/package.json +4 -4
- package/src/IntInputField.tsx +27 -4
package/lib/cjs/IntInputField.js
CHANGED
|
@@ -13,14 +13,25 @@ const InputField_1 = require("./InputField");
|
|
|
13
13
|
const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
14
14
|
const InputAdornment_1 = __importDefault(require("@mui/material/InputAdornment"));
|
|
15
15
|
const IconButton_1 = __importDefault(require("@mui/material/IconButton"));
|
|
16
|
+
const react_2 = require("@etsoo/react");
|
|
16
17
|
/**
|
|
17
18
|
* Integer input field (controlled)
|
|
18
19
|
*/
|
|
19
20
|
function IntInputField(props) {
|
|
20
21
|
// Destruct
|
|
21
|
-
const { min = 0, step = 1, max = 9999999, inputStyle = { textAlign: "right" }, boxProps, buttons, endSymbol, symbol, value, changeDelay = [600], onChangeDelay, onChange, onFocus = (event) => event.currentTarget.select(), onValueChange, required, ...rest } = props;
|
|
22
|
+
const { min = 0, step = 1, max = 9999999, inputRef, inputStyle = { textAlign: "right" }, boxProps, buttons, endSymbol, symbol, value, changeDelay = [600], onChangeDelay, onChange, onFocus = (event) => event.currentTarget.select(), onValueChange, required, ...rest } = props;
|
|
23
|
+
const isControlled = value !== undefined;
|
|
22
24
|
// State
|
|
23
|
-
const [localValue,
|
|
25
|
+
const [localValue, setInnerLocalValue] = react_1.default.useState();
|
|
26
|
+
const localRef = react_1.default.useRef(null);
|
|
27
|
+
function setLocalValue(value) {
|
|
28
|
+
if (isControlled) {
|
|
29
|
+
setInnerLocalValue(value);
|
|
30
|
+
}
|
|
31
|
+
else if (localRef.current) {
|
|
32
|
+
localRef.current.value = value?.toString() ?? "";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
24
35
|
const setValue = (value, source, init = false) => {
|
|
25
36
|
if (onValueChange) {
|
|
26
37
|
const newValue = onValueChange(value, source, init);
|
|
@@ -40,10 +51,17 @@ function IntInputField(props) {
|
|
|
40
51
|
}
|
|
41
52
|
};
|
|
42
53
|
react_1.default.useEffect(() => {
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
if (isControlled)
|
|
55
|
+
setValue(value, undefined, true);
|
|
56
|
+
}, [value, isControlled]);
|
|
45
57
|
// Layout
|
|
46
|
-
const layout = ((0, jsx_runtime_1.jsx)(InputField_1.InputField, { type: "number",
|
|
58
|
+
const layout = ((0, jsx_runtime_1.jsx)(InputField_1.InputField, { type: "number", inputRef: (0, react_2.useCombinedRefs)(inputRef, localRef), value: isControlled
|
|
59
|
+
? localValue == null
|
|
60
|
+
? required
|
|
61
|
+
? min
|
|
62
|
+
: ""
|
|
63
|
+
: localValue
|
|
64
|
+
: undefined, slotProps: {
|
|
47
65
|
input: {
|
|
48
66
|
startAdornment: symbol ? ((0, jsx_runtime_1.jsx)(react_1.default.Fragment, { children: (0, jsx_runtime_1.jsx)(InputAdornment_1.default, { position: "start", children: symbol }) })) : undefined,
|
|
49
67
|
endAdornment: endSymbol ? ((0, jsx_runtime_1.jsx)(InputAdornment_1.default, { position: "end", children: endSymbol })) : undefined
|
package/lib/mjs/IntInputField.js
CHANGED
|
@@ -7,14 +7,25 @@ import { InputField } from "./InputField";
|
|
|
7
7
|
import Box from "@mui/material/Box";
|
|
8
8
|
import InputAdornment from "@mui/material/InputAdornment";
|
|
9
9
|
import IconButton from "@mui/material/IconButton";
|
|
10
|
+
import { useCombinedRefs } from "@etsoo/react";
|
|
10
11
|
/**
|
|
11
12
|
* Integer input field (controlled)
|
|
12
13
|
*/
|
|
13
14
|
export function IntInputField(props) {
|
|
14
15
|
// Destruct
|
|
15
|
-
const { min = 0, step = 1, max = 9999999, inputStyle = { textAlign: "right" }, boxProps, buttons, endSymbol, symbol, value, changeDelay = [600], onChangeDelay, onChange, onFocus = (event) => event.currentTarget.select(), onValueChange, required, ...rest } = props;
|
|
16
|
+
const { min = 0, step = 1, max = 9999999, inputRef, inputStyle = { textAlign: "right" }, boxProps, buttons, endSymbol, symbol, value, changeDelay = [600], onChangeDelay, onChange, onFocus = (event) => event.currentTarget.select(), onValueChange, required, ...rest } = props;
|
|
17
|
+
const isControlled = value !== undefined;
|
|
16
18
|
// State
|
|
17
|
-
const [localValue,
|
|
19
|
+
const [localValue, setInnerLocalValue] = React.useState();
|
|
20
|
+
const localRef = React.useRef(null);
|
|
21
|
+
function setLocalValue(value) {
|
|
22
|
+
if (isControlled) {
|
|
23
|
+
setInnerLocalValue(value);
|
|
24
|
+
}
|
|
25
|
+
else if (localRef.current) {
|
|
26
|
+
localRef.current.value = value?.toString() ?? "";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
18
29
|
const setValue = (value, source, init = false) => {
|
|
19
30
|
if (onValueChange) {
|
|
20
31
|
const newValue = onValueChange(value, source, init);
|
|
@@ -34,10 +45,17 @@ export function IntInputField(props) {
|
|
|
34
45
|
}
|
|
35
46
|
};
|
|
36
47
|
React.useEffect(() => {
|
|
37
|
-
|
|
38
|
-
|
|
48
|
+
if (isControlled)
|
|
49
|
+
setValue(value, undefined, true);
|
|
50
|
+
}, [value, isControlled]);
|
|
39
51
|
// Layout
|
|
40
|
-
const layout = (_jsx(InputField, { type: "number",
|
|
52
|
+
const layout = (_jsx(InputField, { type: "number", inputRef: useCombinedRefs(inputRef, localRef), value: isControlled
|
|
53
|
+
? localValue == null
|
|
54
|
+
? required
|
|
55
|
+
? min
|
|
56
|
+
: ""
|
|
57
|
+
: localValue
|
|
58
|
+
: undefined, slotProps: {
|
|
41
59
|
input: {
|
|
42
60
|
startAdornment: symbol ? (_jsx(React.Fragment, { children: _jsx(InputAdornment, { position: "start", children: symbol }) })) : undefined,
|
|
43
61
|
endAdornment: endSymbol ? (_jsx(InputAdornment, { position: "end", children: endSymbol })) : undefined
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/materialui",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
4
4
|
"description": "TypeScript Material-UI Implementation",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"@dnd-kit/sortable": "^10.0.0",
|
|
41
41
|
"@emotion/react": "^11.14.0",
|
|
42
42
|
"@emotion/styled": "^11.14.1",
|
|
43
|
-
"@etsoo/appscript": "^1.6.
|
|
43
|
+
"@etsoo/appscript": "^1.6.53",
|
|
44
44
|
"@etsoo/notificationbase": "^1.1.66",
|
|
45
|
-
"@etsoo/react": "^1.8.
|
|
45
|
+
"@etsoo/react": "^1.8.70",
|
|
46
46
|
"@etsoo/shared": "^1.2.80",
|
|
47
47
|
"@mui/icons-material": "^7.3.7",
|
|
48
48
|
"@mui/material": "^7.3.7",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@testing-library/react": "^16.3.1",
|
|
76
76
|
"@types/pica": "^9.0.5",
|
|
77
77
|
"@types/pulltorefreshjs": "^0.1.7",
|
|
78
|
-
"@types/react": "^19.2.
|
|
78
|
+
"@types/react": "^19.2.8",
|
|
79
79
|
"@types/react-avatar-editor": "^13.0.4",
|
|
80
80
|
"@types/react-dom": "^19.2.3",
|
|
81
81
|
"@types/react-input-mask": "^3.0.6",
|
package/src/IntInputField.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import { InputField, InputFieldProps } from "./InputField";
|
|
|
6
6
|
import Box, { BoxProps } from "@mui/material/Box";
|
|
7
7
|
import InputAdornment from "@mui/material/InputAdornment";
|
|
8
8
|
import IconButton from "@mui/material/IconButton";
|
|
9
|
+
import { useCombinedRefs } from "@etsoo/react";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Integer input field props
|
|
@@ -81,6 +82,7 @@ export function IntInputField(props: IntInputFieldProps) {
|
|
|
81
82
|
min = 0,
|
|
82
83
|
step = 1,
|
|
83
84
|
max = 9999999,
|
|
85
|
+
inputRef,
|
|
84
86
|
inputStyle = { textAlign: "right" },
|
|
85
87
|
boxProps,
|
|
86
88
|
buttons,
|
|
@@ -96,8 +98,20 @@ export function IntInputField(props: IntInputFieldProps) {
|
|
|
96
98
|
...rest
|
|
97
99
|
} = props;
|
|
98
100
|
|
|
101
|
+
const isControlled = value !== undefined;
|
|
102
|
+
|
|
99
103
|
// State
|
|
100
|
-
const [localValue,
|
|
104
|
+
const [localValue, setInnerLocalValue] = React.useState<number | string>();
|
|
105
|
+
|
|
106
|
+
const localRef = React.useRef<HTMLInputElement>(null);
|
|
107
|
+
|
|
108
|
+
function setLocalValue(value: number | string | undefined) {
|
|
109
|
+
if (isControlled) {
|
|
110
|
+
setInnerLocalValue(value);
|
|
111
|
+
} else if (localRef.current) {
|
|
112
|
+
localRef.current.value = value?.toString() ?? "";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
101
115
|
|
|
102
116
|
const setValue = (
|
|
103
117
|
value: number | undefined,
|
|
@@ -121,14 +135,23 @@ export function IntInputField(props: IntInputFieldProps) {
|
|
|
121
135
|
};
|
|
122
136
|
|
|
123
137
|
React.useEffect(() => {
|
|
124
|
-
setValue(value, undefined, true);
|
|
125
|
-
}, [value]);
|
|
138
|
+
if (isControlled) setValue(value, undefined, true);
|
|
139
|
+
}, [value, isControlled]);
|
|
126
140
|
|
|
127
141
|
// Layout
|
|
128
142
|
const layout = (
|
|
129
143
|
<InputField
|
|
130
144
|
type="number"
|
|
131
|
-
|
|
145
|
+
inputRef={useCombinedRefs(inputRef, localRef)}
|
|
146
|
+
value={
|
|
147
|
+
isControlled
|
|
148
|
+
? localValue == null
|
|
149
|
+
? required
|
|
150
|
+
? min
|
|
151
|
+
: ""
|
|
152
|
+
: localValue
|
|
153
|
+
: undefined
|
|
154
|
+
}
|
|
132
155
|
slotProps={{
|
|
133
156
|
input: {
|
|
134
157
|
startAdornment: symbol ? (
|