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 { Reference } from 'react-popper'; import { DropdownContext } from './DropdownContext'; import { mapToCssModules, tagPropType } from './utils'; import Button from './Button'; var propTypes = { caret: PropTypes.bool, color: PropTypes.string, children: PropTypes.node, className: PropTypes.string, cssModule: PropTypes.object, disabled: PropTypes.bool, onClick: PropTypes.func, 'aria-haspopup': PropTypes.bool, split: PropTypes.bool, tag: tagPropType, nav: PropTypes.bool }; var defaultProps = { 'aria-haspopup': true, color: 'secondary' }; var DropdownToggle = /*#__PURE__*/function (_React$Component) { _inheritsLoose(DropdownToggle, _React$Component); function DropdownToggle(props) { var _this; _this = _React$Component.call(this, props) || this; _this.onClick = _this.onClick.bind(_assertThisInitialized(_this)); return _this; } var _proto = DropdownToggle.prototype; _proto.onClick = function onClick(e) { if (this.props.disabled || this.context.disabled) { e.preventDefault(); return; } if (this.props.nav && !this.props.tag) { e.preventDefault(); } if (this.props.onClick) { this.props.onClick(e); } this.context.toggle(e); }; _proto.render = function render() { var _this2 = this; var _this$props = this.props, className = _this$props.className, color = _this$props.color, cssModule = _this$props.cssModule, caret = _this$props.caret, split = _this$props.split, nav = _this$props.nav, tag = _this$props.tag, innerRef = _this$props.innerRef, props = _objectWithoutPropertiesLoose(_this$props, ["className", "color", "cssModule", "caret", "split", "nav", "tag", "innerRef"]); var ariaLabel = props['aria-label'] || 'Toggle Dropdown'; var classes = mapToCssModules(classNames(className, { 'dropdown-toggle': caret || split, 'dropdown-toggle-split': split, 'nav-link': nav }), cssModule); var children = typeof props.children !== 'undefined' ? props.children : /*#__PURE__*/React.createElement("span", { className: "sr-only" }, ariaLabel); var Tag; if (nav && !tag) { Tag = 'a'; props.href = '#'; } else if (!tag) { Tag = Button; props.color = color; props.cssModule = cssModule; } else { Tag = tag; } if (this.context.inNavbar) { return /*#__PURE__*/React.createElement(Tag, _extends({}, props, { className: classes, onClick: this.onClick, "aria-expanded": this.context.isOpen, children: children })); } return /*#__PURE__*/React.createElement(Reference, { innerRef: innerRef }, function (_ref) { var _ref2; var ref = _ref.ref; return /*#__PURE__*/React.createElement(Tag, _extends({}, props, (_ref2 = {}, _ref2[typeof Tag === 'string' ? 'ref' : 'innerRef'] = ref, _ref2), { className: classes, onClick: _this2.onClick, "aria-expanded": _this2.context.isOpen, children: children })); }); }; return DropdownToggle; }(React.Component); DropdownToggle.propTypes = propTypes; DropdownToggle.defaultProps = defaultProps; DropdownToggle.contextType = DropdownContext; export default DropdownToggle;