{"ast":null,"code":"import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _objectWithoutPropertiesLoose from \"@babel/runtime/helpers/esm/objectWithoutPropertiesLoose\";\nimport _assertThisInitialized from \"@babel/runtime/helpers/esm/assertThisInitialized\";\nimport _inheritsLoose from \"@babel/runtime/helpers/esm/inheritsLoose\";\nimport _objectSpread2 from \"@babel/runtime/helpers/esm/objectSpread\";\nimport React from 'react';\nimport PropTypes from 'prop-types';\nimport ReactDOM from 'react-dom';\nimport classNames from 'classnames';\nimport { Popper as ReactPopper } from 'react-popper';\nimport { getTarget, targetPropType, mapToCssModules, DOMElement, tagPropType } from './utils';\nimport Fade from './Fade';\n\nfunction noop() {}\n\nvar propTypes = {\n children: PropTypes.node.isRequired,\n popperClassName: PropTypes.string,\n placement: PropTypes.string,\n placementPrefix: PropTypes.string,\n arrowClassName: PropTypes.string,\n hideArrow: PropTypes.bool,\n tag: tagPropType,\n isOpen: PropTypes.bool.isRequired,\n cssModule: PropTypes.object,\n offset: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n fallbackPlacement: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),\n flip: PropTypes.bool,\n container: targetPropType,\n target: targetPropType.isRequired,\n modifiers: PropTypes.object,\n boundariesElement: PropTypes.oneOfType([PropTypes.string, DOMElement]),\n onClosed: PropTypes.func,\n fade: PropTypes.bool,\n transition: PropTypes.shape(Fade.propTypes)\n};\nvar defaultProps = {\n boundariesElement: 'scrollParent',\n placement: 'auto',\n hideArrow: false,\n isOpen: false,\n offset: 0,\n fallbackPlacement: 'flip',\n flip: true,\n container: 'body',\n modifiers: {},\n onClosed: noop,\n fade: true,\n transition: _objectSpread2({}, Fade.defaultProps)\n};\n\nvar PopperContent = /*#__PURE__*/function (_React$Component) {\n _inheritsLoose(PopperContent, _React$Component);\n\n function PopperContent(props) {\n var _this;\n\n _this = _React$Component.call(this, props) || this;\n _this.setTargetNode = _this.setTargetNode.bind(_assertThisInitialized(_this));\n _this.getTargetNode = _this.getTargetNode.bind(_assertThisInitialized(_this));\n _this.getRef = _this.getRef.bind(_assertThisInitialized(_this));\n _this.onClosed = _this.onClosed.bind(_assertThisInitialized(_this));\n _this.state = {\n isOpen: props.isOpen\n };\n return _this;\n }\n\n PopperContent.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {\n if (props.isOpen && !state.isOpen) {\n return {\n isOpen: props.isOpen\n };\n } else return null;\n };\n\n var _proto = PopperContent.prototype;\n\n _proto.componentDidUpdate = function componentDidUpdate() {\n if (this._element && this._element.childNodes && this._element.childNodes[0] && this._element.childNodes[0].focus) {\n this._element.childNodes[0].focus();\n }\n };\n\n _proto.setTargetNode = function setTargetNode(node) {\n this.targetNode = typeof node === 'string' ? getTarget(node) : node;\n };\n\n _proto.getTargetNode = function getTargetNode() {\n return this.targetNode;\n };\n\n _proto.getContainerNode = function getContainerNode() {\n return getTarget(this.props.container);\n };\n\n _proto.getRef = function getRef(ref) {\n this._element = ref;\n };\n\n _proto.onClosed = function onClosed() {\n this.props.onClosed();\n this.setState({\n isOpen: false\n });\n };\n\n _proto.renderChildren = function renderChildren() {\n var _this$props = this.props,\n cssModule = _this$props.cssModule,\n children = _this$props.children,\n isOpen = _this$props.isOpen,\n flip = _this$props.flip,\n target = _this$props.target,\n offset = _this$props.offset,\n fallbackPlacement = _this$props.fallbackPlacement,\n placementPrefix = _this$props.placementPrefix,\n _arrowClassName = _this$props.arrowClassName,\n hideArrow = _this$props.hideArrow,\n _popperClassName = _this$props.popperClassName,\n tag = _this$props.tag,\n container = _this$props.container,\n modifiers = _this$props.modifiers,\n boundariesElement = _this$props.boundariesElement,\n onClosed = _this$props.onClosed,\n fade = _this$props.fade,\n transition = _this$props.transition,\n placement = _this$props.placement,\n attrs = _objectWithoutPropertiesLoose(_this$props, [\"cssModule\", \"children\", \"isOpen\", \"flip\", \"target\", \"offset\", \"fallbackPlacement\", \"placementPrefix\", \"arrowClassName\", \"hideArrow\", \"popperClassName\", \"tag\", \"container\", \"modifiers\", \"boundariesElement\", \"onClosed\", \"fade\", \"transition\", \"placement\"]);\n\n var arrowClassName = mapToCssModules(classNames('arrow', _arrowClassName), cssModule);\n var popperClassName = mapToCssModules(classNames(_popperClassName, placementPrefix ? placementPrefix + \"-auto\" : ''), this.props.cssModule);\n\n var extendedModifiers = _objectSpread2({\n offset: {\n offset: offset\n },\n flip: {\n enabled: flip,\n behavior: fallbackPlacement\n },\n preventOverflow: {\n boundariesElement: boundariesElement\n }\n }, modifiers);\n\n var popperTransition = _objectSpread2({}, Fade.defaultProps, {}, transition, {\n baseClass: fade ? transition.baseClass : '',\n timeout: fade ? transition.timeout : 0\n });\n\n return React.createElement(Fade, _extends({}, popperTransition, attrs, {\n in: isOpen,\n onExited: this.onClosed,\n tag: tag\n }), React.createElement(ReactPopper, {\n referenceElement: this.targetNode,\n modifiers: extendedModifiers,\n placement: placement\n }, function (_ref) {\n var ref = _ref.ref,\n style = _ref.style,\n placement = _ref.placement,\n arrowProps = _ref.arrowProps;\n return React.createElement(\"div\", {\n ref: ref,\n style: style,\n className: popperClassName,\n \"x-placement\": placement\n }, children, !hideArrow && React.createElement(\"span\", {\n ref: arrowProps.ref,\n className: arrowClassName,\n style: arrowProps.style\n }));\n }));\n };\n\n _proto.render = function render() {\n this.setTargetNode(this.props.target);\n\n if (this.state.isOpen) {\n return this.props.container === 'inline' ? this.renderChildren() : ReactDOM.createPortal(React.createElement(\"div\", {\n ref: this.getRef\n }, this.renderChildren()), this.getContainerNode());\n }\n\n return null;\n };\n\n return PopperContent;\n}(React.Component);\n\nPopperContent.propTypes = propTypes;\nPopperContent.defaultProps = defaultProps;\nexport default PopperContent;","map":null,"metadata":{},"sourceType":"module"}