@pagopa/io-app-design-system 1.36.0 → 1.36.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.
- package/lib/commonjs/components/otpInput/OTPInput.js +14 -11
- package/lib/commonjs/components/otpInput/OTPInput.js.map +1 -1
- package/lib/module/components/otpInput/OTPInput.js +14 -11
- package/lib/module/components/otpInput/OTPInput.js.map +1 -1
- package/lib/typescript/components/otpInput/OTPInput.d.ts +5 -1
- package/lib/typescript/components/otpInput/OTPInput.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/otpInput/OTPInput.tsx +105 -93
|
@@ -29,19 +29,21 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
29
29
|
* @param errorMessage - The error message to display
|
|
30
30
|
* @returns
|
|
31
31
|
*/
|
|
32
|
-
const OTPInput = _ref => {
|
|
32
|
+
const OTPInput = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
33
33
|
let {
|
|
34
34
|
value,
|
|
35
35
|
onValueChange,
|
|
36
36
|
length,
|
|
37
|
+
accessibilityLabel,
|
|
38
|
+
accessibilityHint,
|
|
37
39
|
onValidate,
|
|
38
40
|
errorMessage = "",
|
|
39
41
|
secret = false,
|
|
40
|
-
autocomplete = false
|
|
42
|
+
autocomplete = false,
|
|
43
|
+
inputAccessoryViewID
|
|
41
44
|
} = _ref;
|
|
42
45
|
const [hasFocus, setHasFocus] = React.useState(false);
|
|
43
46
|
const [hasError, setHasError] = React.useState(false);
|
|
44
|
-
const [inputValue, setInputValue] = React.useState(value);
|
|
45
47
|
const {
|
|
46
48
|
translate,
|
|
47
49
|
animatedStyle,
|
|
@@ -65,7 +67,6 @@ const OTPInput = _ref => {
|
|
|
65
67
|
// eslint-disable-next-line functional/immutable-data
|
|
66
68
|
timerRef.current = setTimeout(() => {
|
|
67
69
|
setHasError(false);
|
|
68
|
-
setInputValue("");
|
|
69
70
|
onValueChange("");
|
|
70
71
|
}, 500);
|
|
71
72
|
}
|
|
@@ -75,7 +76,6 @@ const OTPInput = _ref => {
|
|
|
75
76
|
if (value.length > length) {
|
|
76
77
|
return;
|
|
77
78
|
}
|
|
78
|
-
setInputValue(value);
|
|
79
79
|
onValueChange(value);
|
|
80
80
|
handleValidate(value);
|
|
81
81
|
};
|
|
@@ -89,16 +89,18 @@ const OTPInput = _ref => {
|
|
|
89
89
|
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
|
|
90
90
|
setHasFocus(true);
|
|
91
91
|
},
|
|
92
|
+
ref: ref,
|
|
92
93
|
style: [_IOStyles.IOStyles.row, {
|
|
93
94
|
justifyContent: "space-around"
|
|
94
95
|
}],
|
|
95
96
|
accessible: true,
|
|
96
|
-
accessibilityLabel:
|
|
97
|
+
accessibilityLabel: accessibilityLabel,
|
|
98
|
+
accessibilityHint: accessibilityHint,
|
|
97
99
|
accessibilityValue: {
|
|
98
|
-
text:
|
|
100
|
+
text: value
|
|
99
101
|
}
|
|
100
102
|
}, /*#__PURE__*/React.createElement(_reactNative.TextInput, {
|
|
101
|
-
value:
|
|
103
|
+
value: value,
|
|
102
104
|
onChangeText: handleChange,
|
|
103
105
|
style: {
|
|
104
106
|
position: "absolute",
|
|
@@ -112,12 +114,13 @@ const OTPInput = _ref => {
|
|
|
112
114
|
returnKeyType: "done",
|
|
113
115
|
textContentType: "oneTimeCode",
|
|
114
116
|
autoComplete: autocomplete ? "sms-otp" : undefined,
|
|
117
|
+
inputAccessoryViewID: inputAccessoryViewID,
|
|
115
118
|
accessible: true
|
|
116
119
|
}), [...Array(length)].map((_, i) => /*#__PURE__*/React.createElement(_BoxedInput.BoxedInput, {
|
|
117
120
|
key: i,
|
|
118
|
-
status: hasError ? "error" : hasFocus &&
|
|
121
|
+
status: hasError ? "error" : hasFocus && value.length === i ? "focus" : "default",
|
|
119
122
|
secret: secret,
|
|
120
|
-
value:
|
|
123
|
+
value: value[i]
|
|
121
124
|
}))), /*#__PURE__*/React.createElement(_spacer.VSpacer, {
|
|
122
125
|
size: 4
|
|
123
126
|
}), hasError && errorMessage && /*#__PURE__*/React.createElement(_typography.LabelSmall, {
|
|
@@ -126,6 +129,6 @@ const OTPInput = _ref => {
|
|
|
126
129
|
textAlign: "center"
|
|
127
130
|
}
|
|
128
131
|
}, errorMessage));
|
|
129
|
-
};
|
|
132
|
+
});
|
|
130
133
|
exports.OTPInput = OTPInput;
|
|
131
134
|
//# sourceMappingURL=OTPInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","_interopRequireWildcard","require","_reactNative","_reactNativeReanimated","_interopRequireDefault","_IOStyles","_typography","_functions","_spacer","_useErrorShakeAnimation","_BoxedInput","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","OTPInput","_ref","value","onValueChange","length","onValidate","errorMessage","secret","autocomplete","hasFocus","setHasFocus","useState","hasError","setHasError","
|
|
1
|
+
{"version":3,"names":["React","_interopRequireWildcard","require","_reactNative","_reactNativeReanimated","_interopRequireDefault","_IOStyles","_typography","_functions","_spacer","_useErrorShakeAnimation","_BoxedInput","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","OTPInput","forwardRef","_ref","ref","value","onValueChange","length","accessibilityLabel","accessibilityHint","onValidate","errorMessage","secret","autocomplete","inputAccessoryViewID","hasFocus","setHasFocus","useState","hasError","setHasError","translate","animatedStyle","shakeAnimation","useErrorShakeAnimation","inputRef","createRef","timerRef","useRef","handleValidate","val","isValid","triggerHaptic","current","clearTimeout","setTimeout","useEffect","handleChange","createElement","View","style","flexGrow","Pressable","onPress","_inputRef$current","focus","IOStyles","row","justifyContent","accessible","accessibilityValue","text","TextInput","onChangeText","position","opacity","maxLength","onBlur","keyboardType","inputMode","returnKeyType","textContentType","autoComplete","undefined","Array","map","_","i","BoxedInput","status","VSpacer","size","LabelSmall","color","textAlign","exports"],"sourceRoot":"../../../../src","sources":["components/otpInput/OTPInput.tsx"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AACA,IAAAQ,uBAAA,GAAAR,OAAA;AACA,IAAAS,WAAA,GAAAT,OAAA;AAA0C,SAAAG,uBAAAO,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAf,wBAAAW,GAAA,EAAAI,WAAA,SAAAA,WAAA,IAAAJ,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAQ,KAAA,GAAAL,wBAAA,CAAAC,WAAA,OAAAI,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAT,GAAA,YAAAQ,KAAA,CAAAE,GAAA,CAAAV,GAAA,SAAAW,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,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ACjB,CACF,CACQ,CAAC,eACZnG,KAAA,CAAAsE,aAAA,CAAC7D,OAAA,CAAA6F,OAAO;IAACC,IAAI,EAAE;EAAE,CAAE,CAAC,EACnBpD,QAAQ,IAAIP,YAAY,iBACvB5C,KAAA,CAAAsE,aAAA,CAAC/D,WAAA,CAAAiG,UAAU;IAACC,KAAK,EAAC,WAAW;IAACjC,KAAK,EAAE;MAAEkC,SAAS,EAAE;IAAS;EAAE,GAC1D9D,YACS,CAED,CAAC;AAEpB,CACF,CAAC;AAAC+D,OAAA,CAAAzE,QAAA,GAAAA,QAAA"}
|
|
@@ -20,19 +20,21 @@ import { BoxedInput } from "./BoxedInput";
|
|
|
20
20
|
* @param errorMessage - The error message to display
|
|
21
21
|
* @returns
|
|
22
22
|
*/
|
|
23
|
-
export const OTPInput = _ref => {
|
|
23
|
+
export const OTPInput = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
24
24
|
let {
|
|
25
25
|
value,
|
|
26
26
|
onValueChange,
|
|
27
27
|
length,
|
|
28
|
+
accessibilityLabel,
|
|
29
|
+
accessibilityHint,
|
|
28
30
|
onValidate,
|
|
29
31
|
errorMessage = "",
|
|
30
32
|
secret = false,
|
|
31
|
-
autocomplete = false
|
|
33
|
+
autocomplete = false,
|
|
34
|
+
inputAccessoryViewID
|
|
32
35
|
} = _ref;
|
|
33
36
|
const [hasFocus, setHasFocus] = React.useState(false);
|
|
34
37
|
const [hasError, setHasError] = React.useState(false);
|
|
35
|
-
const [inputValue, setInputValue] = React.useState(value);
|
|
36
38
|
const {
|
|
37
39
|
translate,
|
|
38
40
|
animatedStyle,
|
|
@@ -56,7 +58,6 @@ export const OTPInput = _ref => {
|
|
|
56
58
|
// eslint-disable-next-line functional/immutable-data
|
|
57
59
|
timerRef.current = setTimeout(() => {
|
|
58
60
|
setHasError(false);
|
|
59
|
-
setInputValue("");
|
|
60
61
|
onValueChange("");
|
|
61
62
|
}, 500);
|
|
62
63
|
}
|
|
@@ -66,7 +67,6 @@ export const OTPInput = _ref => {
|
|
|
66
67
|
if (value.length > length) {
|
|
67
68
|
return;
|
|
68
69
|
}
|
|
69
|
-
setInputValue(value);
|
|
70
70
|
onValueChange(value);
|
|
71
71
|
handleValidate(value);
|
|
72
72
|
};
|
|
@@ -80,16 +80,18 @@ export const OTPInput = _ref => {
|
|
|
80
80
|
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
|
|
81
81
|
setHasFocus(true);
|
|
82
82
|
},
|
|
83
|
+
ref: ref,
|
|
83
84
|
style: [IOStyles.row, {
|
|
84
85
|
justifyContent: "space-around"
|
|
85
86
|
}],
|
|
86
87
|
accessible: true,
|
|
87
|
-
accessibilityLabel:
|
|
88
|
+
accessibilityLabel: accessibilityLabel,
|
|
89
|
+
accessibilityHint: accessibilityHint,
|
|
88
90
|
accessibilityValue: {
|
|
89
|
-
text:
|
|
91
|
+
text: value
|
|
90
92
|
}
|
|
91
93
|
}, /*#__PURE__*/React.createElement(TextInput, {
|
|
92
|
-
value:
|
|
94
|
+
value: value,
|
|
93
95
|
onChangeText: handleChange,
|
|
94
96
|
style: {
|
|
95
97
|
position: "absolute",
|
|
@@ -103,12 +105,13 @@ export const OTPInput = _ref => {
|
|
|
103
105
|
returnKeyType: "done",
|
|
104
106
|
textContentType: "oneTimeCode",
|
|
105
107
|
autoComplete: autocomplete ? "sms-otp" : undefined,
|
|
108
|
+
inputAccessoryViewID: inputAccessoryViewID,
|
|
106
109
|
accessible: true
|
|
107
110
|
}), [...Array(length)].map((_, i) => /*#__PURE__*/React.createElement(BoxedInput, {
|
|
108
111
|
key: i,
|
|
109
|
-
status: hasError ? "error" : hasFocus &&
|
|
112
|
+
status: hasError ? "error" : hasFocus && value.length === i ? "focus" : "default",
|
|
110
113
|
secret: secret,
|
|
111
|
-
value:
|
|
114
|
+
value: value[i]
|
|
112
115
|
}))), /*#__PURE__*/React.createElement(VSpacer, {
|
|
113
116
|
size: 4
|
|
114
117
|
}), hasError && errorMessage && /*#__PURE__*/React.createElement(LabelSmall, {
|
|
@@ -117,5 +120,5 @@ export const OTPInput = _ref => {
|
|
|
117
120
|
textAlign: "center"
|
|
118
121
|
}
|
|
119
122
|
}, errorMessage));
|
|
120
|
-
};
|
|
123
|
+
});
|
|
121
124
|
//# sourceMappingURL=OTPInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Pressable","TextInput","Animated","IOStyles","LabelSmall","triggerHaptic","VSpacer","useErrorShakeAnimation","BoxedInput","OTPInput","_ref","value","onValueChange","length","onValidate","errorMessage","secret","autocomplete","hasFocus","setHasFocus","useState","hasError","setHasError","
|
|
1
|
+
{"version":3,"names":["React","Pressable","TextInput","Animated","IOStyles","LabelSmall","triggerHaptic","VSpacer","useErrorShakeAnimation","BoxedInput","OTPInput","forwardRef","_ref","ref","value","onValueChange","length","accessibilityLabel","accessibilityHint","onValidate","errorMessage","secret","autocomplete","inputAccessoryViewID","hasFocus","setHasFocus","useState","hasError","setHasError","translate","animatedStyle","shakeAnimation","inputRef","createRef","timerRef","useRef","handleValidate","val","isValid","current","clearTimeout","setTimeout","useEffect","handleChange","createElement","View","style","flexGrow","onPress","_inputRef$current","focus","row","justifyContent","accessible","accessibilityValue","text","onChangeText","position","opacity","maxLength","onBlur","keyboardType","inputMode","returnKeyType","textContentType","autoComplete","undefined","Array","map","_","i","key","status","size","color","textAlign"],"sourceRoot":"../../../../src","sources":["components/otpInput/OTPInput.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,SAAS,EAAEC,SAAS,QAAc,cAAc;AACzD,OAAOC,QAAQ,MAAM,yBAAyB;AAC9C,SAASC,QAAQ,QAAQ,qBAAqB;AAC9C,SAASC,UAAU,QAAQ,eAAe;AAC1C,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,SAASC,OAAO,QAAQ,WAAW;AACnC,SAASC,sBAAsB,QAAQ,0CAA0C;AACjF,SAASC,UAAU,QAAQ,c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AO;IAClBH,GAAG,EAAEmB,QAAS;IACd4B,MAAM,EAAEA,CAAA,KAAMnC,WAAW,CAAC,KAAK,CAAE;IACjCoC,YAAY,EAAC,SAAS;IACtBC,SAAS,EAAC,SAAS;IACnBC,aAAa,EAAC,MAAM;IACpBC,eAAe,EAAC,aAAa;IAC7BC,YAAY,EAAE3C,YAAY,GAAG,SAAS,GAAG4C,SAAU;IACnD3C,oBAAoB,EAAEA,oBAAqB;IAC3C8B,UAAU,EAAE;EAAK,CAClB,CAAC,EACD,CAAC,GAAGc,KAAK,CAACnD,MAAM,CAAC,CAAC,CAACoD,GAAG,CAAC,CAACC,CAAC,EAAEC,CAAC,kBAC3BtE,KAAA,CAAA4C,aAAA,CAACnC,UAAU;IACT8D,GAAG,EAAED,CAAE;IACPE,MAAM,EACJ7C,QAAQ,GACJ,OAAO,GACPH,QAAQ,IAAIV,KAAK,CAACE,MAAM,KAAKsD,CAAC,GAC9B,OAAO,GACP,SACL;IACDjD,MAAM,EAAEA,MAAO;IACfP,KAAK,EAAEA,KAAK,CAACwD,CAAC;EAAE,CACjB,CACF,CACQ,CAAC,eACZtE,KAAA,CAAA4C,aAAA,CAACrC,OAAO;IAACkE,IAAI,EAAE;EAAE,CAAE,CAAC,EACnB9C,QAAQ,IAAIP,YAAY,iBACvBpB,KAAA,CAAA4C,aAAA,CAACvC,UAAU;IAACqE,KAAK,EAAC,WAAW;IAAC5B,KAAK,EAAE;MAAE6B,SAAS,EAAE;IAAS;EAAE,GAC1DvD,YACS,CAED,CAAC;AAEpB,CACF,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
2
3
|
type Props = {
|
|
3
4
|
value: string;
|
|
4
5
|
onValueChange: (value: string) => void;
|
|
@@ -7,6 +8,9 @@ type Props = {
|
|
|
7
8
|
autocomplete?: boolean;
|
|
8
9
|
onValidate?: (value: string) => boolean;
|
|
9
10
|
errorMessage?: string;
|
|
11
|
+
accessibilityLabel?: string;
|
|
12
|
+
accessibilityHint?: string;
|
|
13
|
+
inputAccessoryViewID?: string;
|
|
10
14
|
};
|
|
11
15
|
/**
|
|
12
16
|
* `OTPInput` is a component that allows the user to enter a one-time password.
|
|
@@ -21,6 +25,6 @@ type Props = {
|
|
|
21
25
|
* @param errorMessage - The error message to display
|
|
22
26
|
* @returns
|
|
23
27
|
*/
|
|
24
|
-
export declare const OTPInput:
|
|
28
|
+
export declare const OTPInput: React.ForwardRefExoticComponent<Props & React.RefAttributes<View>>;
|
|
25
29
|
export {};
|
|
26
30
|
//# sourceMappingURL=OTPInput.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OTPInput.d.ts","sourceRoot":"","sources":["../../../../src/components/otpInput/OTPInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"OTPInput.d.ts","sourceRoot":"","sources":["../../../../src/components/otpInput/OTPInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAwB,IAAI,EAAE,MAAM,cAAc,CAAC;AAS1D,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ,oEA8GpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { Pressable, TextInput } from "react-native";
|
|
2
|
+
import { Pressable, TextInput, View } from "react-native";
|
|
3
3
|
import Animated from "react-native-reanimated";
|
|
4
4
|
import { IOStyles } from "../../core/IOStyles";
|
|
5
5
|
import { LabelSmall } from "../typography";
|
|
@@ -16,6 +16,9 @@ type Props = {
|
|
|
16
16
|
autocomplete?: boolean;
|
|
17
17
|
onValidate?: (value: string) => boolean;
|
|
18
18
|
errorMessage?: string;
|
|
19
|
+
accessibilityLabel?: string;
|
|
20
|
+
accessibilityHint?: string;
|
|
21
|
+
inputAccessoryViewID?: string;
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
/**
|
|
@@ -31,105 +34,114 @@ type Props = {
|
|
|
31
34
|
* @param errorMessage - The error message to display
|
|
32
35
|
* @returns
|
|
33
36
|
*/
|
|
34
|
-
export const OTPInput = (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
export const OTPInput = React.forwardRef<View, Props>(
|
|
38
|
+
(
|
|
39
|
+
{
|
|
40
|
+
value,
|
|
41
|
+
onValueChange,
|
|
42
|
+
length,
|
|
43
|
+
accessibilityLabel,
|
|
44
|
+
accessibilityHint,
|
|
45
|
+
onValidate,
|
|
46
|
+
errorMessage = "",
|
|
47
|
+
secret = false,
|
|
48
|
+
autocomplete = false,
|
|
49
|
+
inputAccessoryViewID
|
|
50
|
+
},
|
|
51
|
+
ref
|
|
52
|
+
) => {
|
|
53
|
+
const [hasFocus, setHasFocus] = React.useState(false);
|
|
54
|
+
const [hasError, setHasError] = React.useState(false);
|
|
46
55
|
|
|
47
|
-
|
|
56
|
+
const { translate, animatedStyle, shakeAnimation } =
|
|
57
|
+
useErrorShakeAnimation();
|
|
48
58
|
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
const inputRef = React.createRef<TextInput>();
|
|
60
|
+
const timerRef = React.useRef<NodeJS.Timeout>();
|
|
51
61
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
const handleValidate = (val: string) => {
|
|
63
|
+
if (!onValidate || val.length < length) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const isValid = onValidate(val);
|
|
67
|
+
if (!isValid) {
|
|
68
|
+
setHasError(true);
|
|
69
|
+
triggerHaptic("notificationError");
|
|
70
|
+
// eslint-disable-next-line functional/immutable-data
|
|
71
|
+
translate.value = shakeAnimation();
|
|
62
72
|
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
if (timerRef.current) {
|
|
74
|
+
clearTimeout(timerRef.current);
|
|
75
|
+
}
|
|
76
|
+
// eslint-disable-next-line functional/immutable-data
|
|
77
|
+
timerRef.current = setTimeout(() => {
|
|
78
|
+
setHasError(false);
|
|
79
|
+
onValueChange("");
|
|
80
|
+
}, 500);
|
|
65
81
|
}
|
|
66
|
-
|
|
67
|
-
timerRef.current = setTimeout(() => {
|
|
68
|
-
setHasError(false);
|
|
69
|
-
setInputValue("");
|
|
70
|
-
onValueChange("");
|
|
71
|
-
}, 500);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
82
|
+
};
|
|
74
83
|
|
|
75
|
-
|
|
84
|
+
React.useEffect(() => () => clearTimeout(timerRef.current), []);
|
|
76
85
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
};
|
|
86
|
+
const handleChange = (value: string) => {
|
|
87
|
+
if (value.length > length) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
onValueChange(value);
|
|
91
|
+
handleValidate(value);
|
|
92
|
+
};
|
|
85
93
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
accessibilityLabel="OTP Input"
|
|
96
|
-
accessibilityValue={{ text: inputValue }}
|
|
97
|
-
>
|
|
98
|
-
<TextInput
|
|
99
|
-
value={inputValue}
|
|
100
|
-
onChangeText={handleChange}
|
|
101
|
-
style={{ position: "absolute", opacity: 0 }}
|
|
102
|
-
maxLength={length}
|
|
103
|
-
ref={inputRef}
|
|
104
|
-
onBlur={() => setHasFocus(false)}
|
|
105
|
-
keyboardType="numeric"
|
|
106
|
-
inputMode="numeric"
|
|
107
|
-
returnKeyType="done"
|
|
108
|
-
textContentType="oneTimeCode"
|
|
109
|
-
autoComplete={autocomplete ? "sms-otp" : undefined}
|
|
94
|
+
return (
|
|
95
|
+
<Animated.View style={[{ flexGrow: 1 }, animatedStyle]}>
|
|
96
|
+
<Pressable
|
|
97
|
+
onPress={() => {
|
|
98
|
+
inputRef.current?.focus();
|
|
99
|
+
setHasFocus(true);
|
|
100
|
+
}}
|
|
101
|
+
ref={ref}
|
|
102
|
+
style={[IOStyles.row, { justifyContent: "space-around" }]}
|
|
110
103
|
accessible={true}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
104
|
+
accessibilityLabel={accessibilityLabel}
|
|
105
|
+
accessibilityHint={accessibilityHint}
|
|
106
|
+
accessibilityValue={{ text: value }}
|
|
107
|
+
>
|
|
108
|
+
<TextInput
|
|
109
|
+
value={value}
|
|
110
|
+
onChangeText={handleChange}
|
|
111
|
+
style={{ position: "absolute", opacity: 0 }}
|
|
112
|
+
maxLength={length}
|
|
113
|
+
ref={inputRef}
|
|
114
|
+
onBlur={() => setHasFocus(false)}
|
|
115
|
+
keyboardType="numeric"
|
|
116
|
+
inputMode="numeric"
|
|
117
|
+
returnKeyType="done"
|
|
118
|
+
textContentType="oneTimeCode"
|
|
119
|
+
autoComplete={autocomplete ? "sms-otp" : undefined}
|
|
120
|
+
inputAccessoryViewID={inputAccessoryViewID}
|
|
121
|
+
accessible={true}
|
|
124
122
|
/>
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
123
|
+
{[...Array(length)].map((_, i) => (
|
|
124
|
+
<BoxedInput
|
|
125
|
+
key={i}
|
|
126
|
+
status={
|
|
127
|
+
hasError
|
|
128
|
+
? "error"
|
|
129
|
+
: hasFocus && value.length === i
|
|
130
|
+
? "focus"
|
|
131
|
+
: "default"
|
|
132
|
+
}
|
|
133
|
+
secret={secret}
|
|
134
|
+
value={value[i]}
|
|
135
|
+
/>
|
|
136
|
+
))}
|
|
137
|
+
</Pressable>
|
|
138
|
+
<VSpacer size={4} />
|
|
139
|
+
{hasError && errorMessage && (
|
|
140
|
+
<LabelSmall color="error-850" style={{ textAlign: "center" }}>
|
|
141
|
+
{errorMessage}
|
|
142
|
+
</LabelSmall>
|
|
143
|
+
)}
|
|
144
|
+
</Animated.View>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
);
|