react-toolbox/components/button/index.jsx

63 lines
1.9 KiB
React
Raw Normal View History

import React from 'react';
2015-10-21 13:25:07 +03:00
import autobind from 'autobind-decorator';
import FontIcon from '../font_icon';
import Ripple from '../ripple';
import style from './style.scss';
2015-10-06 23:08:37 +03:00
import events from '../utils/events';
2015-10-21 09:13:24 +03:00
@autobind
export default class Button extends React.Component {
static propTypes = {
2015-10-21 01:48:24 +03:00
accent: React.PropTypes.bool,
className: React.PropTypes.string,
disabled: React.PropTypes.bool,
icon: React.PropTypes.string,
2015-10-21 01:48:24 +03:00
kind: React.PropTypes.string,
label: React.PropTypes.string,
loading: React.PropTypes.bool,
2015-10-21 01:48:24 +03:00
mini: React.PropTypes.bool,
primary: React.PropTypes.bool,
ripple: React.PropTypes.bool,
type: React.PropTypes.string
};
static defaultProps = {
2015-10-21 05:58:11 +03:00
accent: false,
className: '',
2015-10-21 05:58:11 +03:00
kind: 'flat',
loading: false,
mini: false,
primary: false,
ripple: true
};
handleMouseDown (event) {
2015-10-06 23:08:37 +03:00
events.pauseEvent(event);
this.refs.ripple.start(event);
}
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
return (
<button
{...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'
onMouseDown={this.handleMouseDown}
2015-10-21 01:48:24 +03:00
disabled={this.props.disabled || this.props.loading}
>
{ 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 }
</button>
);
}
2015-10-21 05:58:11 +03:00
}