6
6
TextInputProps ,
7
7
TextStyle ,
8
8
View ,
9
- ViewProps ,
10
9
} from 'react-native' ;
11
10
import {
12
11
allWithRest ,
@@ -23,26 +22,24 @@ import {
23
22
Text as TextComponent ,
24
23
Props as TextProps ,
25
24
} from '../text/text.component' ;
26
- import { TextStyleProps } from '@kitten/ui/common/props' ;
25
+ import {
26
+ TextStyleProps ,
27
+ FlexStyleProps ,
28
+ } from '../common/props' ;
27
29
28
30
const Text = styled < TextProps > ( TextComponent ) ;
29
31
30
32
type IconElement = React . ReactElement < ImageProps > ;
31
- type LabelElement = React . ReactElement < TextProps > ;
32
-
33
- interface CaptionStyles {
34
- container : StyleType ;
35
- text : StyleType ;
36
- icon : StyleType ;
37
- }
33
+ type TextElement = React . ReactElement < TextProps > ;
34
+ type IconProp = ( style : StyleType ) => React . ReactElement < ImageProps > ;
38
35
39
36
interface InputProps {
40
37
status ?: string ;
41
38
disabled ?: boolean ;
42
39
label ?: string ;
43
40
caption ?: string ;
44
- captionIcon ?: ( style : StyleType ) => React . ReactElement < ImageProps > ;
45
- icon ?: ( style : StyleType ) => React . ReactElement < ImageProps > ;
41
+ captionIcon ?: IconProp ;
42
+ icon ?: IconProp ;
46
43
}
47
44
48
45
export type Props = InputProps & StyledComponentProps & TextInputProps ;
@@ -67,7 +64,8 @@ export class Input extends React.Component<Props> {
67
64
68
65
private getComponentStyle = ( style : StyleType ) : StyleType => {
69
66
const derivedStyle : TextStyle = StyleSheet . flatten ( this . props . style ) ;
70
- const { rest : derivedContainerStyle , ...derivedTextStyle } = allWithRest ( derivedStyle , TextStyleProps ) ;
67
+ const { rest : containerStyle , ...derivedTextStyle } = allWithRest ( derivedStyle , TextStyleProps ) ;
68
+ const { rest : inputContainerStyle , ...derivedContainerStyle } = allWithRest ( containerStyle , FlexStyleProps ) ;
71
69
72
70
const {
73
71
textMarginHorizontal,
@@ -97,12 +95,17 @@ export class Input extends React.Component<Props> {
97
95
98
96
return {
99
97
container : {
100
- ...derivedContainerStyle ,
101
98
...styles . container ,
99
+ ...derivedContainerStyle ,
102
100
} ,
103
101
inputContainer : {
104
102
...containerParameters ,
105
103
...styles . inputContainer ,
104
+ ...inputContainerStyle ,
105
+ } ,
106
+ captionContainer : {
107
+ marginTop : captionMarginTop ,
108
+ ...styles . captionContainer ,
106
109
} ,
107
110
text : {
108
111
marginHorizontal : textMarginHorizontal ,
@@ -127,80 +130,59 @@ export class Input extends React.Component<Props> {
127
130
fontWeight : labelFontWeight ,
128
131
...styles . label ,
129
132
} ,
130
- caption : {
131
- text : {
132
- color : captionTextColor ,
133
- fontSize : captionTextFontSize ,
134
- fontWeight : captionTextFontWeight ,
135
- lineHeight : captionTextLineHeight ,
136
- } ,
137
- icon : {
138
- width : captionIconWidth ,
139
- height : captionIconHeight ,
140
- tintColor : captionIconTintColor ,
141
- marginRight : captionIconMarginRight ,
142
- } ,
143
- container : {
144
- marginTop : captionMarginTop ,
145
- ...styles . captionContainer ,
146
- } ,
133
+ captionIcon : {
134
+ width : captionIconWidth ,
135
+ height : captionIconHeight ,
136
+ tintColor : captionIconTintColor ,
137
+ marginRight : captionIconMarginRight ,
138
+ ...styles . captionIcon ,
139
+ } ,
140
+ captionLabel : {
141
+ fontSize : captionTextFontSize ,
142
+ fontWeight : captionTextFontWeight ,
143
+ lineHeight : captionTextLineHeight ,
144
+ color : captionTextColor ,
145
+ ...styles . captionLabel ,
147
146
} ,
148
147
} ;
149
148
} ;
150
149
151
- private renderIconElement = ( style : StyleType ,
152
- icon : ( style : StyleType ) => IconElement ) : IconElement | null => {
153
-
154
- return icon ? icon ( style ) : null ;
150
+ private renderIconElement = ( style : StyleType , icon : IconProp ) : IconElement => {
151
+ return icon ( style ) ;
155
152
} ;
156
153
157
- private renderTextElement = ( style : StyleType , text : string ) : LabelElement => {
154
+ private renderTextElement = ( style : StyleType , text : string ) : TextElement => {
158
155
return (
159
156
< Text style = { style } > { text } </ Text >
160
157
) ;
161
158
} ;
162
159
163
- private renderText = ( style : StyleType , text : string ) : LabelElement | null => {
164
- const hasText : boolean = text && text . length !== 0 ;
165
-
166
- return hasText ? this . renderTextElement ( style , text ) : null ;
167
- } ;
160
+ public render ( ) : React . ReactElement < TextInputProps > {
161
+ const { themedStyle, disabled, label, icon, caption, captionIcon, ...restProps } = this . props ;
162
+ const style : StyleType = this . getComponentStyle ( themedStyle ) ;
168
163
169
- private renderCaptionElement = ( style : CaptionStyles ) : React . ReactElement < ViewProps > | null => {
170
- const { caption , captionIcon } = this . props ;
171
- const icon : IconElement | null = this . renderIconElement ( style . icon , captionIcon ) ;
172
- const text : LabelElement | null = this . renderText ( style . text , caption ) ;
164
+ const iconElement : IconElement = icon ? this . renderIconElement ( style . icon , icon ) : null ;
165
+ const labelElement : TextElement = label ? this . renderTextElement ( style . label , label ) : null ;
166
+ const captionIconElement : IconElement = captionIcon ? this . renderIconElement ( style . captionIcon , captionIcon ) : null ;
167
+ const captionLabelElement : TextElement = caption ? this . renderTextElement ( style . captionLabel , caption ) : null ;
173
168
174
169
return (
175
170
< View style = { style . container } >
176
- { icon }
177
- { text }
178
- </ View >
179
- ) ;
180
- } ;
181
-
182
- public render ( ) : React . ReactElement < TextInputProps > {
183
- const { themedStyle, disabled, label, icon, ...restProps } = this . props ;
184
- const componentStyle : StyleType = this . getComponentStyle ( themedStyle ) ;
185
- const inputIcon : IconElement | null = this . renderIconElement ( componentStyle . icon , icon ) ;
186
- const inputLabel : LabelElement | null = this . renderText ( componentStyle . label , label ) ;
187
- const caption : React . ReactElement < ViewProps > | null =
188
- this . renderCaptionElement ( componentStyle . caption ) ;
189
-
190
- return (
191
- < View style = { componentStyle . container } >
192
- { inputLabel }
193
- < View style = { componentStyle . inputContainer } >
171
+ { labelElement }
172
+ < View style = { style . inputContainer } >
194
173
< TextInput
195
174
{ ...restProps }
175
+ style = { style . text }
196
176
editable = { ! disabled }
197
177
onFocus = { this . onFocus }
198
178
onEndEditing = { this . onEndEditing }
199
- style = { componentStyle . text }
200
179
/>
201
- { inputIcon }
180
+ { iconElement }
181
+ </ View >
182
+ < View style = { style . captionContainer } >
183
+ { captionIconElement }
184
+ { captionLabelElement }
202
185
</ View >
203
- { caption }
204
186
</ View >
205
187
) ;
206
188
}
@@ -214,13 +196,15 @@ const styles = StyleSheet.create({
214
196
flexDirection : 'row' ,
215
197
alignItems : 'center' ,
216
198
} ,
199
+ captionContainer : {
200
+ flexDirection : 'row' ,
201
+ alignItems : 'center' ,
202
+ } ,
217
203
text : {
218
204
flex : 1 ,
219
205
} ,
220
206
icon : { } ,
221
207
label : { } ,
222
- captionContainer : {
223
- flexDirection : 'row' ,
224
- alignItems : 'center' ,
225
- } ,
208
+ captionIcon : { } ,
209
+ captionLabel : { } ,
226
210
} ) ;
0 commit comments