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;OACnF,OAAO,YAAY,aAAa,QAAQ,MAAM,KAAK,IAAI;IAI5D,qBACE,gCAAC;QACC,MAAK;QACL,OAAO;QACP,cAAc;QACd,aAAa;QACb,SAAS;QACT,SAAS;;AAGf;AAYA,SAAS,wCAAkB,QACzB,IAAI,SACJ,KAAK,iBACL,aAAa,eACb,cAAc,CAAC,iBACf,eAAe,CAAC,YAChB,OAAO,WACP,OAAO,EACmB;IAC1B,IAAI,UAAU;cACZ;QACA,SAAS,MAAM,KAAK;uBACpB;QACA,GAAG,WAAW;IAChB;IAEA,qBACE,gCAAC,CAAA,GAAA,eAAO,uBACN,gCAAC,CAAA,GAAA,qBAAa;QACX,GAAG,YAAY;QAChB,SAAS,MAAM,MAAM;QACrB,WACE,MAAM,MAAM,IAAI,SAAS,WAAW,SAAS,gBAAgB,SAAS;OAEvE,wBAEH,gCAAC,CAAA,GAAA,yCAAY,EAAE,QAAQ;QAAC,OAAO;OAAU;AAG/C","sources":["packages/@adobe/react-spectrum/src/dialog/DialogTrigger.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DialogContext} from './context';\nimport {Modal} from '../overlays/Modal';\nimport {\n  OverlayTriggerProps,\n  OverlayTriggerState,\n  useOverlayTriggerState\n} from 'react-stately/useOverlayTriggerState';\nimport {Popover} from '../overlays/Popover';\nimport {PositionProps} from 'react-aria/useOverlayPosition';\nimport {PressResponder} from 'react-aria/private/interactions/PressResponder';\nimport React, {Fragment, JSX, ReactElement, RefObject, useEffect, useRef} from 'react';\nimport {SpectrumDialogProps} from './Dialog';\nimport {Tray} from '../overlays/Tray';\nimport {useIsMobileDevice} from '../utils/useIsMobileDevice';\nimport {useOverlayTrigger} from 'react-aria/useOverlayTrigger';\n\nexport type SpectrumDialogClose = (close: () => void) => ReactElement;\n\nexport interface SpectrumDialogTriggerProps extends OverlayTriggerProps, PositionProps {\n  /**\n   * The Dialog and its trigger element. See the DialogTrigger [Content section](#content) for more\n   * information on what to provide as children.\n   */\n  children: [ReactElement, SpectrumDialogClose | ReactElement];\n  /**\n   * The type of Dialog that should be rendered. See the DialogTrigger [types\n   * section](#dialog-types) for an explanation on each.\n   *\n   * @default 'modal'\n   */\n  type?: 'modal' | 'popover' | 'tray' | 'fullscreen' | 'fullscreenTakeover';\n  /**\n   * The type of Dialog that should be rendered when on a mobile device. See DialogTrigger [types\n   * section](#dialog-types) for an explanation on each.\n   */\n  mobileType?: 'modal' | 'tray' | 'fullscreen' | 'fullscreenTakeover';\n  /**\n   * Whether a popover type Dialog's arrow should be hidden.\n   */\n  hideArrow?: boolean;\n  /**\n   * The ref of the element the Dialog should visually attach itself to. Defaults to the trigger\n   * button if not defined.\n   */\n  targetRef?: RefObject<HTMLElement | null>;\n  /** Whether a modal type Dialog should be dismissable. */\n  isDismissable?: boolean;\n  /** Whether pressing the escape key to close the dialog should be disabled. */\n  isKeyboardDismissDisabled?: boolean;\n}\n\nfunction DialogTrigger(props: SpectrumDialogTriggerProps) {\n  let {\n    children,\n    type = 'modal',\n    mobileType = type === 'popover' ? 'modal' : type,\n    hideArrow,\n    targetRef,\n    isDismissable,\n    isKeyboardDismissDisabled,\n    ...positionProps\n  } = props;\n  if (!Array.isArray(children) || children.length > 2) {\n    throw new Error('DialogTrigger must have exactly 2 children');\n  }\n  // if a function is passed as the second child, it won't appear in toArray\n  let [trigger, content] = children as [ReactElement, SpectrumDialogClose];\n\n  // On small devices, show a modal or tray instead of a popover.\n  let isMobile = useIsMobileDevice();\n  if (isMobile) {\n    // handle cases where desktop popovers need a close button for the mobile modal view\n    if (type !== 'modal' && mobileType === 'modal') {\n      isDismissable = true;\n    }\n\n    type = mobileType;\n  }\n\n  let state = useOverlayTriggerState(props);\n  let wasOpen = useRef(false);\n  useEffect(() => {\n    wasOpen.current = state.isOpen;\n  }, [state.isOpen]);\n\n  let isExiting = useRef(false);\n  let onExiting = () => (isExiting.current = true);\n  let onExited = () => (isExiting.current = false);\n\n  useEffect(() => {\n    return () => {\n      if (\n        (wasOpen.current || isExiting.current) &&\n        type !== 'popover' &&\n        type !== 'tray' &&\n        process.env.NODE_ENV !== 'production'\n      ) {\n        console.warn(\n          'A DialogTrigger unmounted while open. This is likely due to being placed within a trigger that unmounts or inside a conditional. Consider using a DialogContainer instead.'\n        );\n      }\n    };\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, []);\n\n  if (type === 'popover') {\n    return (\n      <PopoverTrigger\n        {...positionProps}\n        state={state}\n        targetRef={targetRef}\n        trigger={trigger}\n        content={content}\n        isKeyboardDismissDisabled={isKeyboardDismissDisabled}\n        hideArrow={hideArrow}\n      />\n    );\n  }\n\n  let renderOverlay = () => {\n    switch (type) {\n      case 'fullscreen':\n      case 'fullscreenTakeover':\n      case 'modal':\n        return (\n          <Modal\n            state={state}\n            isDismissable={type === 'modal' ? isDismissable : false}\n            type={type}\n            isKeyboardDismissDisabled={isKeyboardDismissDisabled}\n            onExiting={onExiting}\n            onExited={onExited}>\n            {typeof content === 'function' ? content(state.close) : content}\n          </Modal>\n        );\n      case 'tray':\n        return (\n          <Tray state={state} isKeyboardDismissDisabled={isKeyboardDismissDisabled}>\n            {typeof content === 'function' ? content(state.close) : content}\n          </Tray>\n        );\n    }\n  };\n\n  return (\n    <DialogTriggerBase\n      type={type}\n      state={state}\n      isDismissable={isDismissable}\n      trigger={trigger}\n      overlay={renderOverlay()}\n    />\n  );\n}\n\n// Support DialogTrigger inside components using CollectionBuilder.\nDialogTrigger.getCollectionNode = function* (props: SpectrumDialogTriggerProps) {\n  // @ts-ignore - seems like types are wrong. Function children work fine.\n  let [trigger] = React.Children.toArray(props.children);\n  let [, content] = props.children as [ReactElement, SpectrumDialogClose];\n  yield {\n    element: trigger,\n    wrapper: element => (\n      <DialogTrigger key={element.key} {...props}>\n        {element}\n        {content}\n      </DialogTrigger>\n    )\n  };\n};\n\n/**\n * DialogTrigger serves as a wrapper around a Dialog and its associated trigger, linking the\n * Dialog's open state with the trigger's press state. Additionally, it allows you to customize the\n * type and positioning of the Dialog.\n */\n\n// We don't want getCollectionNode to show up in the type definition\nlet _DialogTrigger = DialogTrigger as (props: SpectrumDialogTriggerProps) => JSX.Element;\nexport {_DialogTrigger as DialogTrigger};\n\nfunction PopoverTrigger({state, targetRef, trigger, content, hideArrow, ...props}) {\n  let triggerRef = useRef<HTMLElement>(null);\n  let {triggerProps, overlayProps} = useOverlayTrigger({type: 'dialog'}, state, triggerRef);\n\n  let triggerPropsWithRef = {\n    ...triggerProps,\n    ref: targetRef ? undefined : triggerRef\n  };\n\n  let overlay = (\n    <Popover {...props} hideArrow={hideArrow} triggerRef={targetRef || triggerRef} state={state}>\n      {typeof content === 'function' ? content(state.close) : content}\n    </Popover>\n  );\n\n  return (\n    <DialogTriggerBase\n      type=\"popover\"\n      state={state}\n      triggerProps={triggerPropsWithRef}\n      dialogProps={overlayProps}\n      trigger={trigger}\n      overlay={overlay}\n    />\n  );\n}\n\ninterface SpectrumDialogTriggerBase {\n  type: 'modal' | 'popover' | 'tray' | 'fullscreen' | 'fullscreenTakeover';\n  state: OverlayTriggerState;\n  isDismissable?: boolean;\n  dialogProps?: SpectrumDialogProps | {};\n  triggerProps?: any;\n  overlay?: ReactElement;\n  trigger: ReactElement;\n}\n\nfunction DialogTriggerBase({\n  type,\n  state,\n  isDismissable,\n  dialogProps = {},\n  triggerProps = {},\n  overlay,\n  trigger\n}: SpectrumDialogTriggerBase) {\n  let context = {\n    type,\n    onClose: state.close,\n    isDismissable,\n    ...dialogProps\n  };\n\n  return (\n    <Fragment>\n      <PressResponder\n        {...triggerProps}\n        onPress={state.toggle}\n        isPressed={\n          state.isOpen && type !== 'modal' && type !== 'fullscreen' && type !== 'fullscreenTakeover'\n        }>\n        {trigger}\n      </PressResponder>\n      <DialogContext.Provider value={context}>{overlay}</DialogContext.Provider>\n    </Fragment>\n  );\n}\n"],"names":[],"version":3,"file":"DialogTrigger.mjs.map"}