-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.js
More file actions
78 lines (65 loc) · 1.61 KB
/
Button.js
File metadata and controls
78 lines (65 loc) · 1.61 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"use strict"
import React from 'react'
import classnames from 'classnames'
import getGrid from './higherorder/grid'
import { requireCss } from './themes'
requireCss('buttons')
@getGrid
class Button extends React.Component {
static displayName = 'Button'
static propTypes = {
children: React.PropTypes.any,
className: React.PropTypes.string,
disabled: React.PropTypes.bool,
onClick: React.PropTypes.func,
once: React.PropTypes.bool,
status: React.PropTypes.string,
style: React.PropTypes.object,
type: React.PropTypes.oneOf(['submit', 'button'])
}
componentWillReceiveProps(nextProps) {
if (nextProps.disabled !== this.props.disabled) {
this.setState({ disabled: nextProps.disabled })
}
}
state = {
disabled: this.props.disabled,
show: null
}
disable(elem) {
this.setState({ disabled: true, show: elem })
}
enable(elem) {
this.setState({ disabled: false, show: elem })
}
handleClick() {
if (this.props.onClick) {
this.props.onClick()
}
if (this.props.once) {
this.disable()
}
}
render() {
let status = this.props.status
if (status) {
status = `rct-button-${status}`
}
const className = classnames(
this.props.className,
this.getGrid(),
'rct-button',
status
)
return (
<button onClick={this.handleClick.bind(this)}
style={this.props.style}
disabled={this.state.disabled}
className={className}
type={this.props.type || "button"}>
{ this.state.show || this.props.children }
</button>
)
}
}
export default Button