@symply.io/basic-components 1.5.5-alpha.1 → 1.5.5-alpha.2

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.
@@ -1,5 +1,18 @@
1
- import { CSSProperties } from "react";
1
+ import { CSSProperties, ChangeEvent, FocusEventHandler, KeyboardEventHandler } from "react";
2
2
  import { TextFieldProps } from "@mui/material/TextField";
3
+ export interface InteractionStates {
4
+ typing: boolean;
5
+ tooltipOpen: boolean;
6
+ cursorIndex: number;
7
+ roundedValue: string;
8
+ exceedError: boolean;
9
+ handleKeyboardEvent: KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
10
+ handleChange: (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
11
+ handleFocus: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
12
+ handleBlur: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
13
+ onOpenTooltip: () => void;
14
+ onCloseTooltip: () => void;
15
+ }
3
16
  export interface InteractionProps {
4
17
  value: string;
5
18
  integerOnly?: boolean;
@@ -1,12 +1,12 @@
1
- import { ChangeEvent, KeyboardEventHandler } from "react";
1
+ import { ChangeEvent, FocusEventHandler, KeyboardEventHandler } from "react";
2
2
  import type { InteractionProps } from "./types";
3
3
  declare function useInteractions(props: InteractionProps): {
4
4
  typing: boolean;
5
5
  exceedError: boolean;
6
6
  tooltipOpen: boolean;
7
7
  roundedValue: string;
8
- handleBlur: () => void;
9
- handleFocus: () => void;
8
+ handleBlur: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
9
+ handleFocus: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
10
10
  handleChange: (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
11
11
  onOpenTooltip: () => void;
12
12
  onCloseTooltip: () => void;
@@ -3,7 +3,7 @@ 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(value), register = _f[0], setRegister = _f[1];
6
+ var _f = useState(0), cursorIndex = _f[0], setCursorIndex = _f[1];
7
7
  var roundedValue = useMemo(function () {
8
8
  if (value === null || value === undefined) {
9
9
  return "";
@@ -26,7 +26,7 @@ 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 key = event.key, currentTarget = event.currentTarget;
29
+ var key = event.key;
30
30
  if (key === "e") {
31
31
  event.preventDefault();
32
32
  }
@@ -45,8 +45,8 @@ function useInteractions(props) {
45
45
  else if (String(value).includes(".") && decimals > 0) {
46
46
  var decimalPointIndex = String(value).lastIndexOf(".");
47
47
  var decimalStrLen = String(value).split(".")[1].length;
48
- var selectionStart = currentTarget.selectionStart;
49
- if (selectionStart && decimalPointIndex <= selectionStart) {
48
+ console.log({ cursorIndex: cursorIndex, decimalPointIndex: decimalPointIndex, decimalStrLen: decimalStrLen });
49
+ if (cursorIndex && decimalPointIndex <= cursorIndex) {
50
50
  if (![
51
51
  "Backspace",
52
52
  "ArrowUp",
@@ -60,7 +60,7 @@ function useInteractions(props) {
60
60
  }
61
61
  }
62
62
  }
63
- }, [value, minValue, integerOnly]);
63
+ }, [value, minValue, cursorIndex, integerOnly]);
64
64
  var handleChange = useCallback(function (event) {
65
65
  event.preventDefault();
66
66
  var val = event.currentTarget.value;
@@ -74,9 +74,9 @@ function useInteractions(props) {
74
74
  return;
75
75
  onChange(val);
76
76
  }, [onChange, minValue, integerOnly]);
77
- var handleFocus = useCallback(function () {
77
+ var handleFocus = useCallback(function (event) {
78
78
  setTyping(true);
79
- setRegister(value);
79
+ setCursorIndex(event.target.selectionStart || 0);
80
80
  }, [value]);
81
81
  var handleBlur = useCallback(function () {
82
82
  var excludedValue = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symply.io/basic-components",
3
- "version": "1.5.5-alpha.1",
3
+ "version": "1.5.5-alpha.2",
4
4
  "description": "Basic and reusable components for all frontend of Symply apps",
5
5
  "keywords": [
6
6
  "react",