import _extends from "@babel/runtime/helpers/esm/extends"; import _objectSpread2 from "@babel/runtime/helpers/esm/objectSpread"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose"; import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { Popper } from 'react-popper'; import { DropdownContext } from './DropdownContext'; import { mapToCssModules, tagPropType } from './utils'; var propTypes = { tag: tagPropType, children: PropTypes.node.isRequired, right: PropTypes.bool, flip: PropTypes.bool, modifiers: PropTypes.object, className: PropTypes.string, cssModule: PropTypes.object, persist: PropTypes.bool, positionFixed: PropTypes.bool }; var defaultProps = { tag: 'div', flip: true }; var noFlipModifier = { flip: { enabled: false } }; var directionPositionMap = { up: 'top', left: 'left', right: 'right', down: 'bottom' }; var DropdownMenu = /*#__PURE__*/ function (_React$Component) { _inheritsLoose(DropdownMenu, _React$Component); function DropdownMenu() { return _React$Component.apply(this, arguments) || this; } var _proto = DropdownMenu.prototype; _proto.render = function render() { var _this = this; var _this$props = this.props, className = _this$props.className, cssModule = _this$props.cssModule, right = _this$props.right, tag = _this$props.tag, flip = _this$props.flip, modifiers = _this$props.modifiers, persist = _this$props.persist, positionFixed = _this$props.positionFixed, attrs = _objectWithoutPropertiesLoose(_this$props, ["className", "cssModule", "right", "tag", "flip", "modifiers", "persist", "positionFixed"]); var classes = mapToCssModules(classNames(className, 'dropdown-menu', { 'dropdown-menu-right': right, show: this.context.isOpen }), cssModule); var Tag = tag; if (persist || this.context.isOpen && !this.context.inNavbar) { var position1 = directionPositionMap[this.context.direction] || 'bottom'; var position2 = right ? 'end' : 'start'; var poperPlacement = position1 + "-" + position2; var poperModifiers = !flip ? _objectSpread2({}, modifiers, {}, noFlipModifier) : modifiers; var popperPositionFixed = !!positionFixed; return React.createElement(Popper, { placement: poperPlacement, modifiers: poperModifiers, positionFixed: popperPositionFixed }, function (_ref) { var ref = _ref.ref, style = _ref.style, placement = _ref.placement; return React.createElement(Tag, _extends({ tabIndex: "-1", role: "menu", ref: ref, style: style }, attrs, { "aria-hidden": !_this.context.isOpen, className: classes, "x-placement": placement })); }); } return React.createElement(Tag, _extends({ tabIndex: "-1", role: "menu" }, attrs, { "aria-hidden": !this.context.isOpen, className: classes, "x-placement": attrs.placement })); }; return DropdownMenu; }(React.Component); ; DropdownMenu.propTypes = propTypes; DropdownMenu.defaultProps = defaultProps; DropdownMenu.contextType = DropdownContext; export default DropdownMenu;