@symply.io/basic-components 1.5.5-alpha.6 → 1.5.5-beta.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.
@@ -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, handleClick = _f.handleClick, 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, 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, onClick: handleClick } }, 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: "text", 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)) })) })));
46
46
  }
47
47
  export default NumberInput;
@@ -1,4 +1,4 @@
1
- import { CSSProperties, ChangeEvent, MouseEventHandler, FocusEventHandler, KeyboardEventHandler } from "react";
1
+ import { CSSProperties, ChangeEvent, FocusEventHandler, KeyboardEventHandler } from "react";
2
2
  import { TextFieldProps } from "@mui/material/TextField";
3
3
  export interface InteractionStates {
4
4
  typing: boolean;
@@ -7,7 +7,6 @@ export interface InteractionStates {
7
7
  roundedValue: string;
8
8
  exceedError: boolean;
9
9
  handleKeyboardEvent: KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
10
- handleClick: MouseEventHandler<HTMLInputElement | HTMLTextAreaElement>;
11
10
  handleChange: (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
12
11
  handleFocus: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
13
12
  handleBlur: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
@@ -7,7 +7,6 @@ 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>;
11
10
  handleChange: (event: import("react").ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
12
11
  onOpenTooltip: () => void;
13
12
  onCloseTooltip: () => void;
@@ -3,7 +3,6 @@ function useInteractions(props) {
3
3
  var value = props.value, _a = props.decimals, decimals = _a === void 0 ? 0 : _a, integerOnly = props.integerOnly, _b = props.minValue, minValue = _b === void 0 ? Number.MIN_SAFE_INTEGER : _b, _c = props.maxValue, maxValue = _c === void 0 ? Number.MAX_SAFE_INTEGER : _c, onChange = props.onChange;
4
4
  var _d = useState(false), tooltipOpen = _d[0], setTooltipOpen = _d[1];
5
5
  var _e = useState(false), typing = _e[0], setTyping = _e[1];
6
- var _f = useState(0), cursorIndex = _f[0], setCursorIndex = _f[1];
7
6
  var roundedValue = useMemo(function () {
8
7
  if (value === null || value === undefined) {
9
8
  return "";
@@ -26,7 +25,7 @@ function useInteractions(props) {
26
25
  }, [value, decimals]);
27
26
  var exceedError = useMemo(function () { return !!value && (Number(value) < minValue || Number(value) > maxValue); }, [value, minValue, maxValue]);
28
27
  var handleKeyboardEvent = useCallback(function (event) {
29
- var key = event.key;
28
+ var key = event.key, currentTarget = event.currentTarget;
30
29
  if (key === "e") {
31
30
  event.preventDefault();
32
31
  }
@@ -43,14 +42,15 @@ function useInteractions(props) {
43
42
  event.preventDefault();
44
43
  }
45
44
  else if (String(value).includes(".") && decimals > 0) {
45
+ var selectionStart = currentTarget.selectionStart;
46
46
  var decimalPointIndex = String(value).lastIndexOf(".");
47
47
  var decimalStrLen = String(value).split(".")[1].length;
48
48
  console.log({
49
- cursorIndex: cursorIndex,
50
49
  decimalPointIndex: decimalPointIndex,
51
- decimalStrLen: decimalStrLen
50
+ decimalStrLen: decimalStrLen,
51
+ selectionStart: selectionStart
52
52
  });
53
- if (cursorIndex && decimalPointIndex <= cursorIndex) {
53
+ if (selectionStart && decimalPointIndex < selectionStart) {
54
54
  if (![
55
55
  "Backspace",
56
56
  "ArrowUp",
@@ -64,7 +64,7 @@ function useInteractions(props) {
64
64
  }
65
65
  }
66
66
  }
67
- }, [value, minValue, cursorIndex, integerOnly]);
67
+ }, [value, minValue, integerOnly]);
68
68
  var handleChange = useCallback(function (event) {
69
69
  event.preventDefault();
70
70
  var val = event.currentTarget.value;
@@ -78,13 +78,6 @@ function useInteractions(props) {
78
78
  return;
79
79
  onChange(val);
80
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]);
88
81
  var handleFocus = useCallback(function () {
89
82
  setTyping(true);
90
83
  }, []);
@@ -122,7 +115,6 @@ function useInteractions(props) {
122
115
  roundedValue: roundedValue,
123
116
  handleBlur: handleBlur,
124
117
  handleFocus: handleFocus,
125
- handleClick: handleClick,
126
118
  handleChange: handleChange,
127
119
  onOpenTooltip: onOpenTooltip,
128
120
  onCloseTooltip: onCloseTooltip,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symply.io/basic-components",
3
- "version": "1.5.5-alpha.6",
3
+ "version": "1.5.5-beta.1",
4
4
  "description": "Basic and reusable components for all frontend of Symply apps",
5
5
  "keywords": [
6
6
  "react",