@codezee/sixtify-brahma 0.2.202 → 0.2.203

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codezee/sixtify-brahma",
3
- "version": "0.2.202",
3
+ "version": "0.2.203",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/hardikranpariya/sixtify-brahma.git"
@@ -3,18 +3,20 @@ import { type TextFieldProps as MuiTextFieldProps } from "@mui/material/TextFiel
3
3
  import { type FieldValues, type UseControllerProps } from "react-hook-form";
4
4
  import { type NavigationKey } from "../../utils/hooks/useFormFieldFocus";
5
5
  import type { Styling } from "../../utils/types";
6
+ import type { ReactNode } from "react";
6
7
  export type DecimalTextFieldProps<P extends FieldValues> = UseControllerProps<P> & Omit<MuiTextFieldProps, keyof UseControllerProps<P> | "type" | "value" | "onChange"> & {
7
8
  label?: string;
8
9
  loading?: boolean;
9
10
  containerProps?: StackProps;
10
11
  styling?: Styling;
11
- infoMessage?: React.ReactNode;
12
+ infoMessage?: ReactNode;
12
13
  decimalScale: number;
14
+ returnDecimalScale?: number;
13
15
  defaultFallbackValue?: number;
14
16
  min?: number;
15
17
  max?: number;
16
18
  customOnChange?: (value?: number) => void;
17
19
  navigationKey?: NavigationKey;
18
20
  };
19
- export declare function DecimalTextField<P extends FieldValues>({ control, name, decimalScale, defaultFallbackValue, min, max, defaultValue, label, required, disabled, loading, placeholder, containerProps, styling, infoMessage, customOnChange, navigationKey, rules, ...restProps }: DecimalTextFieldProps<P>): import("react/jsx-runtime").JSX.Element;
21
+ export declare function DecimalTextField<P extends FieldValues>({ control, name, decimalScale, returnDecimalScale, defaultFallbackValue, min, max, defaultValue, label, required, disabled, loading, placeholder, containerProps, styling, infoMessage, customOnChange, navigationKey, rules, ...restProps }: DecimalTextFieldProps<P>): import("react/jsx-runtime").JSX.Element;
20
22
  //# sourceMappingURL=DecimalTextField.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DecimalTextField.d.ts","sourceRoot":"","sources":["../../../src/FormFields/DecimalTextField/DecimalTextField.tsx"],"names":[],"mappings":"AAIA,OAAc,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAkB,EAChB,KAAK,cAAc,IAAI,iBAAiB,EACzC,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EAEL,KAAK,aAAa,EACnB,MAAM,qCAAqC,CAAC;AAO7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAGjD,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,WAAW,IACrD,kBAAkB,CAAC,CAAC,CAAC,GACnB,IAAI,CACF,iBAAiB,EACjB,MAAM,kBAAkB,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,CAC5D,GAAG;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,UAAU,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AAEN,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,WAAW,EAAE,EACtD,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,oBAAoB,EACpB,GAAG,EACH,GAAG,EACH,YAAY,EACZ,KAAU,EACV,QAAQ,EACR,QAAQ,EACR,OAAe,EACf,WAAgB,EAChB,cAAc,EACd,OAAkB,EAClB,WAAW,EACX,cAAc,EACd,aAAa,EACb,KAAK,EACL,GAAG,SAAS,EACb,EAAE,qBAAqB,CAAC,CAAC,CAAC,2CAyM1B"}
1
+ {"version":3,"file":"DecimalTextField.d.ts","sourceRoot":"","sources":["../../../src/FormFields/DecimalTextField/DecimalTextField.tsx"],"names":[],"mappings":"AAIA,OAAc,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAkB,EAChB,KAAK,cAAc,IAAI,iBAAiB,EACzC,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EAEL,KAAK,aAAa,EACnB,MAAM,qCAAqC,CAAC;AAO7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAIV,SAAS,EACV,MAAM,OAAO,CAAC;AAEf,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,WAAW,IACrD,kBAAkB,CAAC,CAAC,CAAC,GACnB,IAAI,CACF,iBAAiB,EACjB,MAAM,kBAAkB,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,CAC5D,GAAG;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,UAAU,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,CAAC;AAEN,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,WAAW,EAAE,EACtD,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,EACpB,GAAG,EACH,GAAG,EACH,YAAY,EACZ,KAAU,EACV,QAAQ,EACR,QAAQ,EACR,OAAe,EACf,WAAgB,EAChB,cAAc,EACd,OAAkB,EAClB,WAAW,EACX,cAAc,EACd,aAAa,EACb,KAAK,EACL,GAAG,SAAS,EACb,EAAE,qBAAqB,CAAC,CAAC,CAAC,2CAgS1B"}
@@ -18,14 +18,15 @@ const utils_1 = require("../../utils");
18
18
  const useFormFieldFocus_1 = require("../../utils/hooks/useFormFieldFocus");
19
19
  const commonStyles_1 = require("../commonStyles");
20
20
  const Skeleton_1 = require("../TextField/Skeleton");
21
- function DecimalTextField({ control, name, decimalScale, defaultFallbackValue, min, max, defaultValue, label = "", required, disabled, loading = false, placeholder = "", containerProps, styling = "custom", infoMessage, customOnChange, navigationKey, rules, ...restProps }) {
21
+ function DecimalTextField({ control, name, decimalScale, returnDecimalScale, defaultFallbackValue, min, max, defaultValue, label = "", required, disabled, loading = false, placeholder = "", containerProps, styling = "custom", infoMessage, customOnChange, navigationKey, rules, ...restProps }) {
22
22
  const validationRules = (0, react_1.useMemo)(() => {
23
23
  const builtRules = { ...rules };
24
24
  builtRules.validate = (val) => {
25
- if (required && (val === undefined || val == null)) {
25
+ const isEmpty = val === undefined || val == null;
26
+ if (required && isEmpty) {
26
27
  return "This field is required";
27
28
  }
28
- if (val === undefined || val == null) {
29
+ if (isEmpty) {
29
30
  return true;
30
31
  }
31
32
  if (isNaN(val)) {
@@ -51,6 +52,7 @@ function DecimalTextField({ control, name, decimalScale, defaultFallbackValue, m
51
52
  const resolvedNavigationKey = navigationKey ?? navigationKeyFromContext;
52
53
  const { inputRef: navigationInputRef, maintainFocus, handleKeyDown: handleNavigationKeyDown, } = (0, useFormFieldFocus_1.useFormFieldFocus)({ navigationKey: resolvedNavigationKey });
53
54
  const inputRef = (0, react_1.useRef)(null);
55
+ const lastInputStringRef = (0, react_1.useRef)("");
54
56
  const parseValue = (val) => {
55
57
  if (val === "") {
56
58
  return undefined;
@@ -58,24 +60,73 @@ function DecimalTextField({ control, name, decimalScale, defaultFallbackValue, m
58
60
  const parsed = Number(val);
59
61
  return isNaN(parsed) ? undefined : parsed;
60
62
  };
63
+ const isEmptyReturnDecimalScale = returnDecimalScale === undefined;
64
+ const truncateStringValue = (0, react_1.useCallback)((valStr) => {
65
+ if (isEmptyReturnDecimalScale || valStr === "") {
66
+ return valStr;
67
+ }
68
+ const decimalIndex = valStr.indexOf(".");
69
+ if (decimalIndex === -1) {
70
+ return valStr;
71
+ }
72
+ const integerPart = valStr.substring(0, decimalIndex);
73
+ const decimalPart = valStr.substring(decimalIndex + 1);
74
+ if (decimalPart.length <= returnDecimalScale) {
75
+ return valStr;
76
+ }
77
+ const truncatedDecimal = decimalPart.substring(0, returnDecimalScale);
78
+ return `${integerPart}.${truncatedDecimal}`;
79
+ }, [returnDecimalScale]);
80
+ const formatReturnValue = (0, react_1.useCallback)((valStr) => {
81
+ if (valStr === undefined || valStr == null || valStr === "") {
82
+ return undefined;
83
+ }
84
+ if (isEmptyReturnDecimalScale) {
85
+ return typeof valStr === "string" ? parseValue(valStr) : valStr;
86
+ }
87
+ const valString = typeof valStr === "string" ? valStr : valStr.toString();
88
+ const truncatedStr = truncateStringValue(valString);
89
+ return parseValue(truncatedStr);
90
+ }, [returnDecimalScale, truncateStringValue]);
61
91
  const handleValueChange = (0, react_1.useCallback)((values) => {
62
- const numericValue = parseValue(values.value);
92
+ const rawValue = values.value;
93
+ lastInputStringRef.current = rawValue;
94
+ const numericValue = parseValue(rawValue);
63
95
  onChange(numericValue);
64
- customOnChange?.(numericValue);
96
+ const returnValue = !isEmptyReturnDecimalScale
97
+ ? formatReturnValue(rawValue)
98
+ : numericValue;
99
+ customOnChange?.(returnValue);
65
100
  maintainFocus();
66
- }, [onChange, customOnChange, maintainFocus]);
101
+ }, [
102
+ onChange,
103
+ customOnChange,
104
+ maintainFocus,
105
+ formatReturnValue,
106
+ returnDecimalScale,
107
+ ]);
67
108
  const isValidValue = (0, react_1.useCallback)((val) => {
68
109
  if (val === undefined || isNaN(val)) {
69
110
  return false;
70
111
  }
71
112
  return ((min === undefined || val >= min) && (max === undefined || val <= max));
72
113
  }, [min, max]);
73
- const handleBlur = (0, react_1.useCallback)((event) => {
74
- const currentValue = typeof value === "number" ? value : undefined;
75
- // If value is invalid, reset to fallback value
114
+ const handleBlur = (0, react_1.useCallback)(
115
+ // eslint-disable-next-line sonarjs/cognitive-complexity
116
+ (event) => {
117
+ const inputStringValue = lastInputStringRef.current || "";
118
+ let currentValue;
119
+ if (inputStringValue) {
120
+ currentValue = parseValue(inputStringValue);
121
+ }
122
+ else if (typeof value === "number") {
123
+ currentValue = value;
124
+ }
125
+ else {
126
+ currentValue = undefined;
127
+ }
76
128
  if (error && currentValue !== undefined && !isValidValue(currentValue)) {
77
129
  let resetValue;
78
- // Priority: defaultFallbackValue > min > 0
79
130
  if (defaultFallbackValue !== undefined &&
80
131
  isValidValue(defaultFallbackValue)) {
81
132
  resetValue = defaultFallbackValue;
@@ -91,6 +142,7 @@ function DecimalTextField({ control, name, decimalScale, defaultFallbackValue, m
91
142
  }
92
143
  onChange(resetValue);
93
144
  }
145
+ lastInputStringRef.current = "";
94
146
  onBlur();
95
147
  restProps.onBlur?.(event);
96
148
  }, [
@@ -103,6 +155,8 @@ function DecimalTextField({ control, name, decimalScale, defaultFallbackValue, m
103
155
  onChange,
104
156
  onBlur,
105
157
  restProps,
158
+ returnDecimalScale,
159
+ formatReturnValue,
106
160
  ]);
107
161
  const handleKeyDown = (0, react_1.useCallback)((event) => {
108
162
  handleNavigationKeyDown(event, undefined, false);
@@ -119,10 +173,14 @@ function DecimalTextField({ control, name, decimalScale, defaultFallbackValue, m
119
173
  }
120
174
  }, [ref, navigationInputRef]);
121
175
  const displayValue = (0, react_1.useMemo)(() => {
122
- return typeof value === "number" ? value : "";
176
+ if (typeof value !== "number") {
177
+ return "";
178
+ }
179
+ return value;
123
180
  }, [value]);
124
181
  if (loading) {
125
182
  return (0, jsx_runtime_1.jsx)(Skeleton_1.Skeleton, { label: label, styling: styling });
126
183
  }
127
- return ((0, jsx_runtime_1.jsxs)(Stack_1.default, { ...containerProps, gap: "5px", children: [label && styling === "custom" && ((0, jsx_runtime_1.jsxs)(Stack_1.default, { direction: "row", alignItems: "center", gap: "4px", children: [(0, jsx_runtime_1.jsx)(InputLabel_1.default, { required: required, disabled: disabled, children: label }), infoMessage && ((0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { toolTipLabel: infoMessage, children: (0, jsx_runtime_1.jsx)(InfoOutlined_1.default, { sx: { fontSize: 13 } }) }))] })), (0, jsx_runtime_1.jsx)(react_number_format_1.NumericFormat, { customInput: TextField_1.default, ...restProps, value: displayValue, decimalScale: decimalScale, fixedDecimalScale: true, allowNegative: false, thousandSeparator: false, disabled: disabled, required: required, fullWidth: true, name: name, error: Boolean(error), helperText: error?.message, placeholder: styling === "default" ? placeholder : placeholder || label, label: styling === "default" ? label : undefined, sx: (0, commonStyles_1.getDefaultTextFieldSx)(styling), InputLabelProps: (0, commonStyles_1.getDefaultInputLabelProps)(styling), onValueChange: handleValueChange, onBlur: handleBlur, onKeyDown: handleKeyDown, inputMode: "decimal", getInputRef: handleInputRef })] }));
184
+ return ((0, jsx_runtime_1.jsxs)(Stack_1.default, { ...containerProps, gap: "5px", children: [label && styling === "custom" && ((0, jsx_runtime_1.jsxs)(Stack_1.default, { direction: "row", alignItems: "center", gap: "4px", children: [(0, jsx_runtime_1.jsx)(InputLabel_1.default, { required: required, disabled: disabled, children: label }), infoMessage && ((0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { toolTipLabel: infoMessage, children: (0, jsx_runtime_1.jsx)(InfoOutlined_1.default, { sx: { fontSize: 13 } }) }))] })), (0, jsx_runtime_1.jsx)(react_number_format_1.NumericFormat, { customInput: TextField_1.default, ...restProps, value: displayValue, decimalScale: decimalScale, fixedDecimalScale: returnDecimalScale === undefined ||
185
+ returnDecimalScale === decimalScale, allowNegative: false, thousandSeparator: false, disabled: disabled, required: required, fullWidth: true, name: name, error: Boolean(error), helperText: error?.message, placeholder: styling === "default" ? placeholder : placeholder || label, label: styling === "default" ? label : undefined, sx: (0, commonStyles_1.getDefaultTextFieldSx)(styling), InputLabelProps: (0, commonStyles_1.getDefaultInputLabelProps)(styling), onValueChange: handleValueChange, onBlur: handleBlur, onKeyDown: handleKeyDown, inputMode: "decimal", getInputRef: handleInputRef })] }));
128
186
  }
@@ -1,3 +1,3 @@
1
1
  import { type TablePaginationProps } from "@mui/material/TablePagination";
2
- export declare const Pagination: ({ count, page, onPageChange, rowsPerPage, onRowsPerPageChange, ...rest }: TablePaginationProps) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const Pagination: ({ count, page, onPageChange, rowsPerPage, onRowsPerPageChange, sx, ...rest }: TablePaginationProps) => import("react/jsx-runtime").JSX.Element;
3
3
  //# sourceMappingURL=Pagination.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Pagination.d.ts","sourceRoot":"","sources":["../../src/Pagination/Pagination.tsx"],"names":[],"mappings":"AACA,OAAwB,EACtB,KAAK,oBAAoB,EAC1B,MAAM,+BAA+B,CAAC;AAIvC,eAAO,MAAM,UAAU,GAAI,0EAOxB,oBAAoB,4CA0CtB,CAAC"}
1
+ {"version":3,"file":"Pagination.d.ts","sourceRoot":"","sources":["../../src/Pagination/Pagination.tsx"],"names":[],"mappings":"AACA,OAAwB,EACtB,KAAK,oBAAoB,EAC1B,MAAM,+BAA+B,CAAC;AAIvC,eAAO,MAAM,UAAU,GAAI,8EAQxB,oBAAoB,4CA2CtB,CAAC"}
@@ -8,7 +8,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const styles_1 = require("@mui/material/styles");
9
9
  const TablePagination_1 = __importDefault(require("@mui/material/TablePagination"));
10
10
  const utils_1 = require("../utils");
11
- const Pagination = ({ count, page, onPageChange, rowsPerPage, onRowsPerPageChange, ...rest }) => {
11
+ const Pagination = ({ count, page, onPageChange, rowsPerPage, onRowsPerPageChange, sx, ...rest }) => {
12
12
  const theme = (0, styles_1.useTheme)();
13
13
  const { grey } = theme.palette;
14
14
  const { layout } = (0, utils_1.useGetDeviceType)();
@@ -30,6 +30,7 @@ const Pagination = ({ count, page, onPageChange, rowsPerPage, onRowsPerPageChang
30
30
  fontSize: "13px",
31
31
  padding: isMobile ? "2px 10px" : "4px 8px",
32
32
  },
33
+ ...sx,
33
34
  }, component: "div", count: count, page: page, onPageChange: onPageChange, rowsPerPage: rowsPerPage, onRowsPerPageChange: onRowsPerPageChange, rowsPerPageOptions: rowsPerPageOptions, defaultValue: 100, labelRowsPerPage: !isMobile ? "Rows per page" : "", ...rest }));
34
35
  };
35
36
  exports.Pagination = Pagination;