116 lines
No EOL
4.8 KiB
JavaScript
116 lines
No EOL
4.8 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
|
|
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 _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
|
|
var _react = require('react');
|
|
|
|
var _react2 = _interopRequireDefault(_react);
|
|
|
|
var _propTypes = require('prop-types');
|
|
|
|
var _propTypes2 = _interopRequireDefault(_propTypes);
|
|
|
|
var _classnames = require('classnames');
|
|
|
|
var _classnames2 = _interopRequireDefault(_classnames);
|
|
|
|
var _utils = require('./utils');
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
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; }
|
|
|
|
var propTypes = {
|
|
active: _propTypes2.default.bool,
|
|
block: _propTypes2.default.bool,
|
|
color: _propTypes2.default.string,
|
|
disabled: _propTypes2.default.bool,
|
|
outline: _propTypes2.default.bool,
|
|
tag: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.string]),
|
|
innerRef: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.string]),
|
|
onClick: _propTypes2.default.func,
|
|
size: _propTypes2.default.string,
|
|
children: _propTypes2.default.node,
|
|
className: _propTypes2.default.string,
|
|
cssModule: _propTypes2.default.object
|
|
};
|
|
|
|
var defaultProps = {
|
|
color: 'secondary',
|
|
tag: 'button'
|
|
};
|
|
|
|
var Button = function (_React$Component) {
|
|
_inherits(Button, _React$Component);
|
|
|
|
function Button(props) {
|
|
_classCallCheck(this, Button);
|
|
|
|
var _this = _possibleConstructorReturn(this, (Button.__proto__ || Object.getPrototypeOf(Button)).call(this, props));
|
|
|
|
_this.onClick = _this.onClick.bind(_this);
|
|
return _this;
|
|
}
|
|
|
|
_createClass(Button, [{
|
|
key: 'onClick',
|
|
value: function onClick(e) {
|
|
if (this.props.disabled) {
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
|
|
if (this.props.onClick) {
|
|
this.props.onClick(e);
|
|
}
|
|
}
|
|
}, {
|
|
key: 'render',
|
|
value: function render() {
|
|
var _props = this.props,
|
|
active = _props.active,
|
|
block = _props.block,
|
|
className = _props.className,
|
|
cssModule = _props.cssModule,
|
|
color = _props.color,
|
|
outline = _props.outline,
|
|
size = _props.size,
|
|
Tag = _props.tag,
|
|
innerRef = _props.innerRef,
|
|
attributes = _objectWithoutProperties(_props, ['active', 'block', 'className', 'cssModule', 'color', 'outline', 'size', 'tag', 'innerRef']);
|
|
|
|
var classes = (0, _utils.mapToCssModules)((0, _classnames2.default)(className, 'btn', 'btn' + (outline ? '-outline' : '') + '-' + color, size ? 'btn-' + size : false, block ? 'btn-block' : false, { active: active, disabled: this.props.disabled }), cssModule);
|
|
|
|
if (attributes.href && Tag === 'button') {
|
|
Tag = 'a';
|
|
}
|
|
|
|
return _react2.default.createElement(Tag, _extends({
|
|
type: Tag === 'button' && attributes.onClick ? 'button' : undefined
|
|
}, attributes, {
|
|
className: classes,
|
|
ref: innerRef,
|
|
onClick: this.onClick
|
|
}));
|
|
}
|
|
}]);
|
|
|
|
return Button;
|
|
}(_react2.default.Component);
|
|
|
|
Button.propTypes = propTypes;
|
|
Button.defaultProps = defaultProps;
|
|
|
|
exports.default = Button; |