mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-25 09:55:15 +00:00
119 lines
3.8 KiB
JavaScript
119 lines
3.8 KiB
JavaScript
|
"use strict";
|
||
|
|
||
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||
|
|
||
|
exports.__esModule = true;
|
||
|
exports.default = void 0;
|
||
|
|
||
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
||
|
|
||
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
||
|
|
||
|
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
||
|
|
||
|
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
||
|
|
||
|
var _react = _interopRequireDefault(require("react"));
|
||
|
|
||
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
||
|
|
||
|
var _classnames = _interopRequireDefault(require("classnames"));
|
||
|
|
||
|
var _utils = require("./utils");
|
||
|
|
||
|
var propTypes = {
|
||
|
active: _propTypes.default.bool,
|
||
|
'aria-label': _propTypes.default.string,
|
||
|
block: _propTypes.default.bool,
|
||
|
color: _propTypes.default.string,
|
||
|
disabled: _propTypes.default.bool,
|
||
|
outline: _propTypes.default.bool,
|
||
|
tag: _utils.tagPropType,
|
||
|
innerRef: _propTypes.default.oneOfType([_propTypes.default.object, _propTypes.default.func, _propTypes.default.string]),
|
||
|
onClick: _propTypes.default.func,
|
||
|
size: _propTypes.default.string,
|
||
|
children: _propTypes.default.node,
|
||
|
className: _propTypes.default.string,
|
||
|
cssModule: _propTypes.default.object,
|
||
|
close: _propTypes.default.bool
|
||
|
};
|
||
|
var defaultProps = {
|
||
|
color: 'secondary',
|
||
|
tag: 'button'
|
||
|
};
|
||
|
|
||
|
var Button = /*#__PURE__*/function (_React$Component) {
|
||
|
(0, _inheritsLoose2.default)(Button, _React$Component);
|
||
|
|
||
|
function Button(props) {
|
||
|
var _this;
|
||
|
|
||
|
_this = _React$Component.call(this, props) || this;
|
||
|
_this.onClick = _this.onClick.bind((0, _assertThisInitialized2.default)(_this));
|
||
|
return _this;
|
||
|
}
|
||
|
|
||
|
var _proto = Button.prototype;
|
||
|
|
||
|
_proto.onClick = function onClick(e) {
|
||
|
if (this.props.disabled) {
|
||
|
e.preventDefault();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (this.props.onClick) {
|
||
|
return this.props.onClick(e);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
_proto.render = function render() {
|
||
|
var _this$props = this.props,
|
||
|
active = _this$props.active,
|
||
|
ariaLabel = _this$props['aria-label'],
|
||
|
block = _this$props.block,
|
||
|
className = _this$props.className,
|
||
|
close = _this$props.close,
|
||
|
cssModule = _this$props.cssModule,
|
||
|
color = _this$props.color,
|
||
|
outline = _this$props.outline,
|
||
|
size = _this$props.size,
|
||
|
Tag = _this$props.tag,
|
||
|
innerRef = _this$props.innerRef,
|
||
|
attributes = (0, _objectWithoutPropertiesLoose2.default)(_this$props, ["active", "aria-label", "block", "className", "close", "cssModule", "color", "outline", "size", "tag", "innerRef"]);
|
||
|
|
||
|
if (close && typeof attributes.children === 'undefined') {
|
||
|
attributes.children = /*#__PURE__*/_react.default.createElement("span", {
|
||
|
"aria-hidden": true
|
||
|
}, "\xD7");
|
||
|
}
|
||
|
|
||
|
var btnOutlineColor = "btn" + (outline ? '-outline' : '') + "-" + color;
|
||
|
var classes = (0, _utils.mapToCssModules)((0, _classnames.default)(className, {
|
||
|
close: close
|
||
|
}, close || 'btn', close || btnOutlineColor, size ? "btn-" + size : false, block ? 'btn-block' : false, {
|
||
|
active: active,
|
||
|
disabled: this.props.disabled
|
||
|
}), cssModule);
|
||
|
|
||
|
if (attributes.href && Tag === 'button') {
|
||
|
Tag = 'a';
|
||
|
}
|
||
|
|
||
|
var defaultAriaLabel = close ? 'Close' : null;
|
||
|
return /*#__PURE__*/_react.default.createElement(Tag, (0, _extends2.default)({
|
||
|
type: Tag === 'button' && attributes.onClick ? 'button' : undefined
|
||
|
}, attributes, {
|
||
|
className: classes,
|
||
|
ref: innerRef,
|
||
|
onClick: this.onClick,
|
||
|
"aria-label": ariaLabel || defaultAriaLabel
|
||
|
}));
|
||
|
};
|
||
|
|
||
|
return Button;
|
||
|
}(_react.default.Component);
|
||
|
|
||
|
Button.propTypes = propTypes;
|
||
|
Button.defaultProps = defaultProps;
|
||
|
var _default = Button;
|
||
|
exports.default = _default;
|