11var React = require ( 'react' ) ;
2- var CssEvent = require ( './utils/css-event.js' ) ;
32var Classable = require ( './mixins/classable.js' ) ;
43var EnhancedButton = require ( './enhanced-button.jsx' ) ;
54var Paper = require ( './paper.jsx' ) ;
65var Ripple = require ( './ripple.jsx' ) ;
6+ var TouchRipple = require ( './ripples/touch-ripple.jsx' ) ;
77
88var RaisedButton = React . createClass ( {
99
@@ -12,7 +12,10 @@ var RaisedButton = React.createClass({
1212 propTypes : {
1313 className : React . PropTypes . string ,
1414 label : React . PropTypes . string . isRequired ,
15- onTouchTap : React . PropTypes . func ,
15+ onMouseDown : React . PropTypes . func ,
16+ onMouseUp : React . PropTypes . func ,
17+ onTouchEnd : React . PropTypes . func ,
18+ onTouchStart : React . PropTypes . func ,
1619 primary : React . PropTypes . bool ,
1720 secondary : React . PropTypes . bool
1821 } ,
@@ -27,22 +30,28 @@ var RaisedButton = React.createClass({
2730
2831 render : function ( ) {
2932 var {
30- className,
31- onTouchTap,
32- ...other } = this . props ,
33- classes = this . getClasses ( 'mui-raised-button' , {
34- 'mui-is-primary' : this . props . primary ,
35- 'mui-is-secondary' : ! this . props . primary && this . props . secondary
36- } ) ;
33+ label,
34+ primary,
35+ secondary,
36+ ...other } = this . props ;
37+ var classes = this . getClasses ( 'mui-raised-button' , {
38+ 'mui-is-primary' : this . props . primary ,
39+ 'mui-is-secondary' : ! this . props . primary && this . props . secondary
40+ } ) ;
3741
3842 return (
3943 < Paper className = { classes } zDepth = { this . state . zDepth } >
40- < EnhancedButton
41- { ...other }
44+ < EnhancedButton { ...other }
4245 className = "mui-raised-button-container"
43- onTouchTap = { this . _onTouchTap } >
46+ onMouseUp = { this . _handleMouseUp }
47+ onMouseDown = { this . _handleMouseDown }
48+ onTouchStart = { this . _handleTouchStart }
49+ onTouchEnd = { this . _handleTouchEnd } >
50+
51+ < TouchRipple
52+ className = "mui-raised-button-ripple"
53+ ref = "touchRipple" />
4454
45- < Ripple ref = "ripple" className = "mui-raised-button-ripple" />
4655 < Ripple className = "mui-raised-button-focus-ripple" />
4756 < span className = "mui-raised-button-label" > { this . props . label } </ span >
4857
@@ -51,22 +60,31 @@ var RaisedButton = React.createClass({
5160 ) ;
5261 } ,
5362
54- _onTouchTap : function ( e ) {
55- if ( ! this . props . disabled ) this . _animateButtonClick ( e ) ;
56- if ( this . props . onTouchTap ) this . props . onTouchTap ( e ) ;
63+ _handleMouseDown : function ( e ) {
64+ //only listen to left clicks
65+ if ( e . button === 0 ) {
66+ this . refs . touchRipple . start ( e ) ;
67+ this . setState ( { zDepth : this . state . initialZDepth + 1 } ) ;
68+ }
69+ if ( this . props . onMouseDown ) this . props . onMouseDown ( e ) ;
5770 } ,
5871
59- _animateButtonClick : function ( e ) {
60- var el = this . getDOMNode ( ) ;
61-
62- //animate the ripple
63- this . refs . ripple . animate ( e ) ;
72+ _handleMouseUp : function ( e ) {
73+ this . refs . touchRipple . end ( ) ;
74+ this . setState ( { zDepth : this . state . initialZDepth } ) ;
75+ if ( this . props . onMouseUp ) this . props . onMouseUp ( e ) ;
76+ } ,
6477
65- //animate the zdepth change
78+ _handleTouchStart : function ( e ) {
79+ this . refs . touchRipple . start ( e ) ;
6680 this . setState ( { zDepth : this . state . initialZDepth + 1 } ) ;
67- setTimeout ( function ( ) {
68- this . setState ( { zDepth : this . state . initialZDepth } ) ;
69- } . bind ( this ) , 450 ) ;
81+ if ( this . props . onTouchStart ) this . props . onTouchStart ( e ) ;
82+ } ,
83+
84+ _handleTouchEnd : function ( e ) {
85+ this . refs . touchRipple . end ( ) ;
86+ this . setState ( { zDepth : this . state . initialZDepth } ) ;
87+ if ( this . props . onTouchEnd ) this . props . onTouchEnd ( e ) ;
7088 }
7189
7290} ) ;
0 commit comments