-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Expand file tree
/
Copy pathraised-button.jsx
More file actions
104 lines (89 loc) · 2.94 KB
/
raised-button.jsx
File metadata and controls
104 lines (89 loc) · 2.94 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
var React = require('react');
var Classable = require('./mixins/classable');
var EnhancedButton = require('./enhanced-button');
var Paper = require('./paper');
var RaisedButton = React.createClass({
mixins: [Classable],
propTypes: {
className: React.PropTypes.string,
label: function(props, propName, componentName){
if (!props.children && !props.label) {
return new Error('Warning: Required prop `label` or `children` was not specified in `'+ componentName + '`.')
}
},
outerStyle: React.PropTypes.object,
style: React.PropTypes.object,
onMouseDown: React.PropTypes.func,
onMouseUp: React.PropTypes.func,
onMouseOut: React.PropTypes.func,
onTouchEnd: React.PropTypes.func,
onTouchStart: React.PropTypes.func,
primary: React.PropTypes.bool,
secondary: React.PropTypes.bool
},
getInitialState: function() {
var zDepth = this.props.disabled ? 0 : 1;
return {
zDepth: zDepth,
initialZDepth: zDepth
};
},
componentWillReceiveProps: function(nextProps) {
var zDepth = nextProps.disabled ? 0 : 1;
this.setState({
zDepth: zDepth,
initialZDepth: zDepth
});
},
render: function() {
var {
label,
primary,
secondary,
...other } = this.props;
var classes = this.getClasses('mui-raised-button', {
'mui-is-primary': !this.props.disabled && primary,
'mui-is-secondary': !this.props.disabled && !primary && secondary
});
var children;
if (label) children = <span className="mui-raised-button-label">{label}</span>;
else children = this.props.children;
return (
<Paper className={classes} zDepth={this.state.zDepth} style={this.props.outerStyle}>
<EnhancedButton {...other}
className="mui-raised-button-container"
onMouseUp={this._handleMouseUp}
onMouseDown={this._handleMouseDown}
onMouseOut={this._handleMouseOut}
onTouchStart={this._handleTouchStart}
onTouchEnd={this._handleTouchEnd}>
{children}
</EnhancedButton>
</Paper>
);
},
_handleMouseDown: function(e) {
//only listen to left clicks
if (e.button === 0) {
this.setState({ zDepth: this.state.initialZDepth + 1 });
}
if (this.props.onMouseDown) this.props.onMouseDown(e);
},
_handleMouseUp: function(e) {
this.setState({ zDepth: this.state.initialZDepth });
if (this.props.onMouseUp) this.props.onMouseUp(e);
},
_handleMouseOut: function(e) {
this.setState({ zDepth: this.state.initialZDepth });
if (this.props.onMouseOut) this.props.onMouseOut(e);
},
_handleTouchStart: function(e) {
this.setState({ zDepth: this.state.initialZDepth + 1 });
if (this.props.onTouchStart) this.props.onTouchStart(e);
},
_handleTouchEnd: function(e) {
this.setState({ zDepth: this.state.initialZDepth });
if (this.props.onTouchEnd) this.props.onTouchEnd(e);
}
});
module.exports = RaisedButton;