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-07 11:40:05 +02:00
|
|
|
status: React.PropTypes.oneOf(['loading', 'disabled']),
|
|
|
|
children: React.PropTypes.oneOfType([React.PropTypes.arrayOf(React.PropTypes.element),
|
|
|
|
React.PropTypes.element])
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
status: this.props.status
|
|
|
|
};
|
|
|
|
},
|
2015-09-03 14:26:25 +02:00
|
|
|
|
2015-09-07 11:40:05 +02:00
|
|
|
render: function render() {
|
|
|
|
let disabled = DISABLED_STATUSES.indexOf(this.state.status) !== -1;
|
|
|
|
let className = '';
|
2015-09-03 14:26:25 +02:00
|
|
|
|
2015-09-07 11:40:05 +02:00
|
|
|
if (this.state.status !== 'disabled') {
|
|
|
|
className = this.state.status;
|
|
|
|
}
|
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-16 22:00:33 +02:00
|
|
|
export const Button = ButtonFactory('primary', 'btn-primary');
|
|
|
|
export const SubmitButton = ButtonFactory('primary', 'btn-primary', { type: 'submit' });
|
|
|
|
export const SecondaryButton = ButtonFactory('default', 'btn-secondary');
|
|
|
|
export const DangerButton = ButtonFactory('danger', 'btn-danger');
|