@bigfishtv/cockpit
Version:
77 lines (64 loc) • 3.33 kB
JavaScript
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _class, _temp;
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import classnames from 'classnames';
import Icon from '../Icon';
/**
* Dumb button component, applies turret classes and spreads rest of props
*/
var Button = (_temp = _class = function (_Component) {
_inherits(Button, _Component);
function Button() {
_classCallCheck(this, Button);
return _possibleConstructorReturn(this, _Component.apply(this, arguments));
}
Button.prototype.render = function render() {
var _props = this.props,
size = _props.size,
style = _props.style,
icon = _props.icon,
text = _props.text,
children = _props.children,
invalid = _props.invalid,
formValue = _props.formValue,
buttonProps = _objectWithoutProperties(_props, ['size', 'style', 'icon', 'text', 'children', 'invalid', 'formValue']);
var buttonClass = classnames('button', size && 'button-' + size, style && 'button-' + style, style);
return React.createElement(
'button',
_extends({}, buttonProps, { className: buttonClass }),
icon && React.createElement(Icon, { name: icon, size: 18 }),
React.createElement(
'span',
null,
children || text
)
);
};
return Button;
}(Component), _class.propTypes = {
/** Size of button: xsmall, small, medium, large, xlarge */
size: PropTypes.string,
/** Button's text, will use children instead if provided */
text: PropTypes.node,
/** Outputs custom button class e.g 'primary' = 'button-primary' */
style: PropTypes.string,
/** Button type i.e. 'button' or 'submit' */
type: PropTypes.oneOf(['button', 'submit', 'reset']),
/** String referencing icon name to include in button */
icon: PropTypes.string,
/** Click callback */
onClick: PropTypes.func
}, _class.defaultProps = {
size: 'medium',
text: 'Button',
style: 'default',
type: 'button',
icon: null,
onClick: function onClick() {}
}, _temp);
export { Button as default };