1
1
import React from 'react' ;
2
2
import { View , Text , TextInputProps , StyleProp } from 'react-native' ;
3
3
import sb from 'react-native-style-block' ;
4
- import TInput , { TInputProps } from './TInput' ;
4
+ import TInput from './TInput' ;
5
+ import styled from 'styled-components/native' ;
6
+
7
+ const FormContainer = styled . View `
8
+ flex-direction: row;
9
+ align-items: center;
10
+ border-bottom: 0.5px solid #ccc;
11
+ margin-bottom: 10px;
12
+ height: 44px;
13
+ ` ;
14
+
15
+ const FormLabel = styled . Text `
16
+ margin-right: 10px;
17
+ flex: 1;
18
+ text-align: right;
19
+ font-size: 16px;
20
+ min-width: 80px;
21
+ height: 32px;
22
+ line-height: 32px;
23
+ ` ;
24
+
25
+ const FormInput = styled ( TInput ) `
26
+ flex: 3;
27
+ border: 0;
28
+ background-color: transparent;
29
+ font-size: 16px;
30
+ ` ;
5
31
6
32
interface Props {
7
33
label : string ;
8
34
value : string ;
9
35
style : StyleProp < View > ;
10
- input : TInputProps ;
36
+ input : TextInputProps ;
11
37
onChangeText : ( text : string ) => void ;
12
38
}
13
-
14
39
class TFormGroup extends React . Component < Props > {
15
40
static defaultProps = {
16
41
label : '' ,
@@ -25,43 +50,16 @@ class TFormGroup extends React.Component<Props> {
25
50
this . props . input . style = [ ] ;
26
51
}
27
52
return (
28
- < View
29
- { ...this . props }
30
- style = { [ ...styles . container , ...( this . props . style as any ) ] }
31
- >
32
- < Text style = { styles . label } > { this . props . label } :</ Text >
33
- < TInput
53
+ < FormContainer { ...( this . props as any ) } >
54
+ < FormLabel > { this . props . label } :</ FormLabel >
55
+ < FormInput
34
56
value = { this . props . value }
35
57
onChangeText = { ( text : string ) => this . props . onChangeText ( text ) }
36
58
{ ...this . props . input }
37
- style = { [ ...styles . input , ...this . props . input . style ] }
38
59
/>
39
- </ View >
60
+ </ FormContainer >
40
61
) ;
41
62
}
42
63
}
43
64
44
- const styles = {
45
- container : [
46
- sb . direction ( 'row' ) ,
47
- sb . alignCenter ( ) ,
48
- // sb.flex(),
49
- sb . border ( 'Bottom' , 0.5 , '#ccc' ) ,
50
- { marginBottom : 10 , height : 44 } ,
51
- ] ,
52
- label : [
53
- sb . margin ( 0 , 10 , 0 , 0 ) ,
54
- sb . flex ( 1 ) ,
55
- sb . textAlign ( 'right' ) ,
56
- sb . font ( 16 ) ,
57
- { minWidth : 80 , height : 32 , lineHeight : 32 } ,
58
- ] ,
59
- input : [
60
- sb . flex ( 3 ) ,
61
- sb . border ( 'all' , 0 ) ,
62
- sb . bgColor ( 'transparent' ) ,
63
- sb . font ( 16 ) ,
64
- ] ,
65
- } ;
66
-
67
65
export default TFormGroup ;
0 commit comments