@autoguru/overdrive 4.24.0 → 4.24.1
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/dist/components/EditableText/EditableText.d.ts.map +1 -1
- package/dist/components/EditableText/EditableText.js +4 -2
- package/dist/components/MinimalModal/MinimalModal.d.ts.map +1 -1
- package/dist/components/Modal/Modal.d.ts.map +1 -1
- package/dist/components/NumberInput/NumberInput.d.ts +5 -1
- package/dist/components/NumberInput/NumberInput.d.ts.map +1 -1
- package/dist/components/NumberInput/NumberInput.js +27 -31
- package/dist/components/NumberInput/stories.js +18 -1
- package/dist/components/NumberInput/useNumberInputBehaviours.d.ts +20 -0
- package/dist/components/NumberInput/useNumberInputBehaviours.d.ts.map +1 -0
- package/dist/components/NumberInput/useNumberInputBehaviours.js +64 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditableText.d.ts","sourceRoot":"","sources":["../../../lib/components/EditableText/EditableText.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,
|
|
1
|
+
{"version":3,"file":"EditableText.d.ts","sourceRoot":"","sources":["../../../lib/components/EditableText/EditableText.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACN,cAAc,EAEd,mBAAmB,EAInB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAiB,MAAM,SAAS,CAAC;AAK9C,KAAK,QAAQ,GAAG,IAAI,CACnB,cAAc,CAAC,OAAO,GAAG,CAAC,EAC1B,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,CAC9C,CAAC;AACF,KAAK,SAAS,GAAG,IAAI,CACpB,cAAc,CAAC,OAAO,IAAI,CAAC,EAC3B,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,CAChD,CAAC;AACF,KAAK,UAAU,GAAG,IAAI,CACrB,mBAAmB,CAAC,gBAAgB,CAAC,EACnC,OAAO,GACP,IAAI,GACJ,WAAW,GACX,OAAO,GACP,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,WAAW,GACX,MAAM,SAAS,GACf,MAAM,QAAQ,CAChB,CAAC;AAEF,MAAM,WAAW,KAAM,SAAQ,SAAS,EAAE,UAAU,EAAE,QAAQ;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;CACzC;AAED,KAAK,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;AAClC,eAAO,MAAM,YAAY,iFAuFxB,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
|
-
const _excluded = ["is", "colour", "size", "display", "value", "onFocus", "onBlur", "onKeyDown", "onModeChange"];
|
|
5
|
+
const _excluded = ["is", "colour", "size", "display", "value", "onFocus", "onBlur", "onKeyDown", "onModeChange", "tabIndex"];
|
|
6
6
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
7
7
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
8
8
|
import clsx from 'clsx';
|
|
@@ -24,7 +24,8 @@ export const EditableText = forwardRef((_ref, ref) => {
|
|
|
24
24
|
onFocus,
|
|
25
25
|
onBlur,
|
|
26
26
|
onKeyDown,
|
|
27
|
-
onModeChange
|
|
27
|
+
onModeChange,
|
|
28
|
+
tabIndex = 0
|
|
28
29
|
} = _ref,
|
|
29
30
|
inputProps = _objectWithoutProperties(_ref, _excluded);
|
|
30
31
|
const textRef = useRef(null);
|
|
@@ -49,6 +50,7 @@ export const EditableText = forwardRef((_ref, ref) => {
|
|
|
49
50
|
return _jsxs(Box, {
|
|
50
51
|
ref: ref,
|
|
51
52
|
display: display,
|
|
53
|
+
tabIndex: tabIndex,
|
|
52
54
|
position: "relative",
|
|
53
55
|
className: styles.root,
|
|
54
56
|
onClick: () => onRequestModeChange('INPUT'),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MinimalModal.d.ts","sourceRoot":"","sources":["../../../lib/components/MinimalModal/MinimalModal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"MinimalModal.d.ts","sourceRoot":"","sources":["../../../lib/components/MinimalModal/MinimalModal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,cAAc,EACd,iBAAiB,EAEjB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,SAAS,EAA2B,MAAM,OAAO,CAAC;AAG3D,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAIjC,MAAM,WAAW,KAChB,SAAQ,cAAc,CAAC,OAAO,KAAK,CAAC,EACnC,IAAI,CAAC,cAAc,CAAC,OAAO,GAAG,CAAC,EAAE,YAAY,CAAC;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACrB;AAED,eAAO,MAAM,YAAY,EAAE,iBAAiB,CAAC,KAAK,CAsEjD,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../../../lib/components/Modal/Modal.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,cAAc,EACd,aAAa,EACb,iBAAiB,EAEjB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,SAAS,EAAyB,MAAM,OAAO,CAAC;AAKzD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAInC,MAAM,WAAW,KAAM,SAAQ,cAAc,CAAC,OAAO,MAAM,CAAC;IAC3D,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,EAAE,SAAS,CAAC;IAErB,cAAc,CAAC,CAAC,CAAC,EAAE,UAAU,GAAG,eAAe,GAAG,MAAM,GAAG,IAAI,CAAC;CAChE;AAqDD,eAAO,MAAM,KAAK,EAAE,iBAAiB,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../../../lib/components/Modal/Modal.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,cAAc,EACd,aAAa,EACb,iBAAiB,EAEjB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,SAAS,EAAyB,MAAM,OAAO,CAAC;AAKzD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAInC,MAAM,WAAW,KAAM,SAAQ,cAAc,CAAC,OAAO,MAAM,CAAC;IAC3D,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,EAAE,SAAS,CAAC;IAErB,cAAc,CAAC,CAAC,CAAC,EAAE,UAAU,GAAG,eAAe,GAAG,MAAM,GAAG,IAAI,CAAC;CAChE;AAqDD,eAAO,MAAM,KAAK,EAAE,iBAAiB,CAAC,KAAK,CAmF1C,CAAC;AAEF,eAAO,MAAM,SAAS,wIAmBpB,CAAC;AAEH,eAAe,KAAK,CAAC"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
2
|
+
import { FocusEventHandler, FormEventHandler } from 'react';
|
|
3
|
+
interface Props extends Partial<Pick<HTMLInputElement, 'min' | 'max' | 'step'>>, Pick<HTMLInputElement, 'value'> {
|
|
3
4
|
preventMouseWheel?: boolean;
|
|
5
|
+
onChange?: FormEventHandler<HTMLInputElement>;
|
|
6
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
7
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
4
8
|
}
|
|
5
9
|
export declare const NumberInput: React.ForwardRefExoticComponent<Props & import("../private/InputBase/withEnhancedInput").EnhanceInputPrimitiveProps & import("../private/InputBase/withEnhancedInput").EventHandlers<HTMLInputElement> & import("../private/InputBase/withEnhancedInput").ValidationProps & React.RefAttributes<HTMLInputElement>>;
|
|
6
10
|
export default NumberInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberInput.d.ts","sourceRoot":"","sources":["../../../lib/components/NumberInput/NumberInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"NumberInput.d.ts","sourceRoot":"","sources":["../../../lib/components/NumberInput/NumberInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAY5D,UAAU,KACT,SAAQ,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC,CAAC,EAC9D,IAAI,CAAC,gBAAgB,EAAE,OAAO,CAAC;IAChC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IAC9C,OAAO,CAAC,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IAC9C,MAAM,CAAC,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;CAC7C;AAED,eAAO,MAAM,WAAW,oTA4CvB,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
5
|
const _excluded = ["ref"],
|
|
6
|
-
_excluded2 = ["field", "eventHandlers", "validation", "isLoading", "suffixed", "prefixed", "preventMouseWheel", "size"];
|
|
6
|
+
_excluded2 = ["field", "eventHandlers", "validation", "isLoading", "suffixed", "prefixed", "preventMouseWheel", "size", "onChange", "onFocus", "onBlur"];
|
|
7
7
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
8
8
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
9
9
|
import * as React from 'react';
|
|
10
|
-
import { useCallback, useEffect, useRef } from 'react';
|
|
11
10
|
import { Box } from "../Box/index.js";
|
|
12
11
|
import { withEnhancedInput } from "../private/InputBase/index.js";
|
|
12
|
+
import { useNumberInputBehaviours } from "./useNumberInputBehaviours.js";
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
const isEdge = typeof navigator !== 'undefined' && /edge/i.test(navigator.userAgent);
|
|
15
15
|
const type = isEdge ? 'text' : 'number';
|
|
@@ -24,42 +24,38 @@ export const NumberInput = withEnhancedInput(_ref => {
|
|
|
24
24
|
suffixed,
|
|
25
25
|
prefixed,
|
|
26
26
|
preventMouseWheel = false,
|
|
27
|
-
size
|
|
27
|
+
size,
|
|
28
|
+
onChange: incomingOnChange,
|
|
29
|
+
onFocus: incomingOnFocus,
|
|
30
|
+
onBlur: incomingOnBlur
|
|
28
31
|
} = _ref,
|
|
29
32
|
incomingFieldProps = _objectWithoutProperties(_ref.field, _excluded),
|
|
30
33
|
rest = _objectWithoutProperties(_ref, _excluded2);
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
passive: false
|
|
46
|
-
});
|
|
47
|
-
wheelListener = inputRef.current.addEventListener('wheel', preventWheel, {
|
|
48
|
-
passive: false
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return () => {
|
|
52
|
-
if (mouseWheelListener) inputRef.current.removeEventListener('mousewheel', mouseWheelListener);
|
|
53
|
-
if (onWheelListener) inputRef.current.removeEventListener('onwheel', onWheelListener);
|
|
54
|
-
if (wheelListener) inputRef.current.removeEventListener('wheel', wheelListener);
|
|
55
|
-
};
|
|
56
|
-
}, [preventMouseWheel, inputRef.current]);
|
|
34
|
+
const {
|
|
35
|
+
value,
|
|
36
|
+
inputRef,
|
|
37
|
+
onFocus,
|
|
38
|
+
onBlur,
|
|
39
|
+
onChange
|
|
40
|
+
} = useNumberInputBehaviours({
|
|
41
|
+
ref,
|
|
42
|
+
preventMouseWheel,
|
|
43
|
+
onFocus: eventHandlers.onFocus,
|
|
44
|
+
onBlur: eventHandlers.onBlur,
|
|
45
|
+
onChange: eventHandlers.onChange,
|
|
46
|
+
value: incomingFieldProps.value
|
|
47
|
+
});
|
|
57
48
|
return _jsx(Box, _objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
58
49
|
is: "input",
|
|
59
50
|
ref: inputRef
|
|
60
|
-
}, eventHandlers),
|
|
51
|
+
}, eventHandlers), {}, {
|
|
52
|
+
onFocus: onFocus,
|
|
53
|
+
onBlur: onBlur,
|
|
54
|
+
onChange: onChange
|
|
55
|
+
}, incomingFieldProps), rest), {}, {
|
|
61
56
|
autoComplete: "off",
|
|
62
|
-
type: type
|
|
57
|
+
type: type,
|
|
58
|
+
value: value
|
|
63
59
|
}));
|
|
64
60
|
}, {
|
|
65
61
|
primitiveType: type
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
|
+
const _excluded = ["value", "onChange"];
|
|
4
6
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
7
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
8
|
import { AccountEditIcon, AlertCircleIcon, CalendarIcon, CarIcon, CarMultipleIcon, CheckIcon, CurrencyUsdIcon, PlusIcon, StarIcon } from '@autoguru/icons';
|
|
@@ -63,7 +65,21 @@ const argTypes = {
|
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
};
|
|
66
|
-
const Template =
|
|
68
|
+
const Template = _ref => {
|
|
69
|
+
let {
|
|
70
|
+
value: initialValue,
|
|
71
|
+
onChange: incomingOnChange
|
|
72
|
+
} = _ref,
|
|
73
|
+
args = _objectWithoutProperties(_ref, _excluded);
|
|
74
|
+
const [value, setValue] = React.useState(initialValue);
|
|
75
|
+
return _jsx(NumberInput, _objectSpread(_objectSpread({}, args), {}, {
|
|
76
|
+
value: value,
|
|
77
|
+
onChange: e => {
|
|
78
|
+
setValue(e.currentTarget.value);
|
|
79
|
+
incomingOnChange(e);
|
|
80
|
+
}
|
|
81
|
+
}));
|
|
82
|
+
};
|
|
67
83
|
const sharedProps = {
|
|
68
84
|
disabled: false,
|
|
69
85
|
name: 'number',
|
|
@@ -75,6 +91,7 @@ const sharedProps = {
|
|
|
75
91
|
reserveHintSpace: false,
|
|
76
92
|
hintText: '',
|
|
77
93
|
notch: true,
|
|
94
|
+
preventMouseWheel: true,
|
|
78
95
|
prefixIcon: null,
|
|
79
96
|
onChange: action('onChange'),
|
|
80
97
|
onFocus: action('onFocus'),
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FocusEventHandler, FormEventHandler, RefObject } from 'react';
|
|
2
|
+
import { EnhanceInputPrimitiveProps } from '../private/InputBase/withEnhancedInput';
|
|
3
|
+
interface Props {
|
|
4
|
+
value: EnhanceInputPrimitiveProps['value'];
|
|
5
|
+
ref: RefObject<HTMLInputElement>;
|
|
6
|
+
preventMouseWheel: boolean;
|
|
7
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
8
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
9
|
+
onChange?: FormEventHandler<HTMLInputElement>;
|
|
10
|
+
}
|
|
11
|
+
interface Returns {
|
|
12
|
+
value: EnhanceInputPrimitiveProps['value'];
|
|
13
|
+
inputRef: RefObject<HTMLInputElement>;
|
|
14
|
+
onFocus: FocusEventHandler<HTMLInputElement>;
|
|
15
|
+
onBlur: FocusEventHandler<HTMLInputElement>;
|
|
16
|
+
onChange: FormEventHandler<HTMLInputElement>;
|
|
17
|
+
}
|
|
18
|
+
export declare const useNumberInputBehaviours: ({ ref, preventMouseWheel, onBlur: incomingOnBlur, onFocus: incomingOnFocus, onChange: incomingOnChange, value, }: Props) => Returns;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=useNumberInputBehaviours.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNumberInputBehaviours.d.ts","sourceRoot":"","sources":["../../../lib/components/NumberInput/useNumberInputBehaviours.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAChB,SAAS,EAKT,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,0BAA0B,EAAE,MAAM,wCAAwC,CAAC;AAEpF,UAAU,KAAK;IACd,KAAK,EAAE,0BAA0B,CAAC,OAAO,CAAC,CAAC;IAC3C,GAAG,EAAE,SAAS,CAAC,gBAAgB,CAAC,CAAC;IACjC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,OAAO,CAAC,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IAC9C,MAAM,CAAC,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IAC7C,QAAQ,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC9C;AAED,UAAU,OAAO;IAChB,KAAK,EAAE,0BAA0B,CAAC,OAAO,CAAC,CAAC;IAC3C,QAAQ,EAAE,SAAS,CAAC,gBAAgB,CAAC,CAAC;IACtC,OAAO,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IAC7C,MAAM,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IAC5C,QAAQ,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;CAC7C;AAED,eAAO,MAAM,wBAAwB,qHAOlC,KAAK,KAAG,OAqFV,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
export const useNumberInputBehaviours = _ref => {
|
|
5
|
+
let {
|
|
6
|
+
ref,
|
|
7
|
+
preventMouseWheel,
|
|
8
|
+
onBlur: incomingOnBlur,
|
|
9
|
+
onFocus: incomingOnFocus,
|
|
10
|
+
onChange: incomingOnChange,
|
|
11
|
+
value
|
|
12
|
+
} = _ref;
|
|
13
|
+
const inputRef = useRef(ref === null || ref === void 0 ? void 0 : ref.current);
|
|
14
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
15
|
+
const [displayValue, setDisplayValue] = useState(value);
|
|
16
|
+
const onBlur = useCallback(e => {
|
|
17
|
+
if (typeof incomingOnBlur === 'function') incomingOnBlur(e);
|
|
18
|
+
setIsFocused(false);
|
|
19
|
+
setDisplayValue(void 0);
|
|
20
|
+
}, [incomingOnBlur]);
|
|
21
|
+
const onFocus = useCallback(e => {
|
|
22
|
+
if (typeof incomingOnFocus === 'function') incomingOnFocus(e);
|
|
23
|
+
if (typeof value === 'string' && displayValue !== value) setDisplayValue(value);
|
|
24
|
+
setIsFocused(true);
|
|
25
|
+
}, [incomingOnFocus, value, displayValue]);
|
|
26
|
+
const onChange = useCallback(e => {
|
|
27
|
+
if (isFocused) {
|
|
28
|
+
setDisplayValue(e.currentTarget.value);
|
|
29
|
+
}
|
|
30
|
+
if (typeof incomingOnChange === 'function') incomingOnChange(e);
|
|
31
|
+
}, [incomingOnChange, isFocused, value, displayValue]);
|
|
32
|
+
const preventWheel = useCallback(e => {
|
|
33
|
+
e.preventDefault();
|
|
34
|
+
e.stopPropagation();
|
|
35
|
+
}, []);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
let mouseWheelListener;
|
|
38
|
+
let onWheelListener;
|
|
39
|
+
let wheelListener;
|
|
40
|
+
if (preventMouseWheel && inputRef !== null && inputRef !== void 0 && inputRef.current) {
|
|
41
|
+
mouseWheelListener = inputRef.current.addEventListener('mousewheel', preventWheel, {
|
|
42
|
+
passive: false
|
|
43
|
+
});
|
|
44
|
+
onWheelListener = inputRef.current.addEventListener('onwheel', preventWheel, {
|
|
45
|
+
passive: false
|
|
46
|
+
});
|
|
47
|
+
wheelListener = inputRef.current.addEventListener('wheel', preventWheel, {
|
|
48
|
+
passive: false
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return () => {
|
|
52
|
+
if (mouseWheelListener && inputRef.current) inputRef.current.removeEventListener('mousewheel', mouseWheelListener);
|
|
53
|
+
if (onWheelListener && inputRef.current) inputRef.current.removeEventListener('onwheel', onWheelListener);
|
|
54
|
+
if (wheelListener && inputRef.current) inputRef.current.removeEventListener('wheel', wheelListener);
|
|
55
|
+
};
|
|
56
|
+
}, [preventMouseWheel, inputRef.current]);
|
|
57
|
+
return {
|
|
58
|
+
inputRef,
|
|
59
|
+
onBlur,
|
|
60
|
+
onFocus,
|
|
61
|
+
onChange,
|
|
62
|
+
value: typeof displayValue === 'string' ? displayValue : value
|
|
63
|
+
};
|
|
64
|
+
};
|