66
77import React from 'react'
88import PropTypes from 'prop-types'
9- import { Input } from 'antd'
9+ import { Input , InputNumber } from 'antd'
1010import R from 'ramda'
1111
1212import FormItem from '../FormItem'
@@ -19,39 +19,73 @@ const debug = makeDebugger('c:FormInputer:index')
1919
2020const { TextArea } = Input
2121
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+ }
3971
4072FormInputer . propTypes = {
4173 // https://www.npmjs.com/package/prop-types
4274 onChange : PropTypes . func ,
4375 label : PropTypes . string ,
4476 value : PropTypes . string ,
45- textarea : PropTypes . bool ,
4677 note : PropTypes . string ,
78+ type : PropTypes . oneOf ( [ 'default' , 'textarea' , 'number' ] ) ,
79+ disabled : PropTypes . bool ,
4780}
4881
4982FormInputer . defaultProps = {
5083 onChange : debug ,
5184 value : '' ,
5285 label : '' ,
53- textarea : false ,
5486 note : '' ,
87+ type : 'default' ,
88+ disabled : false ,
5589}
5690
5791export default FormInputer
0 commit comments