2015-09-07 11:40:05 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2015-09-03 14:26:25 +02:00
|
|
|
import React from 'react';
|
|
|
|
import _Button from 'react-bootstrap/lib/Button';
|
2015-09-07 11:40:05 +02:00
|
|
|
import classnames from 'classnames';
|
|
|
|
|
|
|
|
|
|
|
|
const DISABLED_STATUSES = ['loading', 'disabled'];
|
|
|
|
|
|
|
|
|
2015-09-16 22:00:33 +02:00
|
|
|
function ButtonFactory(style, btnClassName, options) {
|
|
|
|
|
|
|
|
style = style || 'default';
|
|
|
|
options = options || {};
|
2015-09-07 11:40:05 +02:00
|
|
|
|
|
|
|
let GenericButton = React.createClass({
|
|
|
|
propTypes: {
|
2015-09-16 22:00:33 +02:00
|
|
|
onClick: React.PropTypes.func,
|
2015-09-17 16:50:38 +02:00
|
|
|
status: React.PropTypes.oneOf(['loading', 'disabled', null]),
|
2015-09-07 11:40:05 +02:00
|
|
|
children: React.PropTypes.oneOfType([React.PropTypes.arrayOf(React.PropTypes.element),
|
2015-09-17 17:00:25 +02:00
|
|
|
React.PropTypes.element,
|
|
|
|
React.PropTypes.string])
|
2015-09-07 11:40:05 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function render() {
|
2015-09-17 16:50:38 +02:00
|
|
|
let disabled = DISABLED_STATUSES.indexOf(this.props.status) !== -1;
|
2015-09-07 11:40:05 +02:00
|
|
|
let className = '';
|
2015-09-03 14:26:25 +02:00
|
|
|
|
2015-09-17 16:50:38 +02:00
|
|
|
if (this.props.status !== 'disabled' && this.props.status !== null) {
|
|
|
|
className = this.props.status;
|
2015-09-07 11:40:05 +02:00
|
|
|
}
|
2015-09-03 14:26:25 +02:00
|
|
|
|
2015-09-07 11:40:05 +02:00
|
|
|
return (
|
2015-09-16 22:00:33 +02:00
|
|
|
<_Button bsStyle={style} onClick={this.props.onClick} className={classnames(btnClassName, className)} type={options.type} disabled={disabled}>
|
2015-09-07 11:40:05 +02:00
|
|
|
{this.props.children}
|
|
|
|
</_Button>
|
|
|
|
);
|
|
|
|
}
|
2015-09-03 14:26:25 +02:00
|
|
|
|
2015-09-07 11:40:05 +02:00
|
|
|
});
|
2015-09-03 14:26:25 +02:00
|
|
|
|
2015-09-07 11:40:05 +02:00
|
|
|
return GenericButton;
|
|
|
|
}
|
2015-09-03 14:26:25 +02:00
|
|
|
|
|
|
|
|
2015-09-17 12:01:20 +02:00
|
|
|
export let Button = ButtonFactory('primary', 'btn-primary');
|
|
|
|
export let SubmitButton = ButtonFactory('primary', 'btn-primary', { type: 'submit' });
|
|
|
|
export let SubmitDangerButton = ButtonFactory('danger', 'btn-danger', { type: 'submit' });
|
|
|
|
export let SecondaryButton = ButtonFactory('default', 'btn-secondary');
|
|
|
|
export let DangerButton = ButtonFactory('danger', 'btn-danger');
|