GoScrobble/web/node_modules/reactstrap/es/Button.js

103 lines
3.2 KiB
JavaScript
Raw Permalink Normal View History

2022-04-25 02:47:15 +00:00
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { mapToCssModules, tagPropType } from './utils';
var propTypes = {
active: PropTypes.bool,
'aria-label': PropTypes.string,
block: PropTypes.bool,
color: PropTypes.string,
disabled: PropTypes.bool,
outline: PropTypes.bool,
tag: tagPropType,
innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
onClick: PropTypes.func,
size: PropTypes.string,
children: PropTypes.node,
className: PropTypes.string,
cssModule: PropTypes.object,
close: PropTypes.bool
};
var defaultProps = {
color: 'secondary',
tag: 'button'
};
var Button = /*#__PURE__*/function (_React$Component) {
_inheritsLoose(Button, _React$Component);
function Button(props) {
var _this;
_this = _React$Component.call(this, props) || this;
_this.onClick = _this.onClick.bind(_assertThisInitialized(_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 = _objectWithoutPropertiesLoose(_this$props, ["active", "aria-label", "block", "className", "close", "cssModule", "color", "outline", "size", "tag", "innerRef"]);
if (close && typeof attributes.children === 'undefined') {
attributes.children = /*#__PURE__*/React.createElement("span", {
"aria-hidden": true
}, "\xD7");
}
var btnOutlineColor = "btn" + (outline ? '-outline' : '') + "-" + color;
var classes = mapToCssModules(classNames(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.createElement(Tag, _extends({
type: Tag === 'button' && attributes.onClick ? 'button' : undefined
}, attributes, {
className: classes,
ref: innerRef,
onClick: this.onClick,
"aria-label": ariaLabel || defaultAriaLabel
}));
};
return Button;
}(React.Component);
Button.propTypes = propTypes;
Button.defaultProps = defaultProps;
export default Button;