@@ -16,7 +16,7 @@ type Props = {
16
16
focusStyle ?: Object ,
17
17
isDisabled ?: boolean ,
18
18
disabledStyle ?: Object ,
19
- hasErrored ?: boolean ,
19
+ hasErrored ?: boolean ,
20
20
errorStyle ?: Object ,
21
21
shouldAutoFocus ?: boolean ,
22
22
} ;
@@ -26,6 +26,8 @@ type State = {
26
26
otp : string [ ] ,
27
27
} ;
28
28
29
+ const isObject = obj => typeof obj === 'object' ;
30
+
29
31
class SingleOtpInput extends PureComponent < * > {
30
32
input : ?HTMLInputElement ;
31
33
@@ -56,6 +58,8 @@ class SingleOtpInput extends PureComponent<*> {
56
58
}
57
59
}
58
60
61
+ getClasses = ( ...classes ) => classes . filter ( c => ! isObject ( c ) && c !== false ) . join ( ' ' ) ;
62
+
59
63
render ( ) {
60
64
const {
61
65
separator,
@@ -76,6 +80,11 @@ class SingleOtpInput extends PureComponent<*> {
76
80
style = { Object . assign (
77
81
{ width : '1em' , textAlign : 'center' } ,
78
82
inputStyle ,
83
+ focus && isObject ( focusStyle ) && focusStyle ,
84
+ isDisabled && isObject ( disabledStyle ) && disabledStyle ,
85
+ hasErrored && isObject ( errorStyle ) && errorStyle
86
+ ) }
87
+ className = { this . getClasses (
79
88
focus && focusStyle ,
80
89
isDisabled && disabledStyle ,
81
90
hasErrored && errorStyle
@@ -251,7 +260,7 @@ class OtpInput extends Component<Props, State> {
251
260
const { containerStyle } = this . props ;
252
261
253
262
return (
254
- < div style = { { display : 'flex' , ... containerStyle } } >
263
+ < div style = { Object . assign ( { display : 'flex' } , isObject ( containerStyle ) && containerStyle ) } className = { ! isObject ( containerStyle ) && containerStyle } >
255
264
{ this . renderInputs ( ) }
256
265
</ div >
257
266
) ;
0 commit comments