@symply.io/basic-components 1.5.5-alpha.5 → 1.5.5-alpha.6
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/NumberInput/index.js
CHANGED
@@ -40,8 +40,8 @@ function NumberInput(props) {
|
|
40
40
|
decimals: decimals,
|
41
41
|
integerOnly: integerOnly,
|
42
42
|
onChange: onChange
|
43
|
-
}), typing = _f.typing, exceedError = _f.exceedError, tooltipOpen = _f.tooltipOpen, roundedValue = _f.roundedValue, handleBlur = _f.handleBlur, handleFocus = _f.handleFocus, handleChange = _f.handleChange, onOpenTooltip = _f.onOpenTooltip, onCloseTooltip = _f.onCloseTooltip, handleKeyboardEvent = _f.handleKeyboardEvent;
|
43
|
+
}), typing = _f.typing, exceedError = _f.exceedError, tooltipOpen = _f.tooltipOpen, roundedValue = _f.roundedValue, handleBlur = _f.handleBlur, handleFocus = _f.handleFocus, handleClick = _f.handleClick, handleChange = _f.handleChange, onOpenTooltip = _f.onOpenTooltip, onCloseTooltip = _f.onCloseTooltip, handleKeyboardEvent = _f.handleKeyboardEvent;
|
44
44
|
var valueDisplay = useMemo(function () { return (typing ? value : roundedValue); }, [typing, value, roundedValue]);
|
45
|
-
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Tooltip, __assign({ arrow: true, placement: "top", title: tooltip !== null && tooltip !== void 0 ? tooltip : "", open: !!tooltip && tooltipOpen }, { children: _jsx(Field, __assign({ size: size, margin: "dense", type: "number", value: value === undefined || value === null ? "" : valueDisplay, onMouseEnter: onOpenTooltip, onMouseLeave: onCloseTooltip, onBlur: handleBlur, onFocus: handleFocus, onChange: handleChange, error: error || exceedError, helperText: helperText || (exceedError ? EXCEED_ERROR : ""), inputProps: { onKeyDown: handleKeyboardEvent } }, rest)) })) })));
|
45
|
+
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(Tooltip, __assign({ arrow: true, placement: "top", title: tooltip !== null && tooltip !== void 0 ? tooltip : "", open: !!tooltip && tooltipOpen }, { children: _jsx(Field, __assign({ size: size, margin: "dense", type: "number", value: value === undefined || value === null ? "" : valueDisplay, onMouseEnter: onOpenTooltip, onMouseLeave: onCloseTooltip, onBlur: handleBlur, onFocus: handleFocus, onChange: handleChange, error: error || exceedError, helperText: helperText || (exceedError ? EXCEED_ERROR : ""), inputProps: { onKeyDown: handleKeyboardEvent, onClick: handleClick } }, rest)) })) })));
|
46
46
|
}
|
47
47
|
export default NumberInput;
|
package/NumberInput/types.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { CSSProperties, ChangeEvent, FocusEventHandler, KeyboardEventHandler } from "react";
|
1
|
+
import { CSSProperties, ChangeEvent, MouseEventHandler, FocusEventHandler, KeyboardEventHandler } from "react";
|
2
2
|
import { TextFieldProps } from "@mui/material/TextField";
|
3
3
|
export interface InteractionStates {
|
4
4
|
typing: boolean;
|
@@ -7,6 +7,7 @@ export interface InteractionStates {
|
|
7
7
|
roundedValue: string;
|
8
8
|
exceedError: boolean;
|
9
9
|
handleKeyboardEvent: KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
10
|
+
handleClick: MouseEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
10
11
|
handleChange: (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
11
12
|
handleFocus: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
12
13
|
handleBlur: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
@@ -7,6 +7,7 @@ declare function useInteractions(props: InteractionProps): {
|
|
7
7
|
roundedValue: string;
|
8
8
|
handleBlur: import("react").FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
9
9
|
handleFocus: import("react").FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
10
|
+
handleClick: import("react").MouseEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
10
11
|
handleChange: (event: import("react").ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
11
12
|
onOpenTooltip: () => void;
|
12
13
|
onCloseTooltip: () => void;
|
@@ -26,7 +26,6 @@ function useInteractions(props) {
|
|
26
26
|
}, [value, decimals]);
|
27
27
|
var exceedError = useMemo(function () { return !!value && (Number(value) < minValue || Number(value) > maxValue); }, [value, minValue, maxValue]);
|
28
28
|
var handleKeyboardEvent = useCallback(function (event) {
|
29
|
-
var _a, _b;
|
30
29
|
var key = event.key;
|
31
30
|
if (key === "e") {
|
32
31
|
event.preventDefault();
|
@@ -44,14 +43,12 @@ function useInteractions(props) {
|
|
44
43
|
event.preventDefault();
|
45
44
|
}
|
46
45
|
else if (String(value).includes(".") && decimals > 0) {
|
47
|
-
var cursorPos = ((_b = (_a = document.getSelection()) === null || _a === void 0 ? void 0 : _a.getRangeAt(0)) === null || _b === void 0 ? void 0 : _b.startOffset) || 0;
|
48
46
|
var decimalPointIndex = String(value).lastIndexOf(".");
|
49
47
|
var decimalStrLen = String(value).split(".")[1].length;
|
50
48
|
console.log({
|
51
49
|
cursorIndex: cursorIndex,
|
52
50
|
decimalPointIndex: decimalPointIndex,
|
53
|
-
decimalStrLen: decimalStrLen
|
54
|
-
cursorPos: cursorPos
|
51
|
+
decimalStrLen: decimalStrLen
|
55
52
|
});
|
56
53
|
if (cursorIndex && decimalPointIndex <= cursorIndex) {
|
57
54
|
if (![
|
@@ -81,6 +78,13 @@ function useInteractions(props) {
|
|
81
78
|
return;
|
82
79
|
onChange(val);
|
83
80
|
}, [onChange, minValue, integerOnly]);
|
81
|
+
var handleClick = useCallback(function (event) {
|
82
|
+
console.log({
|
83
|
+
cts: event.currentTarget.selectionStart,
|
84
|
+
cte: event.currentTarget.selectionEnd
|
85
|
+
});
|
86
|
+
event.currentTarget.setSelectionRange(value.length - 1, value.length - 1);
|
87
|
+
}, [value]);
|
84
88
|
var handleFocus = useCallback(function () {
|
85
89
|
setTyping(true);
|
86
90
|
}, []);
|
@@ -118,6 +122,7 @@ function useInteractions(props) {
|
|
118
122
|
roundedValue: roundedValue,
|
119
123
|
handleBlur: handleBlur,
|
120
124
|
handleFocus: handleFocus,
|
125
|
+
handleClick: handleClick,
|
121
126
|
handleChange: handleChange,
|
122
127
|
onOpenTooltip: onOpenTooltip,
|
123
128
|
onCloseTooltip: onCloseTooltip,
|