1 line
7.0 KiB
JSON
1 line
7.0 KiB
JSON
{"ast":null,"code":"import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _objectWithoutPropertiesLoose from \"@babel/runtime/helpers/esm/objectWithoutPropertiesLoose\";\nimport _inheritsLoose from \"@babel/runtime/helpers/esm/inheritsLoose\";\n/* eslint-disable max-classes-per-file */\n\nimport contains from 'dom-helpers/contains';\nimport React, { cloneElement } from 'react';\nimport ReactDOM from 'react-dom';\nimport warning from 'warning';\nimport Overlay from './Overlay';\n\nvar RefHolder = /*#__PURE__*/function (_React$Component) {\n _inheritsLoose(RefHolder, _React$Component);\n\n function RefHolder() {\n return _React$Component.apply(this, arguments) || this;\n }\n\n var _proto = RefHolder.prototype;\n\n _proto.render = function render() {\n return this.props.children;\n };\n\n return RefHolder;\n}(React.Component);\n\nvar normalizeDelay = function normalizeDelay(delay) {\n return delay && typeof delay === 'object' ? delay : {\n show: delay,\n hide: delay\n };\n};\n\nvar defaultProps = {\n defaultOverlayShown: false,\n trigger: ['hover', 'focus']\n}; // eslint-disable-next-line react/no-multi-comp\n\nvar OverlayTrigger = /*#__PURE__*/function (_React$Component2) {\n _inheritsLoose(OverlayTrigger, _React$Component2);\n\n function OverlayTrigger(props, context) {\n var _this;\n\n _this = _React$Component2.call(this, props, context) || this;\n\n _this.getTarget = function () {\n return ReactDOM.findDOMNode(_this.trigger.current);\n };\n\n _this.handleShow = function () {\n clearTimeout(_this._timeout);\n _this._hoverState = 'show';\n var delay = normalizeDelay(_this.props.delay);\n\n if (!delay.show) {\n _this.show();\n\n return;\n }\n\n _this._timeout = setTimeout(function () {\n if (_this._hoverState === 'show') _this.show();\n }, delay.show);\n };\n\n _this.handleHide = function () {\n clearTimeout(_this._timeout);\n _this._hoverState = 'hide';\n var delay = normalizeDelay(_this.props.delay);\n\n if (!delay.hide) {\n _this.hide();\n\n return;\n }\n\n _this._timeout = setTimeout(function () {\n if (_this._hoverState === 'hide') _this.hide();\n }, delay.hide);\n };\n\n _this.handleFocus = function (e) {\n var _this$getChildProps = _this.getChildProps(),\n onFocus = _this$getChildProps.onFocus;\n\n _this.handleShow(e);\n\n if (onFocus) onFocus(e);\n };\n\n _this.handleBlur = function (e) {\n var _this$getChildProps2 = _this.getChildProps(),\n onBlur = _this$getChildProps2.onBlur;\n\n _this.handleHide(e);\n\n if (onBlur) onBlur(e);\n };\n\n _this.handleClick = function (e) {\n var _this$getChildProps3 = _this.getChildProps(),\n onClick = _this$getChildProps3.onClick;\n\n if (_this.state.show) _this.hide();else _this.show();\n if (onClick) onClick(e);\n };\n\n _this.handleMouseOver = function (e) {\n _this.handleMouseOverOut(_this.handleShow, e, 'fromElement');\n };\n\n _this.handleMouseOut = function (e) {\n return _this.handleMouseOverOut(_this.handleHide, e, 'toElement');\n };\n\n _this.trigger = React.createRef();\n _this.state = {\n show: !!props.defaultShow\n }; // We add aria-describedby in the case where the overlay is a role=\"tooltip\"\n // for other cases describedby isn't appropriate (e.g. a popover with inputs) so we don't add it.\n\n _this.ariaModifier = {\n enabled: true,\n order: 900,\n fn: function fn(data) {\n var popper = data.instance.popper;\n\n var target = _this.getTarget();\n\n if (!_this.state.show || !target) return data;\n var role = popper.getAttribute('role') || '';\n\n if (popper.id && role.toLowerCase() === 'tooltip') {\n target.setAttribute('aria-describedby', popper.id);\n }\n\n return data;\n }\n };\n return _this;\n }\n\n var _proto2 = OverlayTrigger.prototype;\n\n _proto2.componentWillUnmount = function componentWillUnmount() {\n clearTimeout(this._timeout);\n };\n\n _proto2.getChildProps = function getChildProps() {\n return React.Children.only(this.props.children).props;\n }; // Simple implementation of mouseEnter and mouseLeave.\n // React's built version is broken: https://github.com/facebook/react/issues/4251\n // for cases when the trigger is disabled and mouseOut/Over can cause flicker\n // moving from one child element to another.\n\n\n _proto2.handleMouseOverOut = function handleMouseOverOut(handler, e, relatedNative) {\n var target = e.currentTarget;\n var related = e.relatedTarget || e.nativeEvent[relatedNative];\n\n if ((!related || related !== target) && !contains(target, related)) {\n handler(e);\n }\n };\n\n _proto2.hide = function hide() {\n this.setState({\n show: false\n });\n };\n\n _proto2.show = function show() {\n this.setState({\n show: true\n });\n };\n\n _proto2.render = function render() {\n var _this$props = this.props,\n trigger = _this$props.trigger,\n overlay = _this$props.overlay,\n children = _this$props.children,\n _this$props$popperCon = _this$props.popperConfig,\n popperConfig = _this$props$popperCon === void 0 ? {} : _this$props$popperCon,\n props = _objectWithoutPropertiesLoose(_this$props, [\"trigger\", \"overlay\", \"children\", \"popperConfig\"]);\n\n delete props.delay;\n delete props.defaultShow;\n var child = React.Children.only(children);\n var triggerProps = {};\n var triggers = trigger == null ? [] : [].concat(trigger);\n\n if (triggers.indexOf('click') !== -1) {\n triggerProps.onClick = this.handleClick;\n }\n\n if (triggers.indexOf('focus') !== -1) {\n triggerProps.onFocus = this.handleShow;\n triggerProps.onBlur = this.handleHide;\n }\n\n if (triggers.indexOf('hover') !== -1) {\n process.env.NODE_ENV !== \"production\" ? warning(triggers.length >= 1, '[react-bootstrap] Specifying only the `\"hover\"` trigger limits the ' + 'visibility of the overlay to just mouse users. Consider also ' + 'including the `\"focus\"` trigger so that touch and keyboard only ' + 'users can see the overlay as well.') : void 0;\n triggerProps.onMouseOver = this.handleMouseOver;\n triggerProps.onMouseOut = this.handleMouseOut;\n }\n\n return React.createElement(React.Fragment, null, React.createElement(RefHolder, {\n ref: this.trigger\n }, cloneElement(child, triggerProps)), React.createElement(Overlay, _extends({}, props, {\n popperConfig: _extends({}, popperConfig, {\n modifiers: _extends({}, popperConfig.modifiers, {\n ariaModifier: this.ariaModifier\n })\n }),\n show: this.state.show,\n onHide: this.handleHide,\n target: this.getTarget\n }), overlay));\n };\n\n return OverlayTrigger;\n}(React.Component);\n\nOverlayTrigger.defaultProps = defaultProps;\nexport default OverlayTrigger;","map":null,"metadata":{},"sourceType":"module"} |