@tecsinapse/cortex-react 1.3.2 → 1.3.4

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.
Files changed (58) hide show
  1. package/dist/cjs/components/Calendar/Calendar.js +1 -0
  2. package/dist/cjs/components/Calendar/CalendarCell.js +1 -0
  3. package/dist/cjs/components/Calendar/CalendarGrid.js +1 -0
  4. package/dist/cjs/components/Calendar/RangeCalendar.js +1 -0
  5. package/dist/cjs/components/DatePicker/Content.js +1 -0
  6. package/dist/cjs/components/DatePicker/DatePickerInput.js +1 -0
  7. package/dist/cjs/components/DatePicker/DateRangePickerInput.js +1 -0
  8. package/dist/cjs/components/Input/Mask.js +51 -23
  9. package/dist/cjs/components/Input/Search.js +1 -0
  10. package/dist/cjs/components/Input/masks.js +35 -2
  11. package/dist/cjs/components/Kanban.js +35 -0
  12. package/dist/cjs/components/Menubar/MostUsedList.js +1 -0
  13. package/dist/cjs/components/Popover/Provider.js +1 -0
  14. package/dist/cjs/components/Select/Content.js +1 -0
  15. package/dist/cjs/components/Select/GroupedOptions.js +1 -0
  16. package/dist/cjs/components/Select/MultiGroupedOptions.js +1 -0
  17. package/dist/cjs/components/Select/MultiOptions.js +1 -0
  18. package/dist/cjs/components/Select/Options.js +1 -0
  19. package/dist/cjs/components/Tooltip.js +1 -0
  20. package/dist/cjs/hooks/useNumberMask.js +76 -0
  21. package/dist/cjs/hooks/useStringMask.js +93 -0
  22. package/dist/cjs/index.js +12 -0
  23. package/dist/cjs/service/SnackbarSonner.js +1 -0
  24. package/dist/cjs/utils/extractNumbersFromString.js +7 -0
  25. package/dist/esm/components/Calendar/Calendar.js +1 -0
  26. package/dist/esm/components/Calendar/CalendarCell.js +1 -0
  27. package/dist/esm/components/Calendar/CalendarGrid.js +1 -0
  28. package/dist/esm/components/Calendar/RangeCalendar.js +1 -0
  29. package/dist/esm/components/DatePicker/Content.js +1 -0
  30. package/dist/esm/components/DatePicker/DatePickerInput.js +1 -0
  31. package/dist/esm/components/DatePicker/DateRangePickerInput.js +1 -0
  32. package/dist/esm/components/Input/Mask.js +52 -24
  33. package/dist/esm/components/Input/Search.js +1 -0
  34. package/dist/esm/components/Input/masks.js +33 -3
  35. package/dist/esm/components/Kanban.js +33 -0
  36. package/dist/esm/components/Menubar/MostUsedList.js +1 -0
  37. package/dist/esm/components/Popover/Provider.js +1 -0
  38. package/dist/esm/components/Select/Content.js +1 -0
  39. package/dist/esm/components/Select/GroupedOptions.js +1 -0
  40. package/dist/esm/components/Select/MultiGroupedOptions.js +1 -0
  41. package/dist/esm/components/Select/MultiOptions.js +1 -0
  42. package/dist/esm/components/Select/Options.js +1 -0
  43. package/dist/esm/components/Tooltip.js +1 -0
  44. package/dist/esm/hooks/useNumberMask.js +73 -0
  45. package/dist/esm/hooks/useStringMask.js +89 -0
  46. package/dist/esm/index.js +4 -1
  47. package/dist/esm/service/SnackbarSonner.js +1 -0
  48. package/dist/esm/utils/extractNumbersFromString.js +4 -0
  49. package/dist/types/components/Input/masks.d.ts +24 -0
  50. package/dist/types/components/Input/types.d.ts +9 -9
  51. package/dist/types/components/Kanban.d.ts +1 -2
  52. package/dist/types/components/index.d.ts +1 -0
  53. package/dist/types/hooks/index.d.ts +2 -0
  54. package/dist/types/hooks/useNumberMask.d.ts +8 -0
  55. package/dist/types/hooks/useStringMask.d.ts +4 -0
  56. package/dist/types/utils/extractNumbersFromString.d.ts +2 -0
  57. package/dist/types/utils/index.d.ts +1 -0
  58. package/package.json +3 -3
@@ -6,6 +6,7 @@ require('@internationalized/date');
6
6
  require('react-aria');
7
7
  require('react-stately');
8
8
  require('@floating-ui/react');
9
+ require('currency.js');
9
10
  var CalendarGrid = require('./CalendarGrid.js');
10
11
  var CalendarHeader = require('./CalendarHeader.js');
11
12
 
@@ -6,6 +6,7 @@ require('react-aria');
6
6
  require('react-stately');
7
7
  var useCalendarCell = require('../../hooks/useCalendarCell.js');
8
8
  require('@floating-ui/react');
9
+ require('currency.js');
9
10
  var calendarCell = require('../../styles/calendar-cell.js');
10
11
  require('../../styles/groupButton.js');
11
12
  require('../../styles/progressBar.js');
@@ -6,6 +6,7 @@ require('react-aria');
6
6
  require('react-stately');
7
7
  var useCalendarGrid = require('../../hooks/useCalendarGrid.js');
8
8
  require('@floating-ui/react');
9
+ require('currency.js');
9
10
  var CalendarGridBodyRows = require('./CalendarGridBodyRows.js');
10
11
  var CalendarGridHeaderRow = require('./CalendarGridHeaderRow.js');
11
12
 
@@ -5,6 +5,7 @@ require('@internationalized/date');
5
5
  require('react-aria');
6
6
  require('react-stately');
7
7
  require('@floating-ui/react');
8
+ require('currency.js');
8
9
  var useRangeCalendar = require('../../hooks/useRangeCalendar.js');
9
10
  var CalendarGrid = require('./CalendarGrid.js');
10
11
  var CalendarHeader = require('./CalendarHeader.js');
@@ -5,6 +5,7 @@ require('@internationalized/date');
5
5
  require('react-aria');
6
6
  require('react-stately');
7
7
  require('@floating-ui/react');
8
+ require('currency.js');
8
9
  var useOutsideClickListener = require('../../hooks/useOutsideClickListener.js');
9
10
  var Context = require('../Popover/Context.js');
10
11
 
@@ -7,6 +7,7 @@ require('react-stately');
7
7
  var utils = require('../utils.js');
8
8
  var useDatePickerInput = require('../../hooks/useDatePickerInput.js');
9
9
  require('@floating-ui/react');
10
+ require('currency.js');
10
11
  var Calendar = require('../Calendar/Calendar.js');
11
12
  var DateField = require('./DateField.js');
12
13
  var DatePickerInputBase = require('./DatePickerInputBase.js');
@@ -7,6 +7,7 @@ require('react-stately');
7
7
  var utils = require('../utils.js');
8
8
  var useDateRangePickerInput = require('../../hooks/useDateRangePickerInput.js');
9
9
  require('@floating-ui/react');
10
+ require('currency.js');
10
11
  var RangeCalendar = require('../Calendar/RangeCalendar.js');
11
12
  var DateField = require('./DateField.js');
12
13
  var DatePickerInputBase = require('./DatePickerInputBase.js');
@@ -1,32 +1,60 @@
1
1
  'use strict';
2
2
 
3
3
  var React = require('react');
4
- var reactImask = require('react-imask');
4
+ require('@internationalized/date');
5
+ require('react-aria');
6
+ require('react-stately');
7
+ require('@floating-ui/react');
8
+ var useNumberMask = require('../../hooks/useNumberMask.js');
9
+ var useStringMask = require('../../hooks/useStringMask.js');
5
10
  var Root = require('./Root.js');
6
11
 
7
- const useIMaskLocal = (mask, inputProps, ref, onChangeMask) => {
8
- const { ref: iMaskRef, maskRef } = reactImask.useIMask(mask, {
9
- onAccept: (value, mask2) => {
10
- onChangeMask?.({
11
- unmaskedValue: mask2._unmaskedValue,
12
- value
13
- });
14
- },
15
- ref: ref ? ref : React.createRef()
16
- });
17
- React.useEffect(() => {
18
- if (inputProps.value === "") {
19
- maskRef.current?.updateValue();
20
- }
21
- }, [maskRef, inputProps.value]);
22
- return {
23
- iMaskRef
24
- };
25
- };
26
12
  const InputMask = React.forwardRef(
27
- ({ mask, onChange, ...rest }, ref) => {
28
- const { iMaskRef } = useIMaskLocal(mask, rest, ref, onChange);
29
- return /* @__PURE__ */ React.createElement(Root.InputRoot, { ...rest, ref: iMaskRef });
13
+ ({ mask, onChange, value, ...rest }, ref) => {
14
+ const getInputHook = (value2) => {
15
+ if (mask !== void 0) {
16
+ if (Array.isArray(mask) || typeof mask === "function") {
17
+ return useStringMask.useStringMask(mask, value2);
18
+ } else {
19
+ return useNumberMask.useNumberMask(mask, value2);
20
+ }
21
+ } else {
22
+ return [void 0, void 0];
23
+ }
24
+ };
25
+ const [maskValue, setMaskValue] = getInputHook(value ?? "");
26
+ const _value = maskValue === void 0 ? value?.toString() : maskValue.formatted ? maskValue.formatted : "";
27
+ React.useEffect(() => {
28
+ if (onChange) {
29
+ onChange(maskValue?.raw);
30
+ }
31
+ }, [maskValue]);
32
+ const onChangeValue = React.useCallback(
33
+ (value2) => {
34
+ if (maskValue !== void 0 && setMaskValue !== void 0) {
35
+ setMaskValue(value2);
36
+ } else onChange?.(value2);
37
+ },
38
+ [value]
39
+ );
40
+ React.useEffect(() => {
41
+ if (maskValue !== void 0 && setMaskValue !== void 0 && value !== void 0 && typeof maskValue === "object") {
42
+ if (maskValue.raw !== void 0 && maskValue.raw.toString() !== value.toString()) {
43
+ onChangeValue(value);
44
+ }
45
+ } else if (maskValue === void 0 && value !== void 0) {
46
+ onChangeValue(value);
47
+ }
48
+ }, [value]);
49
+ return /* @__PURE__ */ React.createElement(
50
+ Root.InputRoot,
51
+ {
52
+ ...rest,
53
+ value: _value,
54
+ onChange: (e) => onChangeValue(e.target.value),
55
+ ref
56
+ }
57
+ );
30
58
  }
31
59
  );
32
60
 
@@ -7,6 +7,7 @@ require('react-aria');
7
7
  require('react-stately');
8
8
  var useDebouncedState = require('../../hooks/useDebouncedState.js');
9
9
  require('@floating-ui/react');
10
+ require('currency.js');
10
11
  var Box = require('./Box.js');
11
12
  var Face = require('./Face.js');
12
13
  var Left = require('./Left.js');
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var extractNumbersFromString = require('../../utils/extractNumbersFromString.js');
4
+
3
5
  const ExpressionMasks = {
4
6
  CPF: "000.000.000-00",
5
7
  CNPJ: "00.000.000/0000-00",
@@ -16,7 +18,7 @@ const CurrencyIMask = {
16
18
  mask: Number,
17
19
  scale: 2,
18
20
  thousandsSeparator: ".",
19
- padFractionalZeros: true,
21
+ padFractionalZeros: false,
20
22
  radix: ",",
21
23
  mapToRadix: ["."]
22
24
  }
@@ -30,14 +32,45 @@ const PercentageIMask = {
30
32
  mask: Number,
31
33
  scale: 2,
32
34
  thousandsSeparator: ".",
33
- padFractionalZeros: true,
35
+ padFractionalZeros: false,
34
36
  radix: ",",
35
37
  mapToRadix: ["."]
36
38
  }
37
39
  }
38
40
  };
41
+ const Masks = {
42
+ CPF: ["999.999.999-99"],
43
+ CNPJ: ["99.999.999/9999-99"],
44
+ DATE: ["99/99/9999"],
45
+ HOUR: ["99:99"],
46
+ MONTH_YEAR: ["99/9999"],
47
+ CEP: ["99999-999"],
48
+ PHONE: ["(99) 9999-9999"],
49
+ PHONE_EXTENDED: ["(99) 99999-9999"],
50
+ COMBINED_PHONE: (value) => {
51
+ const onlyNumbers = extractNumbersFromString.extractDigitsFromString(value);
52
+ const isCellPhoneExtended = onlyNumbers.length === 11;
53
+ return value?.length <= 14 && !isCellPhoneExtended ? Masks.PHONE : Masks.PHONE_EXTENDED;
54
+ },
55
+ COMBINED_CPF_CNPJ: (value) => value?.length <= 14 ? Masks.CPF : Masks.CNPJ
56
+ };
57
+ const BRLMask = {
58
+ symbol: "R$ ",
59
+ separator: ".",
60
+ decimal: ",",
61
+ precision: 2
62
+ };
63
+ const PercentageMask = {
64
+ symbol: "",
65
+ separator: ".",
66
+ decimal: ",",
67
+ precision: 2
68
+ };
39
69
 
70
+ exports.BRLMask = BRLMask;
40
71
  exports.CurrencyIMask = CurrencyIMask;
41
72
  exports.ExpressionMasks = ExpressionMasks;
73
+ exports.Masks = Masks;
42
74
  exports.NumberIMask = NumberIMask;
43
75
  exports.PercentageIMask = PercentageIMask;
76
+ exports.PercentageMask = PercentageMask;
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ var clsx = require('clsx');
4
+ var React = require('react');
5
+
6
+ const Root = ({ children, className, ...rest }) => {
7
+ return /* @__PURE__ */ React.createElement(
8
+ "div",
9
+ {
10
+ ...rest,
11
+ className: clsx.clsx(
12
+ "border border-dashed border-secondary-medium rounded-mili bg-secondary-xlight overflow-hidden",
13
+ className
14
+ )
15
+ },
16
+ children
17
+ );
18
+ };
19
+ const Header = ({ children, className, ...rest }) => {
20
+ return /* @__PURE__ */ React.createElement("div", { ...rest, className: clsx.clsx("p-deca", className) }, children);
21
+ };
22
+ const Body = ({ children, className, ...rest }) => {
23
+ return /* @__PURE__ */ React.createElement("div", { ...rest, className: clsx.clsx("overflow-y-scroll", className) }, children);
24
+ };
25
+ const ContainerList = ({ children, className, ...rest }) => {
26
+ return /* @__PURE__ */ React.createElement("div", { ...rest, className: clsx.clsx("px-deca", className) }, children);
27
+ };
28
+ const Kanban = {
29
+ Root,
30
+ Header,
31
+ Body,
32
+ ContainerList
33
+ };
34
+
35
+ exports.Kanban = Kanban;
@@ -10,6 +10,7 @@ require('../Button.js');
10
10
  require('react-aria');
11
11
  require('react-stately');
12
12
  require('@floating-ui/react');
13
+ require('currency.js');
13
14
  require('../Calendar/CalendarCell.js');
14
15
  require('@tecsinapse/cortex-core');
15
16
  require('react-icons/fa');
@@ -5,6 +5,7 @@ require('@internationalized/date');
5
5
  require('react-aria');
6
6
  require('react-stately');
7
7
  var useFloatingLogic = require('../../hooks/useFloatingLogic.js');
8
+ require('currency.js');
8
9
  var Context = require('./Context.js');
9
10
 
10
11
  const PopoverProvider = ({
@@ -5,6 +5,7 @@ require('@internationalized/date');
5
5
  require('react-aria');
6
6
  require('react-stately');
7
7
  require('@floating-ui/react');
8
+ require('currency.js');
8
9
  var useOutsideClickListener = require('../../hooks/useOutsideClickListener.js');
9
10
  var Context = require('../Popover/Context.js');
10
11
 
@@ -6,6 +6,7 @@ require('@internationalized/date');
6
6
  require('react-aria');
7
7
  require('react-stately');
8
8
  require('@floating-ui/react');
9
+ require('currency.js');
9
10
  var useSelectGroupedOptions = require('../../hooks/useSelectGroupedOptions.js');
10
11
  var Context = require('../Popover/Context.js');
11
12
  var Option = require('./Option.js');
@@ -6,6 +6,7 @@ require('@internationalized/date');
6
6
  require('react-aria');
7
7
  require('react-stately');
8
8
  require('@floating-ui/react');
9
+ require('currency.js');
9
10
  var useSelectGroupedOptions = require('../../hooks/useSelectGroupedOptions.js');
10
11
  var MultiOption = require('./MultiOption.js');
11
12
  var SkeletonOptions = require('./SkeletonOptions.js');
@@ -6,6 +6,7 @@ require('@internationalized/date');
6
6
  require('react-aria');
7
7
  require('react-stately');
8
8
  require('@floating-ui/react');
9
+ require('currency.js');
9
10
  var useSelectOptions = require('../../hooks/useSelectOptions.js');
10
11
  var MultiOption = require('./MultiOption.js');
11
12
  var SkeletonOptions = require('./SkeletonOptions.js');
@@ -6,6 +6,7 @@ require('@internationalized/date');
6
6
  require('react-aria');
7
7
  require('react-stately');
8
8
  require('@floating-ui/react');
9
+ require('currency.js');
9
10
  var useSelectOptions = require('../../hooks/useSelectOptions.js');
10
11
  var Context = require('../Popover/Context.js');
11
12
  var Option = require('./Option.js');
@@ -9,6 +9,7 @@ require('react-aria');
9
9
  require('react-stately');
10
10
  var utils = require('./utils.js');
11
11
  var useFloatingLogic = require('../hooks/useFloatingLogic.js');
12
+ require('currency.js');
12
13
 
13
14
  const Tooltip = React.forwardRef(
14
15
  (props, ref) => {
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ var currency = require('currency.js');
4
+ var React = require('react');
5
+ var extractNumbersFromString = require('../utils/extractNumbersFromString.js');
6
+
7
+ const DEFAULT_OPTIONS = {
8
+ symbol: "R$ ",
9
+ separator: ".",
10
+ decimal: ",",
11
+ precision: 2
12
+ };
13
+ const getRegex = (precision) => new RegExp(`\\B(?=(\\d{${precision}})(?!\\d))`, "g");
14
+ const getInternalNumberAndMask = (value, options) => {
15
+ const mergedOptions = { ...DEFAULT_OPTIONS, ...options };
16
+ const { precision = -1 } = mergedOptions;
17
+ let internalNumber;
18
+ if (typeof value === "number") {
19
+ if (precision) {
20
+ let stringValue = String(value);
21
+ const decimalIndex = stringValue.indexOf(".");
22
+ const currentPrecision = decimalIndex + precision;
23
+ if (decimalIndex !== -1 && currentPrecision <= stringValue.length) {
24
+ const zeros = stringValue.length + 1 - currentPrecision;
25
+ for (let i = 0; i < zeros; i++) stringValue = stringValue + `0`;
26
+ }
27
+ internalNumber = Number(stringValue);
28
+ } else {
29
+ internalNumber = value;
30
+ }
31
+ } else {
32
+ const onlyNumbers = String(extractNumbersFromString.extractNumbersFromString(value));
33
+ const padZeros = String(onlyNumbers).padStart(precision + 1, "0");
34
+ internalNumber = Number(padZeros.replace(getRegex(precision), "."));
35
+ }
36
+ if (internalNumber > Number.MAX_SAFE_INTEGER) {
37
+ internalNumber = Number.MAX_SAFE_INTEGER;
38
+ }
39
+ if (internalNumber < Number.MIN_SAFE_INTEGER) {
40
+ internalNumber = Number.MIN_SAFE_INTEGER;
41
+ }
42
+ return {
43
+ internalNumber,
44
+ mergedOptions
45
+ };
46
+ };
47
+ const useNumberMask = (options, defaultValue) => {
48
+ const applyMask = React.useCallback(
49
+ (value2 = 0) => {
50
+ const { internalNumber, mergedOptions } = getInternalNumberAndMask(
51
+ value2,
52
+ options
53
+ );
54
+ return {
55
+ raw: internalNumber,
56
+ formatted: currency(internalNumber).format(mergedOptions)
57
+ };
58
+ },
59
+ [options, getRegex]
60
+ );
61
+ const [value, setValue] = React.useState(applyMask(defaultValue));
62
+ const handleChangeValue = React.useCallback(
63
+ (formattedValue) => {
64
+ const { raw, formatted } = applyMask(formattedValue);
65
+ setValue({
66
+ raw,
67
+ formatted
68
+ });
69
+ },
70
+ [applyMask, setValue]
71
+ );
72
+ return [value, handleChangeValue];
73
+ };
74
+
75
+ exports.getInternalNumberAndMask = getInternalNumberAndMask;
76
+ exports.useNumberMask = useNumberMask;
@@ -0,0 +1,93 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+
5
+ const mergeMask = (value = "", mask) => {
6
+ let formatted = "";
7
+ let raw = "";
8
+ let iMask = 0;
9
+ let iChars = 0;
10
+ while (!(iMask === mask.length || iChars === value.length)) {
11
+ const maskChar = mask[iMask];
12
+ const valueChar = value[iChars];
13
+ if (maskChar === valueChar) {
14
+ formatted += maskChar;
15
+ iChars++;
16
+ iMask++;
17
+ continue;
18
+ }
19
+ const rawValueChar = value[iChars];
20
+ if (typeof maskChar === "object") {
21
+ iChars++;
22
+ const maskCharRegex = Array.isArray(maskChar) ? maskChar[0] : maskChar;
23
+ const matchRegex = RegExp(maskCharRegex).test(valueChar);
24
+ if (matchRegex) {
25
+ formatted += valueChar;
26
+ raw += rawValueChar;
27
+ iMask++;
28
+ }
29
+ } else {
30
+ formatted += maskChar;
31
+ iMask++;
32
+ }
33
+ }
34
+ return { raw, formatted };
35
+ };
36
+ const getMask = (mask, newValue) => {
37
+ let maskArray;
38
+ const regexArray = [];
39
+ if (typeof mask === "function") {
40
+ maskArray = mask(newValue);
41
+ } else {
42
+ maskArray = mask;
43
+ }
44
+ maskArray.forEach((exp) => {
45
+ if (typeof exp !== "string") {
46
+ if (Array.isArray(exp)) regexArray.push(exp);
47
+ else regexArray.push(exp);
48
+ } else {
49
+ for (let i = 0; i < exp.length; i++) {
50
+ if (exp[i] === "\\") {
51
+ regexArray.push(exp[i + 1]);
52
+ i++;
53
+ } else {
54
+ if (exp[i] === "9") regexArray.push(/\d/);
55
+ else if (exp[i] === "a") regexArray.push(/[a-zA-Z]/);
56
+ else regexArray.push(exp[i]);
57
+ }
58
+ }
59
+ }
60
+ });
61
+ return regexArray;
62
+ };
63
+ const useStringMask = (mask, defaultValue) => {
64
+ const applyMask = React.useCallback(
65
+ (value2 = "") => {
66
+ const selectedMask = getMask(mask, value2);
67
+ const { formatted, raw } = mergeMask(value2, selectedMask);
68
+ return {
69
+ raw,
70
+ formatted
71
+ };
72
+ },
73
+ [mask]
74
+ );
75
+ const [value, setValue] = React.useState(
76
+ applyMask(defaultValue?.toString())
77
+ );
78
+ const handleChangeValue = React.useCallback(
79
+ (formattedValue) => {
80
+ const { raw, formatted } = applyMask(formattedValue?.toString());
81
+ setValue({
82
+ raw,
83
+ formatted
84
+ });
85
+ },
86
+ [applyMask, setValue]
87
+ );
88
+ return [value, handleChangeValue];
89
+ };
90
+
91
+ exports.getMask = getMask;
92
+ exports.mergeMask = mergeMask;
93
+ exports.useStringMask = useStringMask;
package/dist/cjs/index.js CHANGED
@@ -34,6 +34,7 @@ var TimeField = require('./components/TimeField/TimeField.js');
34
34
  var TimeFieldInput = require('./components/TimeField/TimeFieldInput.js');
35
35
  var Toggle = require('./components/Toggle.js');
36
36
  var Tooltip = require('./components/Tooltip.js');
37
+ var Kanban = require('./components/Kanban.js');
37
38
  var useCalendar = require('./hooks/useCalendar.js');
38
39
  var useCalendarCell = require('./hooks/useCalendarCell.js');
39
40
  var useCalendarGrid = require('./hooks/useCalendarGrid.js');
@@ -41,10 +42,12 @@ var useDatePickerInput = require('./hooks/useDatePickerInput.js');
41
42
  var useDateRangePickerInput = require('./hooks/useDateRangePickerInput.js');
42
43
  var useDebouncedState = require('./hooks/useDebouncedState.js');
43
44
  var useFloatingLogic = require('./hooks/useFloatingLogic.js');
45
+ var useNumberMask = require('./hooks/useNumberMask.js');
44
46
  var useOutsideClickListener = require('./hooks/useOutsideClickListener.js');
45
47
  var useRangeCalendar = require('./hooks/useRangeCalendar.js');
46
48
  var useSelectGroupedOptions = require('./hooks/useSelectGroupedOptions.js');
47
49
  var useSelectOptions = require('./hooks/useSelectOptions.js');
50
+ var useStringMask = require('./hooks/useStringMask.js');
48
51
  var SnackbarSonner = require('./service/SnackbarSonner.js');
49
52
  var MenubarProvider = require('./provider/MenubarProvider.js');
50
53
  var SnackbarProvider = require('./provider/SnackbarProvider.js');
@@ -94,6 +97,7 @@ exports.TimeField = TimeField.TimeField;
94
97
  exports.TimeFieldInput = TimeFieldInput.TimeFieldInput;
95
98
  exports.Toggle = Toggle.Toggle;
96
99
  exports.Tooltip = Tooltip.Tooltip;
100
+ exports.Kanban = Kanban.Kanban;
97
101
  exports.useCalendar = useCalendar.useCalendar;
98
102
  exports.useCalendarCell = useCalendarCell.useCalendarCell;
99
103
  exports.useCalendarGrid = useCalendarGrid.useCalendarGrid;
@@ -101,16 +105,24 @@ exports.useDatePickerInput = useDatePickerInput.useDatePickerInput;
101
105
  exports.useDateRangePickerInput = useDateRangePickerInput.useDateRangePickerInput;
102
106
  exports.useDebouncedState = useDebouncedState.useDebouncedState;
103
107
  exports.useFloatingLogic = useFloatingLogic.useFloatingLogic;
108
+ exports.getInternalNumberAndMask = useNumberMask.getInternalNumberAndMask;
109
+ exports.useNumberMask = useNumberMask.useNumberMask;
104
110
  exports.useOutsideClickListener = useOutsideClickListener.useOutsideClickListener;
105
111
  exports.useRangeCalendar = useRangeCalendar.useRangeCalendar;
106
112
  exports.useSelectGroupedOptions = useSelectGroupedOptions.useSelectGroupedOptions;
107
113
  exports.useSelectOptions = useSelectOptions.useSelectOptions;
114
+ exports.getMask = useStringMask.getMask;
115
+ exports.mergeMask = useStringMask.mergeMask;
116
+ exports.useStringMask = useStringMask.useStringMask;
108
117
  exports.SnackbarSonner = SnackbarSonner.SnackbarSonner;
109
118
  exports.MenubarProvider = MenubarProvider.MenubarProvider;
110
119
  exports.useMenubar = MenubarProvider.useMenubar;
111
120
  exports.SnackbarProvider = SnackbarProvider.SnackbarProvider;
112
121
  exports.useSnackbar = SnackbarProvider.useSnackbar;
122
+ exports.BRLMask = masks.BRLMask;
113
123
  exports.CurrencyIMask = masks.CurrencyIMask;
114
124
  exports.ExpressionMasks = masks.ExpressionMasks;
125
+ exports.Masks = masks.Masks;
115
126
  exports.NumberIMask = masks.NumberIMask;
116
127
  exports.PercentageIMask = masks.PercentageIMask;
128
+ exports.PercentageMask = masks.PercentageMask;
@@ -11,6 +11,7 @@ require('../components/Button.js');
11
11
  require('react-aria');
12
12
  require('react-stately');
13
13
  require('@floating-ui/react');
14
+ require('currency.js');
14
15
  require('../components/Calendar/CalendarCell.js');
15
16
  require('@tecsinapse/cortex-core');
16
17
  require('react-icons/fa');
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ const extractNumbersFromString = (value) => Number(extractDigitsFromString(value));
4
+ const extractDigitsFromString = (value) => value.replace(/[^0-9]/g, "");
5
+
6
+ exports.extractDigitsFromString = extractDigitsFromString;
7
+ exports.extractNumbersFromString = extractNumbersFromString;
@@ -4,6 +4,7 @@ import '@internationalized/date';
4
4
  import 'react-aria';
5
5
  import 'react-stately';
6
6
  import '@floating-ui/react';
7
+ import 'currency.js';
7
8
  import { CalendarGrid } from './CalendarGrid.js';
8
9
  import { CalendarHeader } from './CalendarHeader.js';
9
10
 
@@ -4,6 +4,7 @@ import 'react-aria';
4
4
  import 'react-stately';
5
5
  import { useCalendarCell } from '../../hooks/useCalendarCell.js';
6
6
  import '@floating-ui/react';
7
+ import 'currency.js';
7
8
  import { calendarCell } from '../../styles/calendar-cell.js';
8
9
  import '../../styles/groupButton.js';
9
10
  import '../../styles/progressBar.js';
@@ -4,6 +4,7 @@ import 'react-aria';
4
4
  import 'react-stately';
5
5
  import { useCalendarGrid } from '../../hooks/useCalendarGrid.js';
6
6
  import '@floating-ui/react';
7
+ import 'currency.js';
7
8
  import { CalendarGridBodyRows } from './CalendarGridBodyRows.js';
8
9
  import { CalendarGridHeaderRow } from './CalendarGridHeaderRow.js';
9
10
 
@@ -3,6 +3,7 @@ import '@internationalized/date';
3
3
  import 'react-aria';
4
4
  import 'react-stately';
5
5
  import '@floating-ui/react';
6
+ import 'currency.js';
6
7
  import { useRangeCalendar } from '../../hooks/useRangeCalendar.js';
7
8
  import { CalendarGrid } from './CalendarGrid.js';
8
9
  import { CalendarHeader } from './CalendarHeader.js';
@@ -3,6 +3,7 @@ import '@internationalized/date';
3
3
  import 'react-aria';
4
4
  import 'react-stately';
5
5
  import '@floating-ui/react';
6
+ import 'currency.js';
6
7
  import { useOutsideClickListener } from '../../hooks/useOutsideClickListener.js';
7
8
  import { usePopoverContext } from '../Popover/Context.js';
8
9
 
@@ -5,6 +5,7 @@ import 'react-stately';
5
5
  import { dateToCalendarDate } from '../utils.js';
6
6
  import { useDatePickerInput } from '../../hooks/useDatePickerInput.js';
7
7
  import '@floating-ui/react';
8
+ import 'currency.js';
8
9
  import { Calendar } from '../Calendar/Calendar.js';
9
10
  import { DateField } from './DateField.js';
10
11
  import { DatePickerInputBase } from './DatePickerInputBase.js';
@@ -5,6 +5,7 @@ import 'react-stately';
5
5
  import { dateToCalendarDate } from '../utils.js';
6
6
  import { useDateRangePickerInput } from '../../hooks/useDateRangePickerInput.js';
7
7
  import '@floating-ui/react';
8
+ import 'currency.js';
8
9
  import { RangeCalendar } from '../Calendar/RangeCalendar.js';
9
10
  import { DateField } from './DateField.js';
10
11
  import { DatePickerInputBase } from './DatePickerInputBase.js';
@@ -1,30 +1,58 @@
1
- import React__default, { createRef, useEffect } from 'react';
2
- import { useIMask } from 'react-imask';
1
+ import React__default, { useEffect, useCallback } from 'react';
2
+ import '@internationalized/date';
3
+ import 'react-aria';
4
+ import 'react-stately';
5
+ import '@floating-ui/react';
6
+ import { useNumberMask } from '../../hooks/useNumberMask.js';
7
+ import { useStringMask } from '../../hooks/useStringMask.js';
3
8
  import { InputRoot } from './Root.js';
4
9
 
5
- const useIMaskLocal = (mask, inputProps, ref, onChangeMask) => {
6
- const { ref: iMaskRef, maskRef } = useIMask(mask, {
7
- onAccept: (value, mask2) => {
8
- onChangeMask?.({
9
- unmaskedValue: mask2._unmaskedValue,
10
- value
11
- });
12
- },
13
- ref: ref ? ref : createRef()
14
- });
15
- useEffect(() => {
16
- if (inputProps.value === "") {
17
- maskRef.current?.updateValue();
18
- }
19
- }, [maskRef, inputProps.value]);
20
- return {
21
- iMaskRef
22
- };
23
- };
24
10
  const InputMask = React__default.forwardRef(
25
- ({ mask, onChange, ...rest }, ref) => {
26
- const { iMaskRef } = useIMaskLocal(mask, rest, ref, onChange);
27
- return /* @__PURE__ */ React__default.createElement(InputRoot, { ...rest, ref: iMaskRef });
11
+ ({ mask, onChange, value, ...rest }, ref) => {
12
+ const getInputHook = (value2) => {
13
+ if (mask !== void 0) {
14
+ if (Array.isArray(mask) || typeof mask === "function") {
15
+ return useStringMask(mask, value2);
16
+ } else {
17
+ return useNumberMask(mask, value2);
18
+ }
19
+ } else {
20
+ return [void 0, void 0];
21
+ }
22
+ };
23
+ const [maskValue, setMaskValue] = getInputHook(value ?? "");
24
+ const _value = maskValue === void 0 ? value?.toString() : maskValue.formatted ? maskValue.formatted : "";
25
+ useEffect(() => {
26
+ if (onChange) {
27
+ onChange(maskValue?.raw);
28
+ }
29
+ }, [maskValue]);
30
+ const onChangeValue = useCallback(
31
+ (value2) => {
32
+ if (maskValue !== void 0 && setMaskValue !== void 0) {
33
+ setMaskValue(value2);
34
+ } else onChange?.(value2);
35
+ },
36
+ [value]
37
+ );
38
+ useEffect(() => {
39
+ if (maskValue !== void 0 && setMaskValue !== void 0 && value !== void 0 && typeof maskValue === "object") {
40
+ if (maskValue.raw !== void 0 && maskValue.raw.toString() !== value.toString()) {
41
+ onChangeValue(value);
42
+ }
43
+ } else if (maskValue === void 0 && value !== void 0) {
44
+ onChangeValue(value);
45
+ }
46
+ }, [value]);
47
+ return /* @__PURE__ */ React__default.createElement(
48
+ InputRoot,
49
+ {
50
+ ...rest,
51
+ value: _value,
52
+ onChange: (e) => onChangeValue(e.target.value),
53
+ ref
54
+ }
55
+ );
28
56
  }
29
57
  );
30
58
 
@@ -5,6 +5,7 @@ import 'react-aria';
5
5
  import 'react-stately';
6
6
  import { useDebouncedState } from '../../hooks/useDebouncedState.js';
7
7
  import '@floating-ui/react';
8
+ import 'currency.js';
8
9
  import { InputBox } from './Box.js';
9
10
  import { InputFace } from './Face.js';
10
11
  import { InputLeft } from './Left.js';
@@ -1,3 +1,5 @@
1
+ import { extractDigitsFromString } from '../../utils/extractNumbersFromString.js';
2
+
1
3
  const ExpressionMasks = {
2
4
  CPF: "000.000.000-00",
3
5
  CNPJ: "00.000.000/0000-00",
@@ -14,7 +16,7 @@ const CurrencyIMask = {
14
16
  mask: Number,
15
17
  scale: 2,
16
18
  thousandsSeparator: ".",
17
- padFractionalZeros: true,
19
+ padFractionalZeros: false,
18
20
  radix: ",",
19
21
  mapToRadix: ["."]
20
22
  }
@@ -28,11 +30,39 @@ const PercentageIMask = {
28
30
  mask: Number,
29
31
  scale: 2,
30
32
  thousandsSeparator: ".",
31
- padFractionalZeros: true,
33
+ padFractionalZeros: false,
32
34
  radix: ",",
33
35
  mapToRadix: ["."]
34
36
  }
35
37
  }
36
38
  };
39
+ const Masks = {
40
+ CPF: ["999.999.999-99"],
41
+ CNPJ: ["99.999.999/9999-99"],
42
+ DATE: ["99/99/9999"],
43
+ HOUR: ["99:99"],
44
+ MONTH_YEAR: ["99/9999"],
45
+ CEP: ["99999-999"],
46
+ PHONE: ["(99) 9999-9999"],
47
+ PHONE_EXTENDED: ["(99) 99999-9999"],
48
+ COMBINED_PHONE: (value) => {
49
+ const onlyNumbers = extractDigitsFromString(value);
50
+ const isCellPhoneExtended = onlyNumbers.length === 11;
51
+ return value?.length <= 14 && !isCellPhoneExtended ? Masks.PHONE : Masks.PHONE_EXTENDED;
52
+ },
53
+ COMBINED_CPF_CNPJ: (value) => value?.length <= 14 ? Masks.CPF : Masks.CNPJ
54
+ };
55
+ const BRLMask = {
56
+ symbol: "R$ ",
57
+ separator: ".",
58
+ decimal: ",",
59
+ precision: 2
60
+ };
61
+ const PercentageMask = {
62
+ symbol: "",
63
+ separator: ".",
64
+ decimal: ",",
65
+ precision: 2
66
+ };
37
67
 
38
- export { CurrencyIMask, ExpressionMasks, NumberIMask, PercentageIMask };
68
+ export { BRLMask, CurrencyIMask, ExpressionMasks, Masks, NumberIMask, PercentageIMask, PercentageMask };
@@ -0,0 +1,33 @@
1
+ import { clsx } from 'clsx';
2
+ import React__default from 'react';
3
+
4
+ const Root = ({ children, className, ...rest }) => {
5
+ return /* @__PURE__ */ React__default.createElement(
6
+ "div",
7
+ {
8
+ ...rest,
9
+ className: clsx(
10
+ "border border-dashed border-secondary-medium rounded-mili bg-secondary-xlight overflow-hidden",
11
+ className
12
+ )
13
+ },
14
+ children
15
+ );
16
+ };
17
+ const Header = ({ children, className, ...rest }) => {
18
+ return /* @__PURE__ */ React__default.createElement("div", { ...rest, className: clsx("p-deca", className) }, children);
19
+ };
20
+ const Body = ({ children, className, ...rest }) => {
21
+ return /* @__PURE__ */ React__default.createElement("div", { ...rest, className: clsx("overflow-y-scroll", className) }, children);
22
+ };
23
+ const ContainerList = ({ children, className, ...rest }) => {
24
+ return /* @__PURE__ */ React__default.createElement("div", { ...rest, className: clsx("px-deca", className) }, children);
25
+ };
26
+ const Kanban = {
27
+ Root,
28
+ Header,
29
+ Body,
30
+ ContainerList
31
+ };
32
+
33
+ export { Kanban };
@@ -8,6 +8,7 @@ import '../Button.js';
8
8
  import 'react-aria';
9
9
  import 'react-stately';
10
10
  import '@floating-ui/react';
11
+ import 'currency.js';
11
12
  import '../Calendar/CalendarCell.js';
12
13
  import '@tecsinapse/cortex-core';
13
14
  import 'react-icons/fa';
@@ -3,6 +3,7 @@ import '@internationalized/date';
3
3
  import 'react-aria';
4
4
  import 'react-stately';
5
5
  import { useFloatingLogic } from '../../hooks/useFloatingLogic.js';
6
+ import 'currency.js';
6
7
  import { Context } from './Context.js';
7
8
 
8
9
  const PopoverProvider = ({
@@ -3,6 +3,7 @@ import '@internationalized/date';
3
3
  import 'react-aria';
4
4
  import 'react-stately';
5
5
  import '@floating-ui/react';
6
+ import 'currency.js';
6
7
  import { useOutsideClickListener } from '../../hooks/useOutsideClickListener.js';
7
8
  import { usePopoverContext } from '../Popover/Context.js';
8
9
 
@@ -4,6 +4,7 @@ import '@internationalized/date';
4
4
  import 'react-aria';
5
5
  import 'react-stately';
6
6
  import '@floating-ui/react';
7
+ import 'currency.js';
7
8
  import { useSelectGroupedOptions } from '../../hooks/useSelectGroupedOptions.js';
8
9
  import { usePopoverContext } from '../Popover/Context.js';
9
10
  import { SelectOption } from './Option.js';
@@ -4,6 +4,7 @@ import '@internationalized/date';
4
4
  import 'react-aria';
5
5
  import 'react-stately';
6
6
  import '@floating-ui/react';
7
+ import 'currency.js';
7
8
  import { useSelectGroupedOptions } from '../../hooks/useSelectGroupedOptions.js';
8
9
  import { SelectMultiOption } from './MultiOption.js';
9
10
  import { SkeletonOptions } from './SkeletonOptions.js';
@@ -4,6 +4,7 @@ import '@internationalized/date';
4
4
  import 'react-aria';
5
5
  import 'react-stately';
6
6
  import '@floating-ui/react';
7
+ import 'currency.js';
7
8
  import { useSelectOptions } from '../../hooks/useSelectOptions.js';
8
9
  import { SelectMultiOption } from './MultiOption.js';
9
10
  import { SkeletonOptions } from './SkeletonOptions.js';
@@ -4,6 +4,7 @@ import '@internationalized/date';
4
4
  import 'react-aria';
5
5
  import 'react-stately';
6
6
  import '@floating-ui/react';
7
+ import 'currency.js';
7
8
  import { useSelectOptions } from '../../hooks/useSelectOptions.js';
8
9
  import { usePopoverContext } from '../Popover/Context.js';
9
10
  import { SelectOption } from './Option.js';
@@ -5,6 +5,7 @@ import 'react-aria';
5
5
  import 'react-stately';
6
6
  import { cloneWithProps } from './utils.js';
7
7
  import { useFloatingLogic } from '../hooks/useFloatingLogic.js';
8
+ import 'currency.js';
8
9
 
9
10
  const Tooltip = forwardRef(
10
11
  (props, ref) => {
@@ -0,0 +1,73 @@
1
+ import currency from 'currency.js';
2
+ import { useCallback, useState } from 'react';
3
+ import { extractNumbersFromString } from '../utils/extractNumbersFromString.js';
4
+
5
+ const DEFAULT_OPTIONS = {
6
+ symbol: "R$ ",
7
+ separator: ".",
8
+ decimal: ",",
9
+ precision: 2
10
+ };
11
+ const getRegex = (precision) => new RegExp(`\\B(?=(\\d{${precision}})(?!\\d))`, "g");
12
+ const getInternalNumberAndMask = (value, options) => {
13
+ const mergedOptions = { ...DEFAULT_OPTIONS, ...options };
14
+ const { precision = -1 } = mergedOptions;
15
+ let internalNumber;
16
+ if (typeof value === "number") {
17
+ if (precision) {
18
+ let stringValue = String(value);
19
+ const decimalIndex = stringValue.indexOf(".");
20
+ const currentPrecision = decimalIndex + precision;
21
+ if (decimalIndex !== -1 && currentPrecision <= stringValue.length) {
22
+ const zeros = stringValue.length + 1 - currentPrecision;
23
+ for (let i = 0; i < zeros; i++) stringValue = stringValue + `0`;
24
+ }
25
+ internalNumber = Number(stringValue);
26
+ } else {
27
+ internalNumber = value;
28
+ }
29
+ } else {
30
+ const onlyNumbers = String(extractNumbersFromString(value));
31
+ const padZeros = String(onlyNumbers).padStart(precision + 1, "0");
32
+ internalNumber = Number(padZeros.replace(getRegex(precision), "."));
33
+ }
34
+ if (internalNumber > Number.MAX_SAFE_INTEGER) {
35
+ internalNumber = Number.MAX_SAFE_INTEGER;
36
+ }
37
+ if (internalNumber < Number.MIN_SAFE_INTEGER) {
38
+ internalNumber = Number.MIN_SAFE_INTEGER;
39
+ }
40
+ return {
41
+ internalNumber,
42
+ mergedOptions
43
+ };
44
+ };
45
+ const useNumberMask = (options, defaultValue) => {
46
+ const applyMask = useCallback(
47
+ (value2 = 0) => {
48
+ const { internalNumber, mergedOptions } = getInternalNumberAndMask(
49
+ value2,
50
+ options
51
+ );
52
+ return {
53
+ raw: internalNumber,
54
+ formatted: currency(internalNumber).format(mergedOptions)
55
+ };
56
+ },
57
+ [options, getRegex]
58
+ );
59
+ const [value, setValue] = useState(applyMask(defaultValue));
60
+ const handleChangeValue = useCallback(
61
+ (formattedValue) => {
62
+ const { raw, formatted } = applyMask(formattedValue);
63
+ setValue({
64
+ raw,
65
+ formatted
66
+ });
67
+ },
68
+ [applyMask, setValue]
69
+ );
70
+ return [value, handleChangeValue];
71
+ };
72
+
73
+ export { getInternalNumberAndMask, useNumberMask };
@@ -0,0 +1,89 @@
1
+ import { useCallback, useState } from 'react';
2
+
3
+ const mergeMask = (value = "", mask) => {
4
+ let formatted = "";
5
+ let raw = "";
6
+ let iMask = 0;
7
+ let iChars = 0;
8
+ while (!(iMask === mask.length || iChars === value.length)) {
9
+ const maskChar = mask[iMask];
10
+ const valueChar = value[iChars];
11
+ if (maskChar === valueChar) {
12
+ formatted += maskChar;
13
+ iChars++;
14
+ iMask++;
15
+ continue;
16
+ }
17
+ const rawValueChar = value[iChars];
18
+ if (typeof maskChar === "object") {
19
+ iChars++;
20
+ const maskCharRegex = Array.isArray(maskChar) ? maskChar[0] : maskChar;
21
+ const matchRegex = RegExp(maskCharRegex).test(valueChar);
22
+ if (matchRegex) {
23
+ formatted += valueChar;
24
+ raw += rawValueChar;
25
+ iMask++;
26
+ }
27
+ } else {
28
+ formatted += maskChar;
29
+ iMask++;
30
+ }
31
+ }
32
+ return { raw, formatted };
33
+ };
34
+ const getMask = (mask, newValue) => {
35
+ let maskArray;
36
+ const regexArray = [];
37
+ if (typeof mask === "function") {
38
+ maskArray = mask(newValue);
39
+ } else {
40
+ maskArray = mask;
41
+ }
42
+ maskArray.forEach((exp) => {
43
+ if (typeof exp !== "string") {
44
+ if (Array.isArray(exp)) regexArray.push(exp);
45
+ else regexArray.push(exp);
46
+ } else {
47
+ for (let i = 0; i < exp.length; i++) {
48
+ if (exp[i] === "\\") {
49
+ regexArray.push(exp[i + 1]);
50
+ i++;
51
+ } else {
52
+ if (exp[i] === "9") regexArray.push(/\d/);
53
+ else if (exp[i] === "a") regexArray.push(/[a-zA-Z]/);
54
+ else regexArray.push(exp[i]);
55
+ }
56
+ }
57
+ }
58
+ });
59
+ return regexArray;
60
+ };
61
+ const useStringMask = (mask, defaultValue) => {
62
+ const applyMask = useCallback(
63
+ (value2 = "") => {
64
+ const selectedMask = getMask(mask, value2);
65
+ const { formatted, raw } = mergeMask(value2, selectedMask);
66
+ return {
67
+ raw,
68
+ formatted
69
+ };
70
+ },
71
+ [mask]
72
+ );
73
+ const [value, setValue] = useState(
74
+ applyMask(defaultValue?.toString())
75
+ );
76
+ const handleChangeValue = useCallback(
77
+ (formattedValue) => {
78
+ const { raw, formatted } = applyMask(formattedValue?.toString());
79
+ setValue({
80
+ raw,
81
+ formatted
82
+ });
83
+ },
84
+ [applyMask, setValue]
85
+ );
86
+ return [value, handleChangeValue];
87
+ };
88
+
89
+ export { getMask, mergeMask, useStringMask };
package/dist/esm/index.js CHANGED
@@ -32,6 +32,7 @@ export { TimeField } from './components/TimeField/TimeField.js';
32
32
  export { TimeFieldInput } from './components/TimeField/TimeFieldInput.js';
33
33
  export { Toggle } from './components/Toggle.js';
34
34
  export { Tooltip } from './components/Tooltip.js';
35
+ export { Kanban } from './components/Kanban.js';
35
36
  export { useCalendar } from './hooks/useCalendar.js';
36
37
  export { useCalendarCell } from './hooks/useCalendarCell.js';
37
38
  export { useCalendarGrid } from './hooks/useCalendarGrid.js';
@@ -39,11 +40,13 @@ export { useDatePickerInput } from './hooks/useDatePickerInput.js';
39
40
  export { useDateRangePickerInput } from './hooks/useDateRangePickerInput.js';
40
41
  export { useDebouncedState } from './hooks/useDebouncedState.js';
41
42
  export { useFloatingLogic } from './hooks/useFloatingLogic.js';
43
+ export { getInternalNumberAndMask, useNumberMask } from './hooks/useNumberMask.js';
42
44
  export { useOutsideClickListener } from './hooks/useOutsideClickListener.js';
43
45
  export { useRangeCalendar } from './hooks/useRangeCalendar.js';
44
46
  export { useSelectGroupedOptions } from './hooks/useSelectGroupedOptions.js';
45
47
  export { useSelectOptions } from './hooks/useSelectOptions.js';
48
+ export { getMask, mergeMask, useStringMask } from './hooks/useStringMask.js';
46
49
  export { SnackbarSonner } from './service/SnackbarSonner.js';
47
50
  export { MenubarProvider, useMenubar } from './provider/MenubarProvider.js';
48
51
  export { SnackbarProvider, useSnackbar } from './provider/SnackbarProvider.js';
49
- export { CurrencyIMask, ExpressionMasks, NumberIMask, PercentageIMask } from './components/Input/masks.js';
52
+ export { BRLMask, CurrencyIMask, ExpressionMasks, Masks, NumberIMask, PercentageIMask, PercentageMask } from './components/Input/masks.js';
@@ -9,6 +9,7 @@ import '../components/Button.js';
9
9
  import 'react-aria';
10
10
  import 'react-stately';
11
11
  import '@floating-ui/react';
12
+ import 'currency.js';
12
13
  import '../components/Calendar/CalendarCell.js';
13
14
  import '@tecsinapse/cortex-core';
14
15
  import 'react-icons/fa';
@@ -0,0 +1,4 @@
1
+ const extractNumbersFromString = (value) => Number(extractDigitsFromString(value));
2
+ const extractDigitsFromString = (value) => value.replace(/[^0-9]/g, "");
3
+
4
+ export { extractDigitsFromString, extractNumbersFromString };
@@ -37,3 +37,27 @@ export declare const PercentageIMask: {
37
37
  };
38
38
  };
39
39
  };
40
+ export declare const Masks: {
41
+ CPF: string[];
42
+ CNPJ: string[];
43
+ DATE: string[];
44
+ HOUR: string[];
45
+ MONTH_YEAR: string[];
46
+ CEP: string[];
47
+ PHONE: string[];
48
+ PHONE_EXTENDED: string[];
49
+ COMBINED_PHONE: (value: string) => string[];
50
+ COMBINED_CPF_CNPJ: (value: string) => string[];
51
+ };
52
+ export declare const BRLMask: {
53
+ symbol: string;
54
+ separator: string;
55
+ decimal: string;
56
+ precision: number;
57
+ };
58
+ export declare const PercentageMask: {
59
+ symbol: string;
60
+ separator: string;
61
+ decimal: string;
62
+ precision: number;
63
+ };
@@ -1,4 +1,5 @@
1
1
  import { InputBaseVariants } from '@tecsinapse/cortex-core';
2
+ import { CurrencyOptions } from '../../hooks';
2
3
  export interface InputPropsBase {
3
4
  variants?: InputBaseVariants;
4
5
  label?: string;
@@ -18,14 +19,13 @@ export interface InputRightProps extends React.HTMLAttributes<HTMLDivElement> {
18
19
  export interface InputSearchProps extends InputProps {
19
20
  bounceTimeout?: number;
20
21
  }
21
- export type InputMaskEvent = {
22
- value: string;
23
- unmaskedValue: string;
24
- };
25
- export interface Mask extends Record<string, any> {
26
- mask: any;
22
+ export interface MaskValue {
23
+ formatted?: string;
24
+ raw?: string | number;
27
25
  }
28
- export interface InputMaskProps extends Omit<InputProps, 'onChange'> {
29
- onChange?: (e: InputMaskEvent) => void;
30
- mask: Mask;
26
+ export type MaskType = string | RegExp | Array<RegExp>;
27
+ export interface InputMaskProps extends Omit<InputProps, 'onChange' | 'value'> {
28
+ value?: string | number;
29
+ onChange?: (value: any) => void;
30
+ mask?: (MaskType[] | ((value: string) => MaskType[])) | CurrencyOptions;
31
31
  }
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- interface KanbanProps extends React.HTMLAttributes<HTMLDivElement> {
2
+ export interface KanbanProps extends React.HTMLAttributes<HTMLDivElement> {
3
3
  children?: React.ReactNode;
4
4
  }
5
5
  export declare const Kanban: {
@@ -8,4 +8,3 @@ export declare const Kanban: {
8
8
  Body: ({ children, className, ...rest }: KanbanProps) => JSX.Element;
9
9
  ContainerList: ({ children, className, ...rest }: KanbanProps) => JSX.Element;
10
10
  };
11
- export {};
@@ -24,3 +24,4 @@ export * from './TextArea';
24
24
  export * from './TimeField';
25
25
  export * from './Toggle';
26
26
  export * from './Tooltip';
27
+ export * from './Kanban';
@@ -5,7 +5,9 @@ export * from './useDatePickerInput';
5
5
  export * from './useDateRangePickerInput';
6
6
  export * from './useDebouncedState';
7
7
  export * from './useFloatingLogic';
8
+ export * from './useNumberMask';
8
9
  export * from './useOutsideClickListener';
9
10
  export * from './useRangeCalendar';
10
11
  export * from './useSelectGroupedOptions';
11
12
  export * from './useSelectOptions';
13
+ export * from './useStringMask';
@@ -0,0 +1,8 @@
1
+ import currency from 'currency.js';
2
+ import { MaskValue } from '../components';
3
+ export type CurrencyOptions = currency.Options;
4
+ export declare const getInternalNumberAndMask: (value: string | number, options?: CurrencyOptions) => {
5
+ internalNumber: number;
6
+ mergedOptions: CurrencyOptions;
7
+ };
8
+ export declare const useNumberMask: (options?: CurrencyOptions, defaultValue?: string | number) => [MaskValue, (value: string | number) => void];
@@ -0,0 +1,4 @@
1
+ import { MaskType, MaskValue } from '../components';
2
+ export declare const mergeMask: (value: string | undefined, mask: MaskType[]) => MaskValue;
3
+ export declare const getMask: (mask: MaskType[] | ((value: string) => MaskType[]), newValue: string) => MaskType[];
4
+ export declare const useStringMask: (mask: MaskType[] | ((value: string) => MaskType[]), defaultValue?: string | number) => [MaskValue, (text: string | number) => void];
@@ -0,0 +1,2 @@
1
+ export declare const extractNumbersFromString: (value: string) => number;
2
+ export declare const extractDigitsFromString: (value: string) => string;
@@ -0,0 +1 @@
1
+ export * from './extractNumbersFromString';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tecsinapse/cortex-react",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "React components based in @tecsinapse/cortex-core",
5
5
  "license": "MIT",
6
6
  "main": "dist/esm/index.js",
@@ -20,7 +20,7 @@
20
20
  "dependencies": {
21
21
  "@floating-ui/react": "^0.26.18",
22
22
  "@internationalized/date": "*",
23
- "@tecsinapse/cortex-core": "0.3.0",
23
+ "@tecsinapse/cortex-core": "0.3.1",
24
24
  "clsx": "*",
25
25
  "react-aria": "^3.33.1",
26
26
  "react-icons": "^5.2.1",
@@ -43,5 +43,5 @@
43
43
  "react-dom": ">=18.0.0",
44
44
  "tailwind": ">=3.3.0"
45
45
  },
46
- "gitHead": "b2d6ba741db192cd1ae8498d9502653bfb304aa2"
46
+ "gitHead": "01bd621b6459e9ed136a902aaeb9a33236dd4772"
47
47
  }