2017-07-31 23:14:30 +00:00
|
|
|
// @flow
|
|
|
|
import React, { Component } from 'react';
|
2017-08-28 18:05:38 +00:00
|
|
|
import type { Element } from 'react';
|
2017-07-31 23:14:30 +00:00
|
|
|
|
|
|
|
const DEFAULT_BUTTON_TYPE = 'primary';
|
|
|
|
const DEFAULT_BUTTON_SIZE = 'lg';
|
|
|
|
|
2017-08-31 04:00:31 +00:00
|
|
|
import Spinner from './Spinner';
|
2017-07-31 23:14:30 +00:00
|
|
|
|
|
|
|
type ButtonType =
|
|
|
|
| 'default'
|
|
|
|
| 'primary'
|
|
|
|
| 'success'
|
|
|
|
| 'info'
|
|
|
|
| 'warning'
|
|
|
|
| 'danger';
|
|
|
|
type ButtonSize = 'lg' | 'sm' | 'xs';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
onClick: () => any,
|
2017-08-28 18:05:38 +00:00
|
|
|
text: Element<*> | string,
|
2017-07-31 23:14:30 +00:00
|
|
|
loading?: boolean,
|
|
|
|
disabled?: boolean,
|
|
|
|
loadingText?: string,
|
|
|
|
size?: ButtonSize,
|
|
|
|
type?: ButtonType
|
|
|
|
};
|
|
|
|
|
|
|
|
export default class SimpleButton extends Component {
|
|
|
|
props: Props;
|
|
|
|
|
|
|
|
computedClass = () => {
|
|
|
|
return `btn btn-${this.props.size || DEFAULT_BUTTON_TYPE} btn-${this.props
|
|
|
|
.type || DEFAULT_BUTTON_SIZE}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let { loading, disabled, loadingText, text, onClick } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<button
|
|
|
|
onClick={onClick}
|
|
|
|
disabled={loading || disabled}
|
|
|
|
className={this.computedClass()}
|
|
|
|
>
|
|
|
|
{loading
|
|
|
|
? <div>
|
2017-08-28 18:05:38 +00:00
|
|
|
<Spinner /> {loadingText || text}
|
2017-07-31 23:14:30 +00:00
|
|
|
</div>
|
|
|
|
: <div>
|
|
|
|
{text}
|
|
|
|
</div>}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|