UNPKG

@atlaskit/popup

Version:

A popup displays brief content in an overlay.

183 lines (182 loc) 7.57 kB
/* popper-wrapper.tsx generated by @compiled/babel-plugin v0.36.1 */ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; var _excluded = ["shouldRenderToParent", "shouldFitContainer", "children", "appearance", "className", "isReferenceHidden"]; import "./popper-wrapper.compiled.css"; import * as React from 'react'; import { forwardRef, Fragment, useMemo, useState } from 'react'; import { ax, ix } from '@compiled/react/runtime'; import { useLayering } from '@atlaskit/layering'; import { fg } from '@atlaskit/platform-feature-flags'; import { Popper } from '@atlaskit/popper'; import { RepositionOnUpdate } from './reposition-on-update'; import { useCloseManager } from './use-close-manager'; import { useFocusManager } from './use-focus-manager'; var LOCAL_CURRENT_SURFACE_CSS_VAR = '--ds-elevation-surface-current'; var fullWidthStyles = null; var wrapperStyles = { root: "_2rkoglpi _1e0c1ule _vchhusvi _1pby1nn1 _bfhk1bhr _16qs1cd0 _syaz1fxt _1q1l1bhr _nt751r31 _49pcglyw _1hvw1o36" }; var scrollableStyles = null; var blanketStyles = null; var modalStyles = null; var focusRingStyles = { root: "_mizu194a _1ah31bk5 _ra3xnqa1 _128m1bk5 _1cvmnqa1 _4davt94y" }; var DefaultPopupComponent = /*#__PURE__*/forwardRef(function (props, ref) { var shouldRenderToParent = props.shouldRenderToParent, shouldFitContainer = props.shouldFitContainer, children = props.children, appearance = props.appearance, className = props.className, isReferenceHidden = props.isReferenceHidden, htmlAttributes = _objectWithoutProperties(props, _excluded); return /*#__PURE__*/React.createElement("div", _extends({ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop className: ax([wrapperStyles.root, appearance === 'UNSAFE_modal-below-sm' && "_dk5d1b66 _c71ldtre _kqsw1n9t _152t1b66", !shouldRenderToParent && "_1reo1wug _18m91wug", shouldFitContainer && "_1bsb1osq", className]) }, htmlAttributes, { ref: ref }), children); }); function PopperWrapper(_ref) { var xcss = _ref.xcss, isOpen = _ref.isOpen, id = _ref.id, offset = _ref.offset, testId = _ref.testId, content = _ref.content, fallbackPlacements = _ref.fallbackPlacements, onClose = _ref.onClose, boundary = _ref.boundary, rootBoundary = _ref.rootBoundary, shouldFlip = _ref.shouldFlip, _ref$placement = _ref.placement, placement = _ref$placement === void 0 ? 'auto' : _ref$placement, _ref$popupComponent = _ref.popupComponent, PopupContainer = _ref$popupComponent === void 0 ? DefaultPopupComponent : _ref$popupComponent, _ref$autoFocus = _ref.autoFocus, autoFocus = _ref$autoFocus === void 0 ? true : _ref$autoFocus, triggerRef = _ref.triggerRef, shouldUseCaptureOnOutsideClick = _ref.shouldUseCaptureOnOutsideClick, shouldRenderToParent = _ref.shouldRenderToParent, shouldFitContainer = _ref.shouldFitContainer, shouldDisableFocusLock = _ref.shouldDisableFocusLock, _ref$shouldReturnFocu = _ref.shouldReturnFocus, shouldReturnFocus = _ref$shouldReturnFocu === void 0 ? true : _ref$shouldReturnFocu, strategy = _ref.strategy, role = _ref.role, label = _ref.label, titleId = _ref.titleId, modifiers = _ref.modifiers, shouldFitViewport = _ref.shouldFitViewport, _ref$appearance = _ref.appearance, appearance = _ref$appearance === void 0 ? 'default' : _ref$appearance; var _useState = useState(null), _useState2 = _slicedToArray(_useState, 2), popupRef = _useState2[0], setPopupRef = _useState2[1]; var _useState3 = useState(null), _useState4 = _slicedToArray(_useState3, 2), initialFocusRef = _useState4[0], setInitialFocusRef = _useState4[1]; // We have cases where we need to close the Popup on Tab press, e.g. DropdownMenu var shouldCloseOnTab = shouldRenderToParent && shouldDisableFocusLock; var shouldDisableFocusTrap = role !== 'dialog'; useFocusManager({ initialFocusRef: initialFocusRef, popupRef: popupRef, shouldCloseOnTab: shouldCloseOnTab, triggerRef: triggerRef, autoFocus: autoFocus, shouldDisableFocusTrap: shouldDisableFocusTrap, shouldReturnFocus: shouldReturnFocus }); useCloseManager({ isOpen: isOpen, onClose: onClose, popupRef: popupRef, triggerRef: triggerRef, shouldUseCaptureOnOutsideClick: shouldUseCaptureOnOutsideClick, shouldCloseOnTab: shouldCloseOnTab, autoFocus: autoFocus, shouldDisableFocusTrap: shouldDisableFocusTrap, shouldRenderToParent: shouldRenderToParent }); var _useLayering = useLayering(), currentLevel = _useLayering.currentLevel; var mergedModifiers = useMemo(function () { return [{ name: 'flip', enabled: shouldFlip, options: { rootBoundary: rootBoundary, boundary: boundary, fallbackPlacements: fallbackPlacements } }].concat(_toConsumableArray(modifiers || [])); }, [shouldFlip, rootBoundary, boundary, fallbackPlacements, modifiers]); return /*#__PURE__*/React.createElement(Popper, { placement: placement, offset: offset, modifiers: mergedModifiers, strategy: strategy, shouldFitViewport: shouldFitViewport }, function (_ref2) { var _ref3 = _ref2.ref, style = _ref2.style, placement = _ref2.placement, update = _ref2.update, isReferenceHidden = _ref2.isReferenceHidden; var popupContainer = /*#__PURE__*/React.createElement(PopupContainer // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop , { className: ax([xcss, // @ts-expect-error: `ax` is not typed correctly !initialFocusRef && // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix fg('platform-design-system-apply-popup-wrapper-focus') && focusRingStyles.root]), appearance: appearance, id: id, "data-ds--level": currentLevel, "data-placement": placement, "data-testid": testId, role: role, "aria-label": label, "aria-labelledby": titleId, ref: function ref(node) { if (node) { if (typeof _ref3 === 'function') { _ref3(node); } else { _ref3.current = node; } setPopupRef(node); } } // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766 , style: appearance === 'UNSAFE_modal-below-sm' ? {} : style // using tabIndex={-1} would cause a bug where Safari focuses // first on the browser address bar when using keyboard , tabIndex: autoFocus ? 0 : undefined, shouldRenderToParent: shouldRenderToParent, shouldFitContainer: shouldFitContainer, isReferenceHidden: isReferenceHidden }, /*#__PURE__*/React.createElement(RepositionOnUpdate, { update: update }, content({ update: update, isOpen: isOpen, onClose: onClose, setInitialFocusRef: setInitialFocusRef }))); return /*#__PURE__*/React.createElement(Fragment, null, popupContainer, appearance === 'UNSAFE_modal-below-sm' && /*#__PURE__*/React.createElement("div", { className: ax(["_1r04idpf _kqsw1n9t _bfhk10xm"]) })); }); } // eslint-disable-next-line @repo/internal/react/require-jsdoc export default PopperWrapper;