@sheinx/hooks 3.9.14-beta.8 → 3.9.14
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/cjs/components/use-input/use-input-number.d.ts +1 -0
- package/cjs/components/use-input/use-input-number.d.ts.map +1 -1
- package/cjs/components/use-input/use-input-number.js +10 -5
- package/cjs/components/use-input/use-input-number.type.d.ts +1 -0
- package/cjs/components/use-input/use-input-number.type.d.ts.map +1 -1
- package/esm/components/use-input/use-input-number.d.ts +1 -0
- package/esm/components/use-input/use-input-number.d.ts.map +1 -1
- package/esm/components/use-input/use-input-number.js +10 -5
- package/esm/components/use-input/use-input-number.type.d.ts +1 -0
- package/esm/components/use-input/use-input-number.type.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ import { InputNumberProps } from './use-input-number.type';
|
|
|
3
3
|
declare const useNumberFormat: (props: InputNumberProps) => {
|
|
4
4
|
onPlus: () => void;
|
|
5
5
|
onMinus: () => void;
|
|
6
|
+
onClear: () => void;
|
|
6
7
|
onChange: (v: string | undefined) => void;
|
|
7
8
|
onBlur: (e: React.FocusEvent<HTMLInputElement, Element>) => void;
|
|
8
9
|
onFocus: (e: React.FocusEvent<HTMLInputElement, Element>) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-input-number.d.ts","sourceRoot":"","sources":["use-input-number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,QAAA,MAAM,eAAe,UAAW,gBAAgB
|
|
1
|
+
{"version":3,"file":"use-input-number.d.ts","sourceRoot":"","sources":["use-input-number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,QAAA,MAAM,eAAe,UAAW,gBAAgB;;;;;;;;;CAiM/C,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -34,6 +34,7 @@ var useNumberFormat = function useNumberFormat(props) {
|
|
|
34
34
|
min = props.min,
|
|
35
35
|
max = props.max,
|
|
36
36
|
allowNull = props.allowNull,
|
|
37
|
+
clearToUndefined = props.clearToUndefined,
|
|
37
38
|
_props$step = props.step,
|
|
38
39
|
step = _props$step === void 0 ? 1 : _props$step,
|
|
39
40
|
cancelBlurChange = props.cancelBlurChange,
|
|
@@ -54,10 +55,9 @@ var useNumberFormat = function useNumberFormat(props) {
|
|
|
54
55
|
setInternalInputValue = _React$useState2[1];
|
|
55
56
|
var focusedRef = _react.default.useRef(false);
|
|
56
57
|
(0, _react.useEffect)(function () {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
setInternalInputValue(getStringValue(props.value));
|
|
58
|
+
var stringValue = getStringValue(props.value);
|
|
59
|
+
if (stringValue !== inernalInputValue && (!focusedRef.current || props.value == null)) {
|
|
60
|
+
setInternalInputValue(stringValue);
|
|
61
61
|
}
|
|
62
62
|
}, [props.value]);
|
|
63
63
|
var getNumberValue = function getNumberValue(value) {
|
|
@@ -183,6 +183,10 @@ var useNumberFormat = function useNumberFormat(props) {
|
|
|
183
183
|
var num = changeValue(-step);
|
|
184
184
|
if (num !== undefined) setInternalInputValue(getStringValue(num));
|
|
185
185
|
});
|
|
186
|
+
var handleClear = (0, _usePersistFn.default)(function () {
|
|
187
|
+
setInternalInputValue('');
|
|
188
|
+
onChange === null || onChange === void 0 || onChange(clearToUndefined ? undefined : allowNull ? null : '');
|
|
189
|
+
});
|
|
186
190
|
return _objectSpread(_objectSpread({}, (0, _useInputFormat.default)({
|
|
187
191
|
value: inernalInputValue,
|
|
188
192
|
type: 'number',
|
|
@@ -196,7 +200,8 @@ var useNumberFormat = function useNumberFormat(props) {
|
|
|
196
200
|
cancelBlurChange: true
|
|
197
201
|
})), {}, {
|
|
198
202
|
onPlus: handlePlus,
|
|
199
|
-
onMinus: handleMinus
|
|
203
|
+
onMinus: handleMinus,
|
|
204
|
+
onClear: handleClear
|
|
200
205
|
});
|
|
201
206
|
};
|
|
202
207
|
var _default = exports.default = useNumberFormat;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-input-number.type.d.ts","sourceRoot":"","sources":["use-input-number.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;AAC7D,MAAM,WAAW,gBACf,SAAQ,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IAClF,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,SAAS,CAAC;IACnD;;;OAGG;IACH,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
|
|
1
|
+
{"version":3,"file":"use-input-number.type.d.ts","sourceRoot":"","sources":["use-input-number.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;AAC7D,MAAM,WAAW,gBACf,SAAQ,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IAClF,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,SAAS,CAAC;IACnD;;;OAGG;IACH,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
|
|
@@ -3,6 +3,7 @@ import { InputNumberProps } from './use-input-number.type';
|
|
|
3
3
|
declare const useNumberFormat: (props: InputNumberProps) => {
|
|
4
4
|
onPlus: () => void;
|
|
5
5
|
onMinus: () => void;
|
|
6
|
+
onClear: () => void;
|
|
6
7
|
onChange: (v: string | undefined) => void;
|
|
7
8
|
onBlur: (e: React.FocusEvent<HTMLInputElement, Element>) => void;
|
|
8
9
|
onFocus: (e: React.FocusEvent<HTMLInputElement, Element>) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-input-number.d.ts","sourceRoot":"","sources":["use-input-number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,QAAA,MAAM,eAAe,UAAW,gBAAgB
|
|
1
|
+
{"version":3,"file":"use-input-number.d.ts","sourceRoot":"","sources":["use-input-number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,QAAA,MAAM,eAAe,UAAW,gBAAgB;;;;;;;;;CAiM/C,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -25,6 +25,7 @@ var useNumberFormat = function useNumberFormat(props) {
|
|
|
25
25
|
min = props.min,
|
|
26
26
|
max = props.max,
|
|
27
27
|
allowNull = props.allowNull,
|
|
28
|
+
clearToUndefined = props.clearToUndefined,
|
|
28
29
|
_props$step = props.step,
|
|
29
30
|
step = _props$step === void 0 ? 1 : _props$step,
|
|
30
31
|
cancelBlurChange = props.cancelBlurChange,
|
|
@@ -45,10 +46,9 @@ var useNumberFormat = function useNumberFormat(props) {
|
|
|
45
46
|
setInternalInputValue = _React$useState2[1];
|
|
46
47
|
var focusedRef = React.useRef(false);
|
|
47
48
|
useEffect(function () {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
setInternalInputValue(getStringValue(props.value));
|
|
49
|
+
var stringValue = getStringValue(props.value);
|
|
50
|
+
if (stringValue !== inernalInputValue && (!focusedRef.current || props.value == null)) {
|
|
51
|
+
setInternalInputValue(stringValue);
|
|
52
52
|
}
|
|
53
53
|
}, [props.value]);
|
|
54
54
|
var getNumberValue = function getNumberValue(value) {
|
|
@@ -174,6 +174,10 @@ var useNumberFormat = function useNumberFormat(props) {
|
|
|
174
174
|
var num = changeValue(-step);
|
|
175
175
|
if (num !== undefined) setInternalInputValue(getStringValue(num));
|
|
176
176
|
});
|
|
177
|
+
var handleClear = usePersistFn(function () {
|
|
178
|
+
setInternalInputValue('');
|
|
179
|
+
onChange === null || onChange === void 0 || onChange(clearToUndefined ? undefined : allowNull ? null : '');
|
|
180
|
+
});
|
|
177
181
|
return _objectSpread(_objectSpread({}, useInputFormat({
|
|
178
182
|
value: inernalInputValue,
|
|
179
183
|
type: 'number',
|
|
@@ -187,7 +191,8 @@ var useNumberFormat = function useNumberFormat(props) {
|
|
|
187
191
|
cancelBlurChange: true
|
|
188
192
|
})), {}, {
|
|
189
193
|
onPlus: handlePlus,
|
|
190
|
-
onMinus: handleMinus
|
|
194
|
+
onMinus: handleMinus,
|
|
195
|
+
onClear: handleClear
|
|
191
196
|
});
|
|
192
197
|
};
|
|
193
198
|
export default useNumberFormat;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-input-number.type.d.ts","sourceRoot":"","sources":["use-input-number.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;AAC7D,MAAM,WAAW,gBACf,SAAQ,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IAClF,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,SAAS,CAAC;IACnD;;;OAGG;IACH,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
|
|
1
|
+
{"version":3,"file":"use-input-number.type.d.ts","sourceRoot":"","sources":["use-input-number.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;AAC7D,MAAM,WAAW,gBACf,SAAQ,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IAClF,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,SAAS,CAAC;IACnD;;;OAGG;IACH,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
|