Skip to content

Commit 1917acb

Browse files
feat: added style props
1 parent 5707dbb commit 1917acb

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/components/OtpInput.tsx

+30-5
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,31 @@ import {
55
Pressable,
66
TextInput as RNTextInput,
77
} from 'react-native';
8+
import type { StyleProp, ViewStyle, TextStyle } from 'react-native';
89
import { TextInput, Text } from 'react-native-paper';
910

1011
type OtpInputProps = {
1112
maxLength: number;
1213
autoFocus?: boolean;
1314
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;
1421
};
1522

1623
export default function OtpInput({
1724
maxLength,
1825
onPinReady,
1926
autoFocus = true,
27+
containerStyle,
28+
otpContainerStyle,
29+
otpBoxStyle,
30+
otpTextStyle,
31+
otpBorderColor = '#F6F6F6',
32+
otpBorderFocusedColor = '#6200EE',
2033
}: OtpInputProps) {
2134
const [isInputBoxFocused, setIsInputBoxFocused] = React.useState(autoFocus);
2235
const [otp, setOtp] = React.useState('');
@@ -46,7 +59,7 @@ export default function OtpInput({
4659
setIsInputBoxFocused(false);
4760
};
4861
return (
49-
<View style={styles.container}>
62+
<View style={containerStyle ? containerStyle : styles.container}>
5063
<TextInput
5164
mode="outlined"
5265
style={styles.textInput}
@@ -61,24 +74,36 @@ export default function OtpInput({
6174
keyboardType="numeric"
6275
autoFocus={autoFocus}
6376
/>
64-
<Pressable style={styles.otpContainer} onPress={handleOnPress}>
77+
<Pressable
78+
style={otpContainerStyle ? otpContainerStyle : styles.otpContainer}
79+
onPress={handleOnPress}
80+
>
6581
{boxArray.map((_, index) => {
6682
const isCurrentValue = index === otp.length;
6783
const isLastValue = index === maxLength - 1;
6884
const isCodeComplete = otp.length === maxLength;
6985

7086
const isValueFocused =
7187
isCurrentValue || (isLastValue && isCodeComplete);
88+
89+
const otpBoxStyleObject = otpBoxStyle
90+
? (otpBoxStyle as ViewStyle)
91+
: styles.otpBox;
92+
7293
return (
7394
<View
7495
key={index}
7596
style={{
76-
...styles.otpBox,
97+
...otpBoxStyleObject,
7798
borderColor:
78-
isInputBoxFocused && isValueFocused ? '#6200EE' : '#F6F6F6',
99+
isInputBoxFocused && isValueFocused
100+
? otpBorderFocusedColor
101+
: otpBorderColor,
79102
}}
80103
>
81-
<Text style={styles.otpText}>{otp[index] || ''}</Text>
104+
<Text style={otpTextStyle ? otpTextStyle : styles.otpText}>
105+
{otp[index] || ''}
106+
</Text>
82107
</View>
83108
);
84109
})}

0 commit comments

Comments
 (0)