6
6
7
7
import React from 'react'
8
8
import PropTypes from 'prop-types'
9
- import { Input } from 'antd'
9
+ import { Input , InputNumber } from 'antd'
10
10
import R from 'ramda'
11
11
12
12
import FormItem from '../FormItem'
@@ -19,39 +19,73 @@ const debug = makeDebugger('c:FormInputer:index')
19
19
20
20
const { TextArea} = Input
21
21
22
- const FormInputer = ( { label, textarea, value, onChange, note} ) => (
23
- < FormItem label = { label } >
24
- < FormInput >
25
- { textarea ?(
26
- < TextArea
27
- value = { value }
28
- placeholder = { value }
29
- autosize = { { minRows :3 , maxRows :6 } }
30
- onChange = { onChange }
31
- />
32
- ) :(
33
- < Input size = "default" value = { value } onChange = { onChange } />
34
- ) }
35
- { R . isEmpty ( note ) ?< div /> :< Note > { note } </ Note > }
36
- </ FormInput >
37
- </ FormItem >
38
- )
22
+ const FormInputer = ( { label, value, onChange, note, type, disabled} ) => {
23
+ switch ( type ) {
24
+ case 'number' :{
25
+ return (
26
+ < FormItem label = { label } >
27
+ < InputNumber
28
+ min = { 0 }
29
+ defaultValue = { 0 }
30
+ onChange = { onChange }
31
+ disabled = { disabled }
32
+ />
33
+ { R . isEmpty ( note ) ?< div /> :< Note > { note } </ Note > }
34
+ </ FormItem >
35
+ )
36
+ }
37
+ case 'textarea' :{
38
+ return (
39
+ < FormItem label = { label } >
40
+ < FormInput >
41
+ < TextArea
42
+ value = { value }
43
+ placeholder = { value }
44
+ autosize = { { minRows :3 , maxRows :6 } }
45
+ onChange = { onChange }
46
+ disabled = { disabled }
47
+ />
48
+ { R . isEmpty ( note ) ?< div /> :< Note > { note } </ Note > }
49
+ </ FormInput >
50
+ </ FormItem >
51
+ )
52
+ }
53
+
54
+ default :{
55
+ return (
56
+ < FormItem label = { label } >
57
+ < FormInput >
58
+ < Input
59
+ size = "default"
60
+ value = { value }
61
+ onChange = { onChange }
62
+ disabled = { disabled }
63
+ />
64
+ { R . isEmpty ( note ) ?< div /> :< Note > { note } </ Note > }
65
+ </ FormInput >
66
+ </ FormItem >
67
+ )
68
+ }
69
+ }
70
+ }
39
71
40
72
FormInputer . propTypes = {
41
73
// https://www.npmjs.com/package/prop-types
42
74
onChange :PropTypes . func ,
43
75
label :PropTypes . string ,
44
76
value :PropTypes . string ,
45
- textarea :PropTypes . bool ,
46
77
note :PropTypes . string ,
78
+ type :PropTypes . oneOf ( [ 'default' , 'textarea' , 'number' ] ) ,
79
+ disabled :PropTypes . bool ,
47
80
}
48
81
49
82
FormInputer . defaultProps = {
50
83
onChange :debug ,
51
84
value :'' ,
52
85
label :'' ,
53
- textarea :false ,
54
86
note :'' ,
87
+ type :'default' ,
88
+ disabled :false ,
55
89
}
56
90
57
91
export default FormInputer