UNPKG

@atlaskit/popup

Version:

A popup displays brief content in an overlay.

154 lines (153 loc) • 6 kB
/* popup.tsx generated by @compiled/babel-plugin v3.0.2 */ /* eslint-disable @repo/internal/react/require-jsdoc */ import "./popup.compiled.css"; import * as React from 'react'; import { ax, ix } from "@compiled/react/runtime"; 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'; const defaultLayer = 400; const wrapperStyles = { root: "_kqswh2mm" }; const PopupLegacy = props => { const { xcss, appearance: inAppearance = 'default', isOpen, id: providedId, offset, testId, trigger, content, onClose, boundary, rootBoundary = 'viewport', shouldFlip = true, placement = 'auto', fallbackPlacements, popupComponent: PopupContainer, autoFocus = true, zIndex = defaultLayer, shouldUseCaptureOnOutsideClick = false, shouldIgnoreCloseEvent, shouldRenderToParent: inShouldRenderToParent = false, shouldFitContainer = false, shouldDisableFocusLock = false, shouldReturnFocus = true, strategy, role, label, titleId, modifiers, shouldFitViewport } = props; const [triggerRef, setTriggerRef] = useState(null); const getMergedTriggerRef = useGetMemoizedMergedTriggerRef(); const getMergedTriggerRefNew = useGetMemoizedMergedTriggerRefNew(); const generatedId = useId(); const { appearance, shouldRenderToParent } = usePopupAppearance({ appearance: inAppearance, shouldRenderToParent: inShouldRenderToParent }); const id = providedId || generatedId; const handleOpenLayerObserverCloseSignal = useCallback(() => { onClose === null || onClose === void 0 ? void 0 : onClose(null); }, [onClose]); useNotifyOpenLayerObserver({ 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). const xcssPassthrough = { value: xcss }; const 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 })); const popupContent = /*#__PURE__*/React.createElement(Manager, null, /*#__PURE__*/React.createElement(Reference, null, ({ 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 const Popup = /*#__PURE__*/memo(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); });