11import React , { forwardRef , LegacyRef } from "react" ;
2- import { TextInput , View , TextInputProps , Text , TouchableOpacity , StyleProp , TextStyle } from 'react-native' ;
2+ import { TextInput , View , TextInputProps , Text , TouchableOpacity , StyleProp , TextStyle } from 'react-native' ;
33import { MaterialIcons , FontAwesome , Octicons } from '@expo/vector-icons' ;
4- import { themas } from "../../global/themes" ;
54import { style } from "./styles" ;
65
76type IconComponent = React . ComponentType < React . ComponentProps < typeof MaterialIcons > > |
87 React . ComponentType < React . ComponentProps < typeof FontAwesome > > |
98 React . ComponentType < React . ComponentProps < typeof Octicons > > ;
109
1110type Props = TextInputProps & {
12- IconLeft ?: IconComponent ,
13- IconRigth ?: IconComponent ,
14- iconLeftName ?: string ,
15- iconRightName ?: string ,
16- title ?: string ,
17- onIconLeftPress ?: ( ) => void ,
18- onIconRigthPress ?: ( ) => void ,
19- height ?:number ,
20- labelStyle ?:StyleProp < TextStyle >
21- }
11+ IconLeft ?: IconComponent ;
12+ IconRigth ?: IconComponent ;
13+ iconLeftName ?: string ;
14+ iconRightName ?: string ;
15+ title ?: string ;
16+ onIconLeftPress ?: ( ) => void ;
17+ onIconRigthPress ?: ( ) => void ;
18+ height ?: number ;
19+ labelStyle ?: StyleProp < TextStyle > ;
20+ /** sinaliza erro para borda e texto */
21+ error ?: boolean ;
22+ } ;
2223
2324export const Input = forwardRef ( ( props : Props , ref : LegacyRef < TextInput > | null ) => {
24- const { IconLeft, IconRigth, iconLeftName, iconRightName, title, onIconLeftPress, onIconRigthPress, height, labelStyle, ...rest } = props ;
25-
25+ const { IconLeft, IconRigth, iconLeftName, iconRightName, title, onIconLeftPress, onIconRigthPress, height, labelStyle, error = false , ...rest } = props ;
2626
2727 return (
2828 < >
2929 { title && < Text style = { style . inputTitle } > { title } </ Text > }
3030 < View style = { style . inputContainer } >
31- { IconLeft && iconLeftName && (
32- < TouchableOpacity onPress = { onIconLeftPress } >
33- < IconLeft name = { iconLeftName as any } size = { 20 } color = { '#888' } style = { style . iconRight } />
34- </ TouchableOpacity >
35- ) }
31+ < View style = { [
32+ style . inputWrapper ,
33+ error && style . erroInput ,
34+ height ? { height } : undefined
35+ ] } >
36+ { IconLeft && iconLeftName && (
37+ < TouchableOpacity onPress = { onIconLeftPress } >
38+ < IconLeft name = { iconLeftName as any } size = { 20 } color = "#888" style = { style . iconRight } />
39+ </ TouchableOpacity >
40+ ) }
3641
37- < View style = { style . inputWrapper } >
38- < TextInput
39- style = { style . input }
42+ < TextInput
4043 ref = { ref }
44+ style = { style . input }
4145 multiline = { rest . multiline ?? false }
4246 { ...rest }
4347 />
4448
4549 { IconRigth && iconRightName && (
4650 < TouchableOpacity onPress = { onIconRigthPress } >
47- < IconRigth name = { iconRightName as any } size = { 24 } color = { ' #888' } style = { style . iconRight } />
51+ < IconRigth name = { iconRightName as any } size = { 24 } color = " #888" style = { style . iconRight } />
4852 </ TouchableOpacity >
4953 ) }
5054 </ View >
55+ { error && < Text style = { style . erroTexto } > Campo inválido</ Text > }
5156 </ View >
52-
5357 </ >
5458 ) ;
5559} ) ;
0 commit comments