Files
Iris/src/js/components/ConfirmationButton.js

70 lines
1.5 KiB
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react'
import FontAwesome from 'react-fontawesome'
export default class ConfirmationButton extends React.Component{
constructor(props) {
super(props);
this.state = {
2016-10-27 16:58:11 +13:00
timing_out: false,
confirming: false
}
2016-10-17 14:27:48 +13:00
this.confirming = false;
this.unconfirmTimer = false;
}
componentWillUnmount(){
clearTimeout( this.unconfirmTimer );
}
handleClick(e){
if( this.state.confirming ){
this.setState({ confirming: false });
this.props.onConfirm();
}else{
this.setState({ confirming: true });
}
}
2016-10-17 14:27:48 +13:00
handleMouseEnter(e){
2016-10-27 16:58:11 +13:00
this.setState({ timing_out: false });
2016-10-17 14:27:48 +13:00
clearTimeout( this.unconfirmTimer );
}
handleMouseLeave(e){
if( this.state.confirming ){
2016-10-27 16:58:11 +13:00
this.setState({ timing_out: true });
this.unconfirmTimer = setTimeout(
function(){
this.setState({ confirming: false });
}.bind(this),
2016-10-27 16:58:11 +13:00
2000
);
}
2016-10-17 14:27:48 +13:00
}
render(){
var className = 'button';
var content = this.props.content;
if( this.state.confirming ){
className += ' confirming';
content = this.props.confirmingContent;
2016-10-27 16:58:11 +13:00
if( this.state.timing_out ) className += ' timing-out';
}
if( this.props.className ) className += ' '+this.props.className
return (
2016-10-17 14:27:48 +13:00
<button
className={className}
onClick={ (e) => this.handleClick(e) }
onMouseLeave={ (e) => this.handleMouseLeave(e) }
onMouseEnter={ (e) => this.handleMouseEnter(e) }>
{ content }
</button>
);
}
}