2015-10-11 20:07:09 +03:00
|
|
|
import React from 'react';
|
2015-10-21 13:25:07 +03:00
|
|
|
import autobind from 'autobind-decorator';
|
2015-09-18 22:03:08 +03:00
|
|
|
import FontIcon from '../font_icon';
|
|
|
|
import Ripple from '../ripple';
|
2015-10-02 18:39:26 +03:00
|
|
|
import style from './style.scss';
|
2015-10-06 23:08:37 +03:00
|
|
|
import events from '../utils/events';
|
2015-09-18 22:03:08 +03:00
|
|
|
|
2015-10-21 09:13:24 +03:00
|
|
|
@autobind
|
2015-10-20 08:40:51 +03:00
|
|
|
export default class Button extends React.Component {
|
|
|
|
static propTypes = {
|
2015-10-21 01:48:24 +03:00
|
|
|
accent: React.PropTypes.bool,
|
2015-09-18 22:03:08 +03:00
|
|
|
className: React.PropTypes.string,
|
|
|
|
disabled: React.PropTypes.bool,
|
|
|
|
icon: React.PropTypes.string,
|
2015-10-21 01:48:24 +03:00
|
|
|
kind: React.PropTypes.string,
|
2015-09-18 22:03:08 +03:00
|
|
|
label: React.PropTypes.string,
|
|
|
|
loading: React.PropTypes.bool,
|
2015-10-21 01:48:24 +03:00
|
|
|
mini: React.PropTypes.bool,
|
|
|
|
primary: React.PropTypes.bool,
|
2015-09-18 22:03:08 +03:00
|
|
|
ripple: React.PropTypes.bool,
|
|
|
|
type: React.PropTypes.string
|
2015-10-20 08:40:51 +03:00
|
|
|
};
|
2015-09-18 22:03:08 +03:00
|
|
|
|
2015-10-20 08:40:51 +03:00
|
|
|
static defaultProps = {
|
2015-10-21 05:58:11 +03:00
|
|
|
accent: false,
|
2015-10-20 08:40:51 +03:00
|
|
|
className: '',
|
2015-10-21 05:58:11 +03:00
|
|
|
kind: 'flat',
|
|
|
|
loading: false,
|
|
|
|
mini: false,
|
|
|
|
primary: false,
|
|
|
|
ripple: true
|
2015-10-20 08:40:51 +03:00
|
|
|
};
|
2015-09-18 22:03:08 +03:00
|
|
|
|
2015-10-02 18:39:26 +03:00
|
|
|
handleMouseDown (event) {
|
2015-10-06 23:08:37 +03:00
|
|
|
events.pauseEvent(event);
|
2015-10-02 18:39:26 +03:00
|
|
|
this.refs.ripple.start(event);
|
2015-10-20 08:40:51 +03:00
|
|
|
}
|
2015-09-18 22:03:08 +03:00
|
|
|
|
2015-10-02 18:39:26 +03:00
|
|
|
render () {
|
2015-10-21 01:48:24 +03:00
|
|
|
let className = style[this.props.kind];
|
|
|
|
if (!this.props.primary && !this.props.accent) className += ` ${style.primary}`;
|
2015-10-04 16:12:53 +03:00
|
|
|
if (this.props.className) className += ` ${this.props.className}`;
|
2015-10-21 01:48:24 +03:00
|
|
|
if (this.props.primary) className += ` ${style.primary}`;
|
|
|
|
if (this.props.accent) className += ` ${style.accent}`;
|
|
|
|
if (this.props.mini) className += ` ${style.mini}`;
|
2015-10-04 16:12:53 +03:00
|
|
|
|
2015-09-18 22:03:08 +03:00
|
|
|
return (
|
|
|
|
<button
|
2015-10-02 23:08:02 +03:00
|
|
|
{...this.props}
|
|
|
|
label=''
|
2015-10-04 16:12:53 +03:00
|
|
|
className={className}
|
2015-10-21 01:48:24 +03:00
|
|
|
data-react-toolbox='button'
|
2015-10-02 18:39:26 +03:00
|
|
|
onMouseDown={this.handleMouseDown}
|
2015-10-21 01:48:24 +03:00
|
|
|
disabled={this.props.disabled || this.props.loading}
|
2015-09-18 22:03:08 +03:00
|
|
|
>
|
2015-10-02 18:39:26 +03:00
|
|
|
{ this.props.ripple ? <Ripple ref='ripple' loading={this.props.loading}/> : null }
|
2015-10-04 16:12:53 +03:00
|
|
|
{ this.props.icon ? <FontIcon className={style.icon} value={this.props.icon}/> : null }
|
|
|
|
{ this.props.label ? <abbr className={style.label}>{this.props.label}</abbr> : null }
|
2015-09-18 22:03:08 +03:00
|
|
|
</button>
|
|
|
|
);
|
2015-10-20 08:40:51 +03:00
|
|
|
}
|
2015-10-21 05:58:11 +03:00
|
|
|
}
|