@tecsinapse/react-core 1.14.5 → 1.15.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.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,36 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.15.0](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-core@1.14.7...@tecsinapse/react-core@1.15.0) (2022-03-07)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @tecsinapse/react-core
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.14.7](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-core@1.14.6...@tecsinapse/react-core@1.14.7) (2022-02-16)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* removing null check in InputElement value since it needs to be passed as parameter. ([b1af9ce](https://github.com/tecsinapse/design-system/commit/b1af9ceb2f0ef13efe0895db467bdbf61eda5f2a))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## [1.14.6](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-core@1.14.5...@tecsinapse/react-core@1.14.6) (2022-02-16)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* infinite loop caused by the useEffect. Updating values correctly when they change in the parent component. ([0355ed1](https://github.com/tecsinapse/design-system/commit/0355ed19cdd9e237d277df8c431f78602cfc214e))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
6
36
|
## [1.14.5](https://github.com/tecsinapse/design-system/compare/@tecsinapse/react-core@1.14.4...@tecsinapse/react-core@1.14.5) (2022-02-16)
|
|
7
37
|
|
|
8
38
|
|
|
@@ -31,25 +31,24 @@ const InputElement = _react2.default.forwardRef(({
|
|
|
31
31
|
...rest
|
|
32
32
|
}, ref) => {
|
|
33
33
|
const theme = (0, _react.useTheme)();
|
|
34
|
-
const [valueReinitialized, setValueReinitialized] = (0, _react2.useState)(false);
|
|
35
34
|
|
|
36
35
|
const _placeholderColor = placeholderTextColor || theme.font.color.dark;
|
|
37
36
|
|
|
38
|
-
const getInputHook =
|
|
37
|
+
const getInputHook = value => {
|
|
39
38
|
if (mask !== undefined) {
|
|
40
39
|
if (Array.isArray(mask) || typeof mask === 'function') {
|
|
41
|
-
return (0, _useStringMask.useStringMask)(mask, value
|
|
40
|
+
return (0, _useStringMask.useStringMask)(mask, value);
|
|
42
41
|
} else {
|
|
43
|
-
return (0, _useNumberMask.useNumberMask)(mask, value
|
|
42
|
+
return (0, _useNumberMask.useNumberMask)(mask, value);
|
|
44
43
|
}
|
|
45
44
|
} else {
|
|
46
45
|
return [undefined, undefined];
|
|
47
46
|
}
|
|
48
47
|
};
|
|
49
48
|
|
|
50
|
-
const [maskValue, setMaskValue] = getInputHook();
|
|
49
|
+
const [maskValue, setMaskValue] = getInputHook(value);
|
|
51
50
|
|
|
52
|
-
const _value = maskValue
|
|
51
|
+
const _value = maskValue === undefined ? value.toString() : maskValue.formatted ? maskValue.formatted : '';
|
|
53
52
|
|
|
54
53
|
(0, _react2.useEffect)(() => {
|
|
55
54
|
if (onChange) {
|
|
@@ -62,15 +61,14 @@ const InputElement = _react2.default.forwardRef(({
|
|
|
62
61
|
} else onChange && onChange(value);
|
|
63
62
|
}, [value]);
|
|
64
63
|
(0, _react2.useEffect)(() => {
|
|
65
|
-
if (
|
|
66
|
-
if (maskValue !== undefined &&
|
|
67
|
-
|
|
68
|
-
setValueReinitialized(true);
|
|
69
|
-
setMaskValue(value);
|
|
70
|
-
}
|
|
64
|
+
if (maskValue !== undefined && setMaskValue !== undefined && value !== undefined && typeof maskValue === 'object') {
|
|
65
|
+
if (maskValue.raw !== undefined && maskValue.raw.toString() !== value.toString()) {
|
|
66
|
+
onChangeValue(value);
|
|
71
67
|
}
|
|
68
|
+
} else if (maskValue === undefined && value !== undefined) {
|
|
69
|
+
onChangeValue(value);
|
|
72
70
|
}
|
|
73
|
-
}, [value
|
|
71
|
+
}, [value]);
|
|
74
72
|
return _react2.default.createElement(_styled.StyledInputElement, _extends({}, rest, {
|
|
75
73
|
ref: ref,
|
|
76
74
|
onChangeText: onChangeValue,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/components/atoms/Input/InputElement/InputElement.tsx"],"names":["InputElement","React","forwardRef","onChange","placeholder","value","disabled","placeholderTextColor","mask","rest","ref","theme","
|
|
1
|
+
{"version":3,"sources":["../../../../../src/components/atoms/Input/InputElement/InputElement.tsx"],"names":["InputElement","React","forwardRef","onChange","placeholder","value","disabled","placeholderTextColor","mask","rest","ref","theme","_placeholderColor","font","color","dark","getInputHook","undefined","Array","isArray","maskValue","setMaskValue","_value","toString","formatted","raw","onChangeValue","displayName"],"mappings":";;;;;;;AAAA;;AAEA;;AAEA;;AACA;;AACA;;;;;;;;AAuBA,MAAMA,YAAmC,GAAGC,gBAAMC,UAAN,CAC1C,CACE;AACEC,EAAAA,QADF;AAEEC,EAAAA,WAFF;AAGEC,EAAAA,KAHF;AAIEC,EAAAA,QAAQ,GAAG,KAJb;AAKEC,EAAAA,oBALF;AAMEC,EAAAA,IANF;AAOE,KAAGC;AAPL,CADF,EAUEC,GAVF,KAWkB;AAChB,QAAMC,KAAK,GAAG,sBAAd;;AAEA,QAAMC,iBAAiB,GAAGL,oBAAoB,IAAII,KAAK,CAACE,IAAN,CAAWC,KAAX,CAAiBC,IAAnE;;AAEA,QAAMC,YAAY,GAAIX,KAAD,IAA4B;AAC/C,QAAIG,IAAI,KAAKS,SAAb,EAAwB;AACtB,UAAIC,KAAK,CAACC,OAAN,CAAcX,IAAd,KAAuB,OAAOA,IAAP,KAAgB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AoD;AACzDS,MAAAA,aAAa,CAACrB,KAAD,CAAb;AACD;AACF,GAlBD,EAkBG,CAACA,KAAD,CAlBH;AAoBA,SACE,8BAAC,0BAAD,eACMI,IADN;AAEE,IAAA,GAAG,EAAEC,GAFP;AAGE,IAAA,YAAY,EAAEgB,aAHhB;AAIE,IAAA,KAAK,EAAEJ,MAJT;AAKE,IAAA,WAAW,EAAElB,WALf;AAME,IAAA,oBAAoB,EAAEQ,iBANxB;AAOE,IAAA,QAAQ,EAAEN,QAPZ;AAQE,IAAA,QAAQ,EAAE,CAACA;AARb,KADF;AAYD,CArFyC,CAA5C;;AAwFAN,YAAY,CAAC2B,WAAb,GAA2B,cAA3B;eAEe3B,Y","sourcesContent":["import { useTheme } from '@emotion/react';\nimport { ThemeProp } from '@tecsinapse/react-core';\nimport React, { FC, useCallback, useEffect } from 'react';\nimport { StyleProp, TextInputProps, TextStyle } from 'react-native';\nimport { StyledInputElement } from '../styled';\nimport { MaskType, useStringMask } from '../hooks/useStringMask';\nimport { CurrencyOptions, useNumberMask } from '../hooks/useNumberMask';\n\nexport interface InputElementProps\n extends Omit<TextInputProps, 'onChange' | 'value' | 'ref'> {\n style?: StyleProp<TextStyle>;\n value: string | number;\n placeholder?: string;\n disabled?: boolean;\n onChange?: (value: any) => void;\n /**\n To use mask for strings you have to pass a MaskType[] or ((value: string) => MaskType[])\n A MaskType can be a string, RegExp, or Array<RegExp>.\n In case we have a string, '9' represents digits, 'a' represents alphabet characters, and any other character represents fixed characters in the mask.\n For example a phone mask can be represented as ['(99) \\\\99999-9999'], or ['(99) ', '/[9]/', '9999-9999'], or ['(', /[0-9]/, /[0-9]/, ') ', '/[9]/', '9999-9999'] and many others.\n To use mask for numbers you have to pass a CurrencyOptions object\n A CurrencyOptions object contains symbol, separator, decimal, precision. For example {symbol: 'R$ ', separator: '.', decimal: ',', precision: 2,}.\n **/\n mask?: (MaskType[] | ((value: string) => MaskType[])) | CurrencyOptions;\n onFocus?: () => void;\n onBlur?: () => void;\n ref?: React.Ref<any>;\n}\n\nconst InputElement: FC<InputElementProps> = React.forwardRef(\n (\n {\n onChange,\n placeholder,\n value,\n disabled = false,\n placeholderTextColor,\n mask,\n ...rest\n },\n ref: React.Ref<any>\n ): JSX.Element => {\n const theme = useTheme() as ThemeProp;\n\n const _placeholderColor = placeholderTextColor || theme.font.color.dark;\n\n const getInputHook = (value: string | number) => {\n if (mask !== undefined) {\n if (Array.isArray(mask) || typeof mask === 'function') {\n return useStringMask(mask, value);\n } else {\n return useNumberMask(mask, value);\n }\n } else {\n return [undefined, undefined];\n }\n };\n\n const [maskValue, setMaskValue] = getInputHook(value);\n\n const _value =\n maskValue === undefined\n ? value.toString()\n : maskValue.formatted\n ? maskValue.formatted\n : '';\n\n useEffect(() => {\n if (onChange) {\n onChange(maskValue?.raw);\n }\n }, [maskValue]);\n\n const onChangeValue = useCallback(\n (value: string | number) => {\n if (maskValue !== undefined && setMaskValue !== undefined) {\n setMaskValue(value);\n } else onChange && onChange(value);\n },\n [value]\n );\n\n useEffect(() => {\n /** Used to reinitialize maskValue when the value is updated in the parent component **/\n if (\n maskValue !== undefined &&\n setMaskValue !== undefined &&\n value !== undefined &&\n typeof maskValue === 'object'\n ) {\n /** Case there is a mask **/\n if (\n maskValue.raw !== undefined &&\n maskValue.raw.toString() !== value.toString()\n ) {\n onChangeValue(value);\n }\n } else if (maskValue === undefined && value !== undefined) {\n onChangeValue(value);\n }\n }, [value]);\n\n return (\n <StyledInputElement\n {...rest}\n ref={ref}\n onChangeText={onChangeValue}\n value={_value}\n placeholder={placeholder}\n placeholderTextColor={_placeholderColor}\n disabled={disabled}\n editable={!disabled}\n />\n );\n }\n);\n\nInputElement.displayName = 'InputElement';\n\nexport default InputElement;\n"],"file":"InputElement.js"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tecsinapse/react-core",
|
|
3
3
|
"description": "TecSinapse hybrid React components",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.15.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"react-native": ">=0.64.0",
|
|
32
32
|
"react-native-vector-icons": ">=8.1.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "e7dd208b02a6728b47f77ab2d6a5970b09c70970"
|
|
35
35
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useTheme } from '@emotion/react';
|
|
2
2
|
import { ThemeProp } from '@tecsinapse/react-core';
|
|
3
|
-
import React, { FC, useCallback, useEffect
|
|
3
|
+
import React, { FC, useCallback, useEffect } from 'react';
|
|
4
4
|
import { StyleProp, TextInputProps, TextStyle } from 'react-native';
|
|
5
5
|
import { StyledInputElement } from '../styled';
|
|
6
6
|
import { MaskType, useStringMask } from '../hooks/useStringMask';
|
|
@@ -42,31 +42,28 @@ const InputElement: FC<InputElementProps> = React.forwardRef(
|
|
|
42
42
|
): JSX.Element => {
|
|
43
43
|
const theme = useTheme() as ThemeProp;
|
|
44
44
|
|
|
45
|
-
/** Check if value was reinitialized, without this state we can't total "erase" a value that was already reinitialized **/
|
|
46
|
-
const [valueReinitialized, setValueReinitialized] = useState<boolean>(
|
|
47
|
-
false
|
|
48
|
-
);
|
|
49
|
-
|
|
50
45
|
const _placeholderColor = placeholderTextColor || theme.font.color.dark;
|
|
51
46
|
|
|
52
|
-
const getInputHook = () => {
|
|
47
|
+
const getInputHook = (value: string | number) => {
|
|
53
48
|
if (mask !== undefined) {
|
|
54
49
|
if (Array.isArray(mask) || typeof mask === 'function') {
|
|
55
|
-
return useStringMask(mask, value
|
|
50
|
+
return useStringMask(mask, value);
|
|
56
51
|
} else {
|
|
57
|
-
return useNumberMask(mask, value
|
|
52
|
+
return useNumberMask(mask, value);
|
|
58
53
|
}
|
|
59
54
|
} else {
|
|
60
55
|
return [undefined, undefined];
|
|
61
56
|
}
|
|
62
57
|
};
|
|
63
58
|
|
|
64
|
-
const [maskValue, setMaskValue] = getInputHook();
|
|
59
|
+
const [maskValue, setMaskValue] = getInputHook(value);
|
|
65
60
|
|
|
66
61
|
const _value =
|
|
67
|
-
maskValue
|
|
68
|
-
?
|
|
69
|
-
:
|
|
62
|
+
maskValue === undefined
|
|
63
|
+
? value.toString()
|
|
64
|
+
: maskValue.formatted
|
|
65
|
+
? maskValue.formatted
|
|
66
|
+
: '';
|
|
70
67
|
|
|
71
68
|
useEffect(() => {
|
|
72
69
|
if (onChange) {
|
|
@@ -84,22 +81,24 @@ const InputElement: FC<InputElementProps> = React.forwardRef(
|
|
|
84
81
|
);
|
|
85
82
|
|
|
86
83
|
useEffect(() => {
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
/** Used to reinitialize maskValue when the value is updated in the parent component **/
|
|
85
|
+
if (
|
|
86
|
+
maskValue !== undefined &&
|
|
87
|
+
setMaskValue !== undefined &&
|
|
88
|
+
value !== undefined &&
|
|
89
|
+
typeof maskValue === 'object'
|
|
90
|
+
) {
|
|
91
|
+
/** Case there is a mask **/
|
|
89
92
|
if (
|
|
90
|
-
maskValue !== undefined &&
|
|
91
|
-
|
|
92
|
-
value !== undefined &&
|
|
93
|
-
typeof maskValue === 'object'
|
|
93
|
+
maskValue.raw !== undefined &&
|
|
94
|
+
maskValue.raw.toString() !== value.toString()
|
|
94
95
|
) {
|
|
95
|
-
|
|
96
|
-
if (maskValue.raw !== value?.toString()) {
|
|
97
|
-
setValueReinitialized(true);
|
|
98
|
-
setMaskValue(value);
|
|
99
|
-
}
|
|
96
|
+
onChangeValue(value);
|
|
100
97
|
}
|
|
98
|
+
} else if (maskValue === undefined && value !== undefined) {
|
|
99
|
+
onChangeValue(value);
|
|
101
100
|
}
|
|
102
|
-
}, [value
|
|
101
|
+
}, [value]);
|
|
103
102
|
|
|
104
103
|
return (
|
|
105
104
|
<StyledInputElement
|