@@ -5,18 +5,31 @@ import {
5
5
Pressable ,
6
6
TextInput as RNTextInput ,
7
7
} from 'react-native' ;
8
+ import type { StyleProp , ViewStyle , TextStyle } from 'react-native' ;
8
9
import { TextInput , Text } from 'react-native-paper' ;
9
10
10
11
type OtpInputProps = {
11
12
maxLength : number ;
12
13
autoFocus ?: boolean ;
13
14
onPinReady ?: ( pin : string ) => void ;
15
+ containerStyle ?: StyleProp < ViewStyle > ;
16
+ otpContainerStyle ?: StyleProp < ViewStyle > ;
17
+ otpBoxStyle ?: StyleProp < ViewStyle > ;
18
+ otpTextStyle ?: StyleProp < TextStyle > ;
19
+ otpBorderColor ?: string ;
20
+ otpBorderFocusedColor ?: string ;
14
21
} ;
15
22
16
23
export default function OtpInput ( {
17
24
maxLength,
18
25
onPinReady,
19
26
autoFocus = true ,
27
+ containerStyle,
28
+ otpContainerStyle,
29
+ otpBoxStyle,
30
+ otpTextStyle,
31
+ otpBorderColor = '#F6F6F6' ,
32
+ otpBorderFocusedColor = '#6200EE' ,
20
33
} : OtpInputProps ) {
21
34
const [ isInputBoxFocused , setIsInputBoxFocused ] = React . useState ( autoFocus ) ;
22
35
const [ otp , setOtp ] = React . useState ( '' ) ;
@@ -46,7 +59,7 @@ export default function OtpInput({
46
59
setIsInputBoxFocused ( false ) ;
47
60
} ;
48
61
return (
49
- < View style = { styles . container } >
62
+ < View style = { containerStyle ? containerStyle : styles . container } >
50
63
< TextInput
51
64
mode = "outlined"
52
65
style = { styles . textInput }
@@ -61,24 +74,36 @@ export default function OtpInput({
61
74
keyboardType = "numeric"
62
75
autoFocus = { autoFocus }
63
76
/>
64
- < Pressable style = { styles . otpContainer } onPress = { handleOnPress } >
77
+ < Pressable
78
+ style = { otpContainerStyle ? otpContainerStyle : styles . otpContainer }
79
+ onPress = { handleOnPress }
80
+ >
65
81
{ boxArray . map ( ( _ , index ) => {
66
82
const isCurrentValue = index === otp . length ;
67
83
const isLastValue = index === maxLength - 1 ;
68
84
const isCodeComplete = otp . length === maxLength ;
69
85
70
86
const isValueFocused =
71
87
isCurrentValue || ( isLastValue && isCodeComplete ) ;
88
+
89
+ const otpBoxStyleObject = otpBoxStyle
90
+ ? ( otpBoxStyle as ViewStyle )
91
+ : styles . otpBox ;
92
+
72
93
return (
73
94
< View
74
95
key = { index }
75
96
style = { {
76
- ...styles . otpBox ,
97
+ ...otpBoxStyleObject ,
77
98
borderColor :
78
- isInputBoxFocused && isValueFocused ? '#6200EE' : '#F6F6F6' ,
99
+ isInputBoxFocused && isValueFocused
100
+ ? otpBorderFocusedColor
101
+ : otpBorderColor ,
79
102
} }
80
103
>
81
- < Text style = { styles . otpText } > { otp [ index ] || '' } </ Text >
104
+ < Text style = { otpTextStyle ? otpTextStyle : styles . otpText } >
105
+ { otp [ index ] || '' }
106
+ </ Text >
82
107
</ View >
83
108
) ;
84
109
} ) }
0 commit comments