-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (53 loc) · 1.56 KB
/
index.js
File metadata and controls
56 lines (53 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React, { Component, PropTypes } from 'react'
import CSSModules from 'react-css-modules'
import styles from './index.styl'
@CSSModules(styles, { allowMultiple: true, errorWhenNotFound: false })
export default class extends Component {
static propTypes = {
inputWidth: PropTypes.string,
labelWidth: PropTypes.string,
value: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),
onChange: PropTypes.func,
onBlur: PropTypes.func,
disabled: PropTypes.bool,
required: PropTypes.bool,
limited: PropTypes.number
}
static defaultProps = {
inputWidth: '200px'
}
handleChange (e) {
this.props.onChange(e)
}
handleBlur (e) {
if (this.props.limited) {
e.target.value = e.target.value.substr(0, this.props.limited)
this.props.onChange(e)
}
if (typeof this.props.onBlur === 'function') {
this.props.onBlur(e)
}
}
render () {
return (
<div styleName='InputOuter'>
<label styleName='labelContainer'>
{
this.props.label
? <span styleName={this.props.required ? 'label required' : 'label'} style={Object.assign({}, {width: this.props.labelWidth})}>{this.props.label}</span>
: <span></span>
}
<div styleName='inputContainer'>
<input
{ ...this.props }
style={Object.assign({}, {width: this.props.inputWidth})}
onChange={this.handleChange.bind(this)}
onBlur={this.handleBlur.bind(this)} /></div>
</label>
</div>
)
}
}