UNPKG

1.17 kBJSXView Raw
1/*
2 * <Button
3 * className=string
4 * text=required string
5 * onClick=required func
6 * >
7 */
8
9var React = require("react");
10require("react/addons");
11var cx = React.addons.classSet;
12var PropTypes = React.PropTypes;
13
14var Button = React.createClass({
15
16 mixins: [ React.addons.PureRenderMixin ],
17
18 propTypes: {
19 text: PropTypes.string.isRequired,
20 onClick: PropTypes.func,
21 className: PropTypes.string,
22 value: PropTypes.any,
23 active: PropTypes.bool,
24 disabled: PropTypes.bool
25 },
26
27 getDefaultProps: function() {
28 return {
29 active: false,
30 disabled: false
31 };
32 },
33
34 onClick: function(e) {
35 e.preventDefault();
36 if( typeof( this.props.onClick ) !== 'undefined' ) {
37 this.props.onClick(e);
38 } else {
39 return void(0);
40 }
41
42 },
43
44 render: function() {
45 var className = cx({
46 "active": this.props.active
47 });
48
49 return (
50 <button
51 className={["cb-button", this.props.className, className].join(" ")}
52 onClick={this.onClick}
53 value={this.props.value}
54 disabled={this.props.disabled}
55 >
56 {this.props.text}
57 </button>
58 );
59 }
60});
61
62module.exports = Button;