11import * as React from 'react'
2- import {
3- View ,
4- Text ,
5- TextInput ,
6- TextInputIOSProps ,
7- NativeSyntheticEvent ,
8- TextInputKeyPressEventData ,
9- } from 'react-native'
2+ import { View , Text , TextInput , TextInputProps } from 'react-native'
103import styled , { css } from 'styled-components'
114
125const Base = styled ( TextInput ) < {
@@ -25,6 +18,7 @@ const Base = styled(TextInput)<{
2518 font-weight: 900;
2619 color: var(--dark-blue);
2720 letter-spacing: -0.91px;
21+ outline: none;
2822 transition: box-shadow 0.3s ease;
2923
3024 ${ props =>
@@ -45,63 +39,46 @@ const Label = styled(Text)`
4539 letter-spacing: -0.61px;
4640`
4741
48- interface InputProps {
42+ interface InputProps extends TextInputProps {
4943 style ?: any
5044 inputStyle ?: any
5145 name ?: string
5246 label ?: string
53- placeholder ?: string
54- value ?: string
55- onChangeText : ( text : string ) => void
56- onBlur ?: ( e : any ) => void
57- onFocus ?: ( e : any ) => void
58- onKeyPress ?: ( e : NativeSyntheticEvent < TextInputKeyPressEventData > ) => void
5947 secure ?: boolean
60- focused ?: boolean
6148 focusable ?: boolean
62- textContentType ?: TextInputIOSProps [ 'textContentType' ]
6349}
6450
6551const Input = React . forwardRef (
66- (
67- {
68- style,
69- inputStyle,
70- name,
71- label,
72- placeholder,
73- value,
74- onChangeText,
75- onBlur,
76- onFocus,
77- onKeyPress,
78- secure,
79- focused,
80- focusable,
81- textContentType,
82- } : InputProps ,
83- ref
84- ) => (
85- < View style = { style } >
86- { label && < Label > { label } </ Label > }
87- < Base
88- innerRef = { ref }
89- style = { inputStyle }
90- name = { name }
91- value = { value }
92- onChangeText = { onChangeText }
93- onBlur = { onBlur }
94- onFocus = { onFocus }
95- onKeyPress = { onKeyPress }
96- placeholder = { placeholder }
97- placeholderTextColor = "var(--dark-moderate-blue-30)"
98- textContentType = { textContentType }
99- secureTextEntry = { secure }
100- focused = { focused }
101- focusable = { focusable }
102- />
103- </ View >
104- )
52+ ( { style, inputStyle, name, label, secure, focusable, ...props } : InputProps , ref ) => {
53+ const [ focused , setFocused ] = React . useState ( false )
54+ return (
55+ < View style = { style } >
56+ { label && < Label > { label } </ Label > }
57+ < Base
58+ { ...props }
59+ innerRef = { ref }
60+ style = { inputStyle }
61+ name = { name }
62+ placeholderTextColor = "var(--dark-moderate-blue-30)"
63+ secureTextEntry = { secure }
64+ focused = { focused }
65+ focusable = { focusable }
66+ onFocus = { e => {
67+ setFocused ( true )
68+ if ( props . onFocus ) {
69+ props . onFocus ( e )
70+ }
71+ } }
72+ onBlur = { e => {
73+ setFocused ( false )
74+ if ( props . onBlur ) {
75+ props . onBlur ( e )
76+ }
77+ } }
78+ />
79+ </ View >
80+ )
81+ }
10582)
10683
10784export default Input
0 commit comments