@tecsinapse/react-core 1.13.0 → 1.14.0

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 (46) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/components/atoms/Input/InputElement/InputElement.d.ts +5 -3
  3. package/dist/components/atoms/Input/InputElement/InputElement.js +22 -8
  4. package/dist/components/atoms/Input/InputElement/InputElement.js.map +1 -1
  5. package/dist/components/atoms/Input/hooks/useNumberMask.d.ts +8 -0
  6. package/dist/components/atoms/Input/hooks/useNumberMask.js +98 -0
  7. package/dist/components/atoms/Input/hooks/useNumberMask.js.map +1 -0
  8. package/dist/components/atoms/Input/hooks/useStringMask.d.ts +8 -0
  9. package/dist/components/atoms/Input/hooks/useStringMask.js +109 -0
  10. package/dist/components/atoms/Input/hooks/useStringMask.js.map +1 -0
  11. package/dist/components/atoms/Input/index.d.ts +2 -3
  12. package/dist/components/atoms/Input/index.js +12 -26
  13. package/dist/components/atoms/Input/index.js.map +1 -1
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.js +8 -29
  16. package/dist/index.js.map +1 -1
  17. package/dist/utils/formatWithMask.d.ts +3 -0
  18. package/dist/utils/formatWithMask.js +31 -0
  19. package/dist/utils/formatWithMask.js.map +1 -0
  20. package/dist/utils/index.d.ts +2 -0
  21. package/dist/utils/index.js +28 -0
  22. package/dist/utils/index.js.map +1 -1
  23. package/dist/utils/masks.d.ts +10 -0
  24. package/dist/utils/masks.js +18 -0
  25. package/dist/utils/masks.js.map +1 -0
  26. package/package.json +2 -2
  27. package/src/components/atoms/Input/InputElement/InputElement.tsx +37 -11
  28. package/src/components/atoms/Input/hooks/useNumberMask.ts +99 -0
  29. package/src/components/atoms/Input/hooks/useStringMask.ts +126 -0
  30. package/src/components/atoms/Input/index.ts +2 -3
  31. package/src/index.ts +3 -6
  32. package/src/utils/formatWithMask.ts +25 -0
  33. package/src/utils/index.ts +4 -2
  34. package/src/utils/masks.ts +13 -0
  35. package/dist/components/atoms/Input/hooks/useCurrencyMask.d.ts +0 -3
  36. package/dist/components/atoms/Input/hooks/useCurrencyMask.js +0 -69
  37. package/dist/components/atoms/Input/hooks/useCurrencyMask.js.map +0 -1
  38. package/dist/components/atoms/Input/hooks/useMask.d.ts +0 -9
  39. package/dist/components/atoms/Input/hooks/useMask.js +0 -61
  40. package/dist/components/atoms/Input/hooks/useMask.js.map +0 -1
  41. package/dist/components/atoms/Input/masks/index.d.ts +0 -10
  42. package/dist/components/atoms/Input/masks/index.js +0 -18
  43. package/dist/components/atoms/Input/masks/index.js.map +0 -1
  44. package/src/components/atoms/Input/hooks/useCurrencyMask.ts +0 -74
  45. package/src/components/atoms/Input/hooks/useMask.ts +0 -92
  46. package/src/components/atoms/Input/masks/index.ts +0 -12
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Masks = void 0;
7
- const Masks = {
8
- CPF: '999.999.999-99',
9
- CNPJ: '99.999.999/9999-99',
10
- DATE: '99/99/9999',
11
- MONTH_YEAR: '99/9999',
12
- CEP: '99999-999',
13
- PHONE: '(99) 9999-9999',
14
- PHONE_EXTENDED: '(99) 99999-9999',
15
- COMBINED_PHONE: value => (value === null || value === void 0 ? void 0 : value.length) <= 10 ? Masks.PHONE : Masks.PHONE_EXTENDED
16
- };
17
- exports.Masks = Masks;
18
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../src/components/atoms/Input/masks/index.ts"],"names":["Masks","CPF","CNPJ","DATE","MONTH_YEAR","CEP","PHONE","PHONE_EXTENDED","COMBINED_PHONE","value","length"],"mappings":";;;;;;AACO,MAAMA,KAAK,GAAG;AACnBC,EAAAA,GAAG,EAAE,gBADc;AAEnBC,EAAAA,IAAI,EAAE,oBAFa;AAGnBC,EAAAA,IAAI,EAAE,YAHa;AAInBC,EAAAA,UAAU,EAAE,SAJO;AAKnBC,EAAAA,GAAG,EAAE,WALc;AAMnBC,EAAAA,KAAK,EAAE,gBANY;AAOnBC,EAAAA,cAAc,EAAE,iBAPG;AAQnBC,EAAAA,cAAc,EAAGC,KAAD,IACd,CAAAA,KAAK,SAAL,IAAAA,KAAK,WAAL,YAAAA,KAAK,CAAEC,MAAP,KAAiB,EAAjB,GAAsBV,KAAK,CAACM,KAA5B,GAAoCN,KAAK,CAACO;AATzB,CAAd","sourcesContent":["// NOTE: Add here all individually masks, then you can use it on input components everywhere.\nexport const Masks = {\n CPF: '999.999.999-99',\n CNPJ: '99.999.999/9999-99',\n DATE: '99/99/9999',\n MONTH_YEAR: '99/9999',\n CEP: '99999-999',\n PHONE: '(99) 9999-9999',\n PHONE_EXTENDED: '(99) 99999-9999',\n COMBINED_PHONE: (value: string) =>\n value?.length <= 10 ? Masks.PHONE : Masks.PHONE_EXTENDED,\n};\n"],"file":"index.js"}
@@ -1,74 +0,0 @@
1
- import currency from 'currency.js';
2
- import { useCallback, useState } from 'react';
3
- import { extractNumbersFromString } from '../../../../utils';
4
- import { IMask, IMaskValue } from './useMask';
5
-
6
- type CurrencyOptions = currency.Options;
7
-
8
- const DEFAULT_OPTIONS: CurrencyOptions = {
9
- symbol: 'R$ ',
10
- separator: '.',
11
- decimal: ',',
12
- precision: 2,
13
- };
14
-
15
- /**
16
- * TODO:
17
- * @param options
18
- * @param defaultValue
19
- * @returns
20
- */
21
- export const useCurrencyMask = (
22
- options?: CurrencyOptions,
23
- defaultValue?: string
24
- ): [IMask, (value: string) => void] => {
25
- const getRegex = useCallback(
26
- (precision: number) => new RegExp(`\\B(?=(\\d{${precision}})(?!\\d))`, 'g'),
27
- [options]
28
- );
29
-
30
- const applyMask = useCallback(
31
- (value = ''): IMaskValue => {
32
- const mergedOptions = { ...DEFAULT_OPTIONS, ...options };
33
- const { precision = -1 } = mergedOptions;
34
- const onlyNumbers = String(extractNumbersFromString(value));
35
- const padZeros = String(onlyNumbers).padStart(precision + 1, '0');
36
- let internalNumber = Number(padZeros.replace(getRegex(precision), '.'));
37
-
38
- if (internalNumber > Number.MAX_SAFE_INTEGER) {
39
- internalNumber = Number.MAX_SAFE_INTEGER;
40
- }
41
-
42
- if (internalNumber < Number.MIN_SAFE_INTEGER) {
43
- internalNumber = Number.MIN_SAFE_INTEGER;
44
- }
45
-
46
- return {
47
- raw: internalNumber,
48
- formatted: currency(internalNumber).format(mergedOptions),
49
- };
50
- },
51
- [options, getRegex]
52
- );
53
-
54
- const [value, setValue] = useState<IMask>({
55
- converter: applyMask,
56
- maskValue: applyMask(defaultValue),
57
- });
58
-
59
- const handleChangeValue = useCallback(
60
- (formattedValue: string) => {
61
- const { raw, formatted } = applyMask(formattedValue);
62
- setValue(oldValue => ({
63
- ...oldValue,
64
- maskValue: {
65
- raw,
66
- formatted,
67
- },
68
- }));
69
- },
70
- [applyMask, setValue]
71
- );
72
-
73
- return [value, handleChangeValue];
74
- };
@@ -1,92 +0,0 @@
1
- import { useCallback, useState } from 'react';
2
- import { extractDigitsFromString } from '../../../../utils';
3
-
4
- export interface IMaskValue {
5
- formatted?: string;
6
- raw?: any;
7
- }
8
-
9
- export interface IMask {
10
- converter?: (raw?: string) => IMaskValue;
11
- maskValue?: IMaskValue;
12
- }
13
-
14
- /**
15
- * TODO:
16
- * @param value
17
- * @param mask
18
- * @returns
19
- */
20
- const mergeMask = (value = '', mask: string) => {
21
- const chars = '' + value;
22
- let formattedValue = '';
23
-
24
- for (
25
- let iMask = 0, iChars = 0;
26
- iMask < mask.length && iChars < chars.length;
27
- iMask++
28
- ) {
29
- formattedValue +=
30
- mask.charAt(iMask) === '9' ? chars.charAt(iChars++) : mask.charAt(iMask);
31
- }
32
- return formattedValue;
33
- };
34
-
35
- /**
36
- * TODO:
37
- * @param value
38
- * @param mask
39
- * @returns
40
- */
41
- const getMask = (value = '', mask: ((raw: any) => string) | string): string => {
42
- if (typeof mask === 'function') {
43
- return mask(value);
44
- }
45
- return mask;
46
- };
47
-
48
- /**
49
- * TODO:
50
- * @param mask
51
- * @param defaultValue
52
- * @returns
53
- */
54
- export const useMask = (
55
- mask: ((raw: any) => string) | string,
56
- defaultValue?: string
57
- ): [IMask, (text: string) => void] => {
58
- const applyMask = useCallback(
59
- (value = ''): IMaskValue => {
60
- const onlyNumbers = value ? extractDigitsFromString(value) : value;
61
- const selectedMask = getMask(onlyNumbers, mask);
62
- const formattedValue = mergeMask(onlyNumbers, selectedMask);
63
-
64
- return {
65
- raw: onlyNumbers,
66
- formatted: formattedValue,
67
- };
68
- },
69
- [mask]
70
- );
71
-
72
- const [value, setValue] = useState<IMask>({
73
- converter: applyMask,
74
- maskValue: applyMask(defaultValue),
75
- });
76
-
77
- const handleChangeValue = useCallback(
78
- (value: string) => {
79
- const { raw, formatted } = applyMask(value);
80
- setValue(oldValue => ({
81
- ...oldValue,
82
- maskValue: {
83
- raw,
84
- formatted,
85
- },
86
- }));
87
- },
88
- [applyMask, setValue]
89
- );
90
-
91
- return [value, handleChangeValue];
92
- };
@@ -1,12 +0,0 @@
1
- // NOTE: Add here all individually masks, then you can use it on input components everywhere.
2
- export const Masks = {
3
- CPF: '999.999.999-99',
4
- CNPJ: '99.999.999/9999-99',
5
- DATE: '99/99/9999',
6
- MONTH_YEAR: '99/9999',
7
- CEP: '99999-999',
8
- PHONE: '(99) 9999-9999',
9
- PHONE_EXTENDED: '(99) 99999-9999',
10
- COMBINED_PHONE: (value: string) =>
11
- value?.length <= 10 ? Masks.PHONE : Masks.PHONE_EXTENDED,
12
- };