react-components-library
Version:
replace 'onBrowserComplete' on karma-coverage with
72 lines (58 loc) • 2.17 kB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
;
var React = require('react');
var classNames = require('classnames');
var _ = require('lodash');
var Button = React.createClass({
displayName: 'Button',
propTypes: {
buttonType: React.PropTypes.oneOf(['default', 'primary', 'secondary', 'tertiary', 'quaternary']),
buttonSize: React.PropTypes.oneOf(['small', 'medium', 'large']),
disabled: React.PropTypes.bool,
leftIcon: React.PropTypes.string,
rightIcon: React.PropTypes.string,
outlined: React.PropTypes.bool
},
getDefaultProps: function getDefaultProps() {
return {
buttonSize: 'small',
buttonType: 'default'
};
},
render: function render() {
return React.createElement(
'button',
this.getProps(),
this.props.children
);
},
getProps: function getProps() {
var props = _.extend({}, this.props, {
className: this.getClass()
});
return props;
},
getClass: function getClass() {
var buttonType = this.props.buttonType;
var buttonSize = this.props.buttonSize;
var classes = {
'button': true,
'button_block': this.props.block,
'button_disabled': this.props.disabled,
'button_outlined': this.props.outlined,
'button_small': buttonSize === 'small',
'button_medium': buttonSize === 'medium',
'button_large': buttonSize === 'large',
'button_default': buttonType === 'default',
'button_primary': buttonType === 'primary',
'button_secondary': buttonType === 'secondary',
'button_tertiary': buttonType === 'tertiary',
'button_quaternary': buttonType === 'quaternary'
};
classes[this.props.className] = this.props.className;
return classNames(classes);
}
});
module.exports = Button;