UNPKG

@atlaskit/popup

Version:

A popup displays brief content in an overlay.

166 lines (164 loc) • 7.65 kB
/* popup.tsx generated by @compiled/babel-plugin v3.0.2 */ import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import "./popup.compiled.css"; import * as React from 'react'; import { ax, ix } from "@compiled/react/runtime"; /* eslint-disable @repo/internal/react/require-jsdoc */ import { memo, useCallback, useState } from 'react'; import { useId } from '@atlaskit/ds-lib/use-id'; import { Layering } from '@atlaskit/layering/layering'; import { useNotifyOpenLayerObserver } from '@atlaskit/layering/use-notify-open-layer-observer'; import ExitingPersistence from '@atlaskit/motion/exiting-persistence'; import { fg } from '@atlaskit/platform-feature-flags/fg'; import { Manager } from '@atlaskit/popper/manager'; import { Reference } from '@atlaskit/popper/reference'; import Portal from '@atlaskit/portal/portal'; import { Box } from '@atlaskit/primitives/compiled'; import PopperWrapper from './popper-wrapper'; import { PopupTopLayer } from './popup-top-layer'; import { usePopupAppearance } from './use-appearance'; import { useGetMemoizedMergedTriggerRef } from './use-get-memoized-merged-trigger-ref'; import { useGetMemoizedMergedTriggerRefNew } from './use-get-memoized-merged-trigger-ref-new'; var defaultLayer = 400; var wrapperStyles = { root: "_kqswh2mm" }; var PopupLegacy = function PopupLegacy(props) { var xcss = props.xcss, _props$appearance = props.appearance, inAppearance = _props$appearance === void 0 ? 'default' : _props$appearance, isOpen = props.isOpen, providedId = props.id, offset = props.offset, testId = props.testId, trigger = props.trigger, content = props.content, onClose = props.onClose, boundary = props.boundary, _props$rootBoundary = props.rootBoundary, rootBoundary = _props$rootBoundary === void 0 ? 'viewport' : _props$rootBoundary, _props$shouldFlip = props.shouldFlip, shouldFlip = _props$shouldFlip === void 0 ? true : _props$shouldFlip, _props$placement = props.placement, placement = _props$placement === void 0 ? 'auto' : _props$placement, fallbackPlacements = props.fallbackPlacements, PopupContainer = props.popupComponent, _props$autoFocus = props.autoFocus, autoFocus = _props$autoFocus === void 0 ? true : _props$autoFocus, _props$zIndex = props.zIndex, zIndex = _props$zIndex === void 0 ? defaultLayer : _props$zIndex, _props$shouldUseCaptu = props.shouldUseCaptureOnOutsideClick, shouldUseCaptureOnOutsideClick = _props$shouldUseCaptu === void 0 ? false : _props$shouldUseCaptu, shouldIgnoreCloseEvent = props.shouldIgnoreCloseEvent, _props$shouldRenderTo = props.shouldRenderToParent, inShouldRenderToParent = _props$shouldRenderTo === void 0 ? false : _props$shouldRenderTo, _props$shouldFitConta = props.shouldFitContainer, shouldFitContainer = _props$shouldFitConta === void 0 ? false : _props$shouldFitConta, _props$shouldDisableF = props.shouldDisableFocusLock, shouldDisableFocusLock = _props$shouldDisableF === void 0 ? false : _props$shouldDisableF, _props$shouldReturnFo = props.shouldReturnFocus, shouldReturnFocus = _props$shouldReturnFo === void 0 ? true : _props$shouldReturnFo, strategy = props.strategy, role = props.role, label = props.label, titleId = props.titleId, modifiers = props.modifiers, shouldFitViewport = props.shouldFitViewport; var _useState = useState(null), _useState2 = _slicedToArray(_useState, 2), triggerRef = _useState2[0], setTriggerRef = _useState2[1]; var getMergedTriggerRef = useGetMemoizedMergedTriggerRef(); var getMergedTriggerRefNew = useGetMemoizedMergedTriggerRefNew(); var generatedId = useId(); var _usePopupAppearance = usePopupAppearance({ appearance: inAppearance, shouldRenderToParent: inShouldRenderToParent }), appearance = _usePopupAppearance.appearance, shouldRenderToParent = _usePopupAppearance.shouldRenderToParent; var id = providedId || generatedId; var handleOpenLayerObserverCloseSignal = useCallback(function () { onClose === null || onClose === void 0 || onClose(null); }, [onClose]); useNotifyOpenLayerObserver({ isOpen: isOpen, onClose: handleOpenLayerObserverCloseSignal, type: 'popup' }); // `xcss` is part of Popup's public API and is forwarded as-is to // the internal PopperWrapper, which rebuilds the inner styles. We // re-bind via a property accessor on a stable object so the // design-system css-prop lint rule's identifier-shape check no // longer flags it (avoiding a ratcheted lint suppression here). var xcssPassthrough = { value: xcss }; var renderPopperWrapper = /*#__PURE__*/React.createElement(Layering, { isDisabled: false }, /*#__PURE__*/React.createElement(PopperWrapper, { xcss: xcssPassthrough.value, appearance: appearance, content: content, isOpen: isOpen, placement: placement, fallbackPlacements: fallbackPlacements, boundary: boundary, rootBoundary: rootBoundary, shouldFlip: shouldFlip, offset: offset, popupComponent: PopupContainer, id: id, testId: testId, onClose: onClose, autoFocus: autoFocus, shouldUseCaptureOnOutsideClick: shouldUseCaptureOnOutsideClick, shouldIgnoreCloseEvent: shouldIgnoreCloseEvent, shouldRenderToParent: shouldRenderToParent || shouldFitContainer, shouldFitContainer: shouldFitContainer, shouldDisableFocusLock: shouldDisableFocusLock, shouldReturnFocus: shouldReturnFocus, triggerRef: triggerRef, zIndex: zIndex, strategy: shouldFitContainer ? 'absolute' : strategy, role: role, label: label, titleId: titleId, modifiers: modifiers, shouldFitViewport: shouldFitViewport })); var popupContent = /*#__PURE__*/React.createElement(Manager, null, /*#__PURE__*/React.createElement(Reference, null, function (_ref) { var ref = _ref.ref; return trigger({ ref: !fg('platform-design-system-popup-ref') ? getMergedTriggerRef(ref, setTriggerRef, isOpen) : getMergedTriggerRefNew(ref, setTriggerRef), 'aria-controls': isOpen ? id : undefined, 'aria-expanded': isOpen, 'aria-haspopup': role === 'dialog' && fg('platform_dst_popup-disable-focuslock') ? 'dialog' : true }); }), !fg('platform-dst-motion-uplift-popup') && isOpen && (shouldRenderToParent || shouldFitContainer ? renderPopperWrapper : /*#__PURE__*/React.createElement(Portal, { zIndex: zIndex }, renderPopperWrapper)), fg('platform-dst-motion-uplift-popup') && /*#__PURE__*/React.createElement(ExitingPersistence, { appear: true }, isOpen && (shouldRenderToParent || shouldFitContainer ? renderPopperWrapper : /*#__PURE__*/React.createElement(Portal, { zIndex: zIndex }, renderPopperWrapper)))); if (shouldFitContainer) { return /*#__PURE__*/React.createElement(Box, { xcss: wrapperStyles.root }, popupContent); } return popupContent; }; export var Popup = /*#__PURE__*/memo(function (props) { // Choose the rendering implementation at the component boundary rather than // gating hooks inside a single component. Each implementation owns its own // hooks unconditionally, so a runtime feature-flag change swaps component // types (a clean remount) instead of changing the hook order of a mounted // component. if (fg('platform-dst-top-layer')) { // Pass the original props object to preserve the discriminated union // (shouldFitContainer: true vs false) that is lost after destructuring. return /*#__PURE__*/React.createElement(PopupTopLayer, props); } return /*#__PURE__*/React.createElement(PopupLegacy, props); });