2017-07-31 23:14:30 +00:00
|
|
|
import React, { Component } from 'react';
|
2017-09-25 02:06:28 +00:00
|
|
|
import Spinner from './Spinner';
|
2018-03-01 17:53:29 +00:00
|
|
|
import './SimpleButton.scss';
|
2017-07-31 23:14:30 +00:00
|
|
|
|
|
|
|
const DEFAULT_BUTTON_TYPE = 'primary';
|
|
|
|
const DEFAULT_BUTTON_SIZE = 'lg';
|
|
|
|
|
2017-12-11 20:17:44 +00:00
|
|
|
type ButtonType = 'default' | 'primary' | 'success' | 'info' | 'warning' | 'danger';
|
2017-07-31 23:14:30 +00:00
|
|
|
type ButtonSize = 'lg' | 'sm' | 'xs';
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
interface Props {
|
|
|
|
text: React.ReactElement<any> | string;
|
|
|
|
loading?: boolean;
|
|
|
|
disabled?: boolean;
|
|
|
|
loadingText?: string;
|
|
|
|
size?: ButtonSize;
|
|
|
|
type?: ButtonType;
|
|
|
|
onClick(): any;
|
|
|
|
}
|
2017-07-31 23:14:30 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
export default class SimpleButton extends Component<Props, {}> {
|
|
|
|
public computedClass = () => {
|
2017-12-11 20:17:44 +00:00
|
|
|
return `btn btn-${this.props.size || DEFAULT_BUTTON_TYPE} btn-${this.props.type ||
|
|
|
|
DEFAULT_BUTTON_SIZE}`;
|
2017-07-31 23:14:30 +00:00
|
|
|
};
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public render() {
|
|
|
|
const { loading, disabled, loadingText, text, onClick } = this.props;
|
2017-07-31 23:14:30 +00:00
|
|
|
return (
|
|
|
|
<div>
|
2017-12-11 20:17:44 +00:00
|
|
|
<button onClick={onClick} disabled={loading || disabled} className={this.computedClass()}>
|
2017-12-11 17:44:53 +00:00
|
|
|
{loading ? (
|
2018-03-01 17:53:29 +00:00
|
|
|
<div className="SimpleButton">
|
|
|
|
<Spinner light={true} /> {loadingText || text}
|
2017-12-11 17:44:53 +00:00
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div>{text}</div>
|
|
|
|
)}
|
2017-07-31 23:14:30 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|