@symply.io/basic-components 1.5.1 → 1.5.2-alpha.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.
@@ -1,14 +1,3 @@
1
- import { CSSProperties } from "react";
2
- import { TextFieldProps } from "@mui/material/TextField";
3
- export interface NumberInputProps extends Omit<TextFieldProps, "onChange"> {
4
- onChange: (value: string) => void;
5
- value: string;
6
- integerOnly?: boolean;
7
- tooltip?: string;
8
- maxValue?: number;
9
- minValue?: number;
10
- primaryColor?: CSSProperties["color"];
11
- secondaryColor?: CSSProperties["color"];
12
- }
1
+ import type { NumberInputProps } from "./types";
13
2
  declare function NumberInput(props: NumberInputProps): JSX.Element;
14
3
  export default NumberInput;
@@ -27,12 +27,19 @@ import ThemeProvider from "@mui/material/styles/ThemeProvider";
27
27
  import useInteractions from "./useInteractions";
28
28
  import useCustomTheme from "../useCustomTheme";
29
29
  function NumberInput(props) {
30
- var onChange = props.onChange, value = props.value, _a = props.size, size = _a === void 0 ? "small" : _a, tooltip = props.tooltip, _b = props.integerOnly, integerOnly = _b === void 0 ? false : _b, _c = props.minValue, minValue = _c === void 0 ? Number.MIN_SAFE_INTEGER : _c, _d = props.maxValue, maxValue = _d === void 0 ? Number.MAX_SAFE_INTEGER : _d, error = props.error, helperText = props.helperText, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, rest = __rest(props, ["onChange", "value", "size", "tooltip", "integerOnly", "minValue", "maxValue", "error", "helperText", "primaryColor", "secondaryColor"]);
30
+ var onChange = props.onChange, value = props.value, _a = props.size, size = _a === void 0 ? "small" : _a, tooltip = props.tooltip, _b = props.integerOnly, integerOnly = _b === void 0 ? false : _b, _c = props.decimals, decimals = _c === void 0 ? 0 : _c, _d = props.minValue, minValue = _d === void 0 ? Number.MIN_SAFE_INTEGER : _d, _e = props.maxValue, maxValue = _e === void 0 ? Number.MAX_SAFE_INTEGER : _e, error = props.error, helperText = props.helperText, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, rest = __rest(props, ["onChange", "value", "size", "tooltip", "integerOnly", "decimals", "minValue", "maxValue", "error", "helperText", "primaryColor", "secondaryColor"]);
31
31
  var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
32
32
  var EXCEED_ERROR = "Your value exceeds the exceptable input range";
33
33
  if (maxValue < minValue)
34
34
  throw new Error("Max should be bigger than the `miniValue`!");
35
- var _e = useInteractions({ maxValue: maxValue, minValue: minValue, value: value, integerOnly: integerOnly, onChange: onChange }), exceedError = _e.exceedError, tooltipOpen = _e.tooltipOpen, handleBlur = _e.handleBlur, handleChange = _e.handleChange, onOpenTooltip = _e.onOpenTooltip, onCloseTooltip = _e.onCloseTooltip, handleKeyboardEvent = _e.handleKeyboardEvent;
35
+ var _f = useInteractions({
36
+ value: value,
37
+ maxValue: maxValue,
38
+ minValue: minValue,
39
+ decimals: decimals,
40
+ integerOnly: integerOnly,
41
+ onChange: onChange
42
+ }), exceedError = _f.exceedError, tooltipOpen = _f.tooltipOpen, handleBlur = _f.handleBlur, handleChange = _f.handleChange, onOpenTooltip = _f.onOpenTooltip, onCloseTooltip = _f.onCloseTooltip, handleKeyboardEvent = _f.handleKeyboardEvent;
36
43
  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 ? "" : value, onMouseEnter: onOpenTooltip, onMouseLeave: onCloseTooltip, onBlur: handleBlur, onChange: handleChange, error: error || exceedError, helperText: helperText || (exceedError ? EXCEED_ERROR : ""), inputProps: { onKeyDown: handleKeyboardEvent } }, rest)) })) })));
37
44
  }
38
45
  export default NumberInput;
@@ -0,0 +1,15 @@
1
+ import { CSSProperties } from "react";
2
+ import { TextFieldProps } from "@mui/material/TextField";
3
+ export interface InteractionProps {
4
+ value: string;
5
+ integerOnly?: boolean;
6
+ decimals?: number;
7
+ maxValue?: number;
8
+ minValue?: number;
9
+ onChange: (value: string) => void;
10
+ }
11
+ export interface NumberInputProps extends InteractionProps, Omit<TextFieldProps, "value" | "onChange"> {
12
+ tooltip?: string;
13
+ primaryColor?: CSSProperties["color"];
14
+ secondaryColor?: CSSProperties["color"];
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,11 +1,5 @@
1
1
  import { ChangeEvent, KeyboardEventHandler } from "react";
2
- interface InteractionProps {
3
- value: string;
4
- integerOnly?: boolean;
5
- maxValue?: number;
6
- minValue?: number;
7
- onChange: (value: string) => void;
8
- }
2
+ import type { InteractionProps } from "./types";
9
3
  declare function useInteractions(props: InteractionProps): {
10
4
  exceedError: boolean;
11
5
  tooltipOpen: boolean;
@@ -1,7 +1,7 @@
1
1
  import { useState, useCallback, useMemo } from "react";
2
2
  function useInteractions(props) {
3
- var value = props.value, integerOnly = props.integerOnly, _a = props.minValue, minValue = _a === void 0 ? Number.MIN_SAFE_INTEGER : _a, _b = props.maxValue, maxValue = _b === void 0 ? Number.MAX_SAFE_INTEGER : _b, onChange = props.onChange;
4
- var _c = useState(false), tooltipOpen = _c[0], setTooltipOpen = _c[1];
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
+ var _d = useState(false), tooltipOpen = _d[0], setTooltipOpen = _d[1];
5
5
  var exceedError = useMemo(function () { return !!value && (Number(value) < minValue || Number(value) > maxValue); }, [value, minValue, maxValue]);
6
6
  var handleKeyboardEvent = useCallback(function (event) {
7
7
  var key = event.key;
@@ -16,6 +16,12 @@ function useInteractions(props) {
16
16
  event.preventDefault();
17
17
  }
18
18
  }
19
+ else if (value.includes(".") && decimals > 0) {
20
+ var decimalStrLen = value.split(".")[1].length;
21
+ if (key !== "Backspace" && decimalStrLen >= decimals) {
22
+ event.preventDefault();
23
+ }
24
+ }
19
25
  else {
20
26
  if (key === "-") {
21
27
  event.preventDefault();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symply.io/basic-components",
3
- "version": "1.5.1",
3
+ "version": "1.5.2-alpha.1",
4
4
  "description": "Basic and reusable components for all frontend of Symply apps",
5
5
  "keywords": [
6
6
  "react",