-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.jsx
38 lines (34 loc) · 1.05 KB
/
index.jsx
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
import React, {PropTypes, Component} from 'react'
import {addons} from 'react/addons'
import omit from 'lodash/object/omit'
const {shouldComponentUpdate} = addons.PureRenderMixin
const namespace = 'btn'
export default class Button extends Component {
// use the pure-render mixin without the mixin. This allows us to use es6
// classes and avoid "magic" code
shouldComponentUpdate (...args) {
return shouldComponentUpdate.apply(this, args)
}
render () {
const classes = [namespace].concat(this.props.classes)
return (
<button {...omit(this.props, 'text')} className={classes.join(' ')}>
<span className="btn-label">{this.props.text}</span>
</button>
)
}
}
Button.propTypes = {
text: PropTypes.string.isRequired
, classes: PropTypes.array.isRequired
, onClick: (props, propName) => {
if (props.type !== 'submit' && !props[propName]) {
return new Error('if the type is not `submit`, you must define onClick')
}
}
, type: PropTypes.string
}
Button.defaultProps = {
text: 'Submit'
, classes: []
}