@symply.io/basic-components 1.4.11-alpha.8 → 1.5.0-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.
@@ -0,0 +1,3 @@
1
+ import type { ClickableFabButtonProps } from "./types";
2
+ declare function ClickableFabButton(props: ClickableFabButtonProps): JSX.Element;
3
+ export default ClickableFabButton;
@@ -0,0 +1,48 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { cloneElement } from "react";
14
+ import Grid from "@mui/material/Grid";
15
+ import Button from "@mui/material/Button";
16
+ import Typography from "@mui/material/Typography";
17
+ import useCustomTheme from "../useCustomTheme";
18
+ function ClickableFabButton(props) {
19
+ var text = props.text, fabIcon = props.fabIcon, _a = props.color, color = _a === void 0 ? "primary" : _a, disabled = props.disabled, onClick = props.onClick, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor;
20
+ var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
21
+ return (_jsxs(Button, __assign({ color: color, onClick: onClick, disabled: disabled, sx: {
22
+ outline: "none",
23
+ color: "rgba(0, 0, 0, 0)",
24
+ "&:hover": {
25
+ backgroundColor: "rgba(0, 0, 0, 0)",
26
+ "& div": {
27
+ boxShadow: "0px 3px 5px -1px rgba(0,0,0,0.2), 0px 6px 10px 0px rgba(0,0,0,0.2), 0px 1px 18px 0px rgba(0,0,0,0.2)"
28
+ },
29
+ "& span": {
30
+ textShadow: "1px 1px 3px rgba(0,0,0,0.4)"
31
+ }
32
+ }
33
+ } }, { children: [_jsx(Grid, __assign({ sx: {
34
+ display: "flex",
35
+ alignItems: "center",
36
+ justifyContent: "center",
37
+ height: "40px",
38
+ width: "40px",
39
+ borderRadius: "50%",
40
+ color: "#ffffff",
41
+ background: disabled ? "#9e9e9e" : theme.palette[color].main,
42
+ boxShadow: "0px 3px 5px -1px rgba(0,0,0,0.05), 0px 6px 10px 0px rgba(0,0,0,0.1), 0px 1px 18px 0px rgba(0,0,0,0.1)"
43
+ } }, { children: cloneElement(fabIcon) })), "\u00A0\u00A0", _jsx(Typography, __assign({ variant: "body2", component: "span", color: disabled ? "#9e9e9e" : color, sx: {
44
+ textShadow: "1px 1px 3px rgba(0,0,0,0.2)",
45
+ fontSize: "16px !important"
46
+ } }, { children: text }))] })));
47
+ }
48
+ export default ClickableFabButton;
@@ -0,0 +1,12 @@
1
+ import type { ReactElement, CSSProperties } from "react";
2
+ import type { ButtonProps } from "@mui/material/Button";
3
+ export interface ClickableFabButtonProps {
4
+ text: string;
5
+ fabIcon: ReactElement;
6
+ disabled?: boolean;
7
+ size?: ButtonProps["size"];
8
+ color?: "error" | "primary" | "secondary" | "success" | "info" | "warning";
9
+ onClick: ButtonProps["onClick"];
10
+ primaryColor?: CSSProperties["color"];
11
+ secondaryColor?: CSSProperties["color"];
12
+ }
@@ -1,4 +1,14 @@
1
- import type { NumberInputProps } from "./types";
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
+ }
2
13
  declare function NumberInput(props: NumberInputProps): JSX.Element;
3
14
  export default NumberInput;
4
- export type { NumberInputProps };
@@ -27,19 +27,12 @@ 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.decimals, decimals = _b === void 0 ? 0 : _b, _c = props.integerOnly, integerOnly = _c === void 0 ? false : _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", "decimals", "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.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"]);
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 _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;
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;
43
36
  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)) })) })));
44
37
  }
45
38
  export default NumberInput;
@@ -1,5 +1,11 @@
1
1
  import { ChangeEvent, KeyboardEventHandler } from "react";
2
- import type { InteractionProps } from "./types";
2
+ interface InteractionProps {
3
+ value: string;
4
+ integerOnly?: boolean;
5
+ maxValue?: number;
6
+ minValue?: number;
7
+ onChange: (value: string) => void;
8
+ }
3
9
  declare function useInteractions(props: InteractionProps): {
4
10
  exceedError: boolean;
5
11
  tooltipOpen: boolean;
@@ -1,7 +1,7 @@
1
1
  import { useState, useCallback, useMemo } from "react";
2
2
  function useInteractions(props) {
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];
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];
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;
@@ -20,19 +20,19 @@ function useInteractions(props) {
20
20
  if (key === "-") {
21
21
  event.preventDefault();
22
22
  }
23
- else if (decimals > 0) {
24
- var decimalStr = value.split(".")[1];
25
- var decimalLen = decimalStr ? decimalStr.length + 1 : 0;
26
- console.log({ value: value, decimals: decimals, decimalLen: decimalLen });
27
- if (decimalLen > decimals) {
28
- event.preventDefault();
29
- }
30
- }
31
23
  }
32
- }, [value, decimals, minValue, integerOnly]);
24
+ }, [value, minValue, integerOnly]);
33
25
  var handleChange = useCallback(function (event) {
34
26
  event.preventDefault();
35
27
  var val = event.currentTarget.value;
28
+ if (val !== "" && minValue >= 0 && val.includes("-"))
29
+ return;
30
+ if (integerOnly) {
31
+ if (val !== "" && val !== "-" && !/^\d+$/g.test(val))
32
+ return;
33
+ }
34
+ else if (val !== "" && val !== "-" && !/^(-?\d*)(\.\d*)?$/g.test(val))
35
+ return;
36
36
  onChange(val);
37
37
  }, [onChange, minValue, integerOnly]);
38
38
  var handleBlur = useCallback(function () {
@@ -54,6 +54,9 @@ function useInteractions(props) {
54
54
  else if (excludedValue.includes(strVal)) {
55
55
  onChange("");
56
56
  }
57
+ else {
58
+ onChange(Number(strVal).toString());
59
+ }
57
60
  }, [value, onChange]);
58
61
  var onOpenTooltip = useCallback(function () {
59
62
  setTooltipOpen(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symply.io/basic-components",
3
- "version": "1.4.11-alpha.8",
3
+ "version": "1.5.0-beta.1",
4
4
  "description": "Basic and reusable components for all frontend of Symply apps",
5
5
  "keywords": [
6
6
  "react",
@@ -1,15 +0,0 @@
1
- import type { CSSProperties } from "react";
2
- import type { TextFieldProps } from "@mui/material/TextField";
3
- export interface InteractionProps {
4
- value: string;
5
- decimals?: number;
6
- integerOnly?: boolean;
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
- }
File without changes