react-toolbox/components/button/index.jsx

67 lines
2.0 KiB
React
Raw Normal View History

import React from 'react';
import FontIcon from '../font_icon';
import Ripple from '../ripple';
2015-11-04 18:28:11 +03:00
import Tooltip from '../tooltip';
2015-10-23 02:26:12 +03:00
import style from './style';
2015-10-06 23:08:37 +03:00
import events from '../utils/events';
2015-10-22 02:31:17 +03:00
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,
2015-11-04 18:28:11 +03:00
tooltip: React.PropTypes.string,
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
};
2015-10-22 02:31:17 +03:00
handleMouseDown = (event) => {
2015-10-06 23:08:37 +03:00
events.pauseEvent(event);
if (this.refs.ripple) this.refs.ripple.start(event);
if (this.props.onMouseDown) this.props.onMouseDown(event);
2015-10-22 11:02:36 +03:00
};
render () {
2015-10-21 01:48:24 +03:00
let className = style[this.props.kind];
2015-11-04 18:28:11 +03:00
const {label, icon, loading, ripple, primary, accent, mini, kind, tooltip, ...others} = this.props;
2015-10-04 16:12:53 +03:00
if (this.props.className) className += ` ${this.props.className}`;
if (!primary && !accent) className += ` ${style.primary}`;
if (primary) className += ` ${style.primary}`;
if (accent) className += ` ${style.accent}`;
if (mini) className += ` ${style.mini}`;
2015-10-04 16:12:53 +03:00
return (
<button
data-react-toolbox='button'
{...others}
2015-10-04 16:12:53 +03:00
className={className}
2015-10-21 01:48:24 +03:00
disabled={this.props.disabled || this.props.loading}
2015-11-10 15:33:38 +03:00
onMouseDown={this.handleMouseDown}
>
{ ripple ? <Ripple ref='ripple' loading={loading}/> : null }
{ icon ? <FontIcon className={style.icon} value={icon}/> : null }
{ label ? <abbr className={style.label}>{label}</abbr> : null }
2015-11-04 18:28:11 +03:00
{ tooltip ? <Tooltip label={tooltip}/> : null }
</button>
);
}
2015-10-21 05:58:11 +03:00
}
2015-10-22 02:31:17 +03:00
export default Button;