1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-10 21:18:38 +01:00
onion/js/lib/buttons.js

59 lines
1.6 KiB
JavaScript
Raw Normal View History

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'];
function ButtonFactory(style, btnClassName, options) {
style = style || 'default';
options = options || {};
2015-09-07 11:40:05 +02:00
let GenericButton = React.createClass({
propTypes: {
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 (
<_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
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');