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,aAAa;QACzB,OAAO;OACN,OAAO,YAAY,aAAa,QAAQ,MAAM,KAAK,IAAI;IAI5D,qBACE,0DAAC;QACC,MAAK;QACL,OAAO;QACP,cAAc;QACd,aAAa;QACb,SAAS;QACT,SAAS;;AAEf;AAYA,SAAS,wCAAkB,QAAC,IAAI,SAAE,KAAK,iBAAE,aAAa,eAAE,cAAc,CAAC,iBAAG,eAAe,CAAC,YAAG,OAAO,WAAE,OAAO,EAA4B;IACvI,IAAI,UAAU;cACZ;QACA,SAAS,MAAM,KAAK;uBACpB;QACA,GAAG,WAAW;IAChB;IAEA,qBACE,0DAAC,CAAA,GAAA,qBAAO,uBACN,0DAAC,CAAA,GAAA,gEAAa;QACX,GAAG,YAAY;QAChB,SAAS,MAAM,MAAM;QACrB,WAAW,MAAM,MAAM,IAAI,SAAS,WAAW,SAAS,gBAAgB,SAAS;OAChF,wBAEH,0DAAC,CAAA,GAAA,uCAAY,EAAE,QAAQ;QAAC,OAAO;OAC5B;AAIT","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 {OverlayTriggerProps, OverlayTriggerState, useOverlayTriggerState} 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  /** The Dialog and its trigger element. See the DialogTrigger [Content section](#content) for more information on what to provide as children. */\n  children: [ReactElement, SpectrumDialogClose | ReactElement],\n  /**\n   * The type of Dialog that should be rendered. See the DialogTrigger [types section](#dialog-types) for an explanation on each.\n   * @default 'modal'\n   */\n  type?: 'modal' | 'popover' | 'tray' | 'fullscreen' | 'fullscreenTakeover',\n  /** The type of Dialog that should be rendered when on a mobile device. See DialogTrigger [types section](#dialog-types) for an explanation on each. */\n  mobileType?: 'modal' | 'tray' | 'fullscreen' | 'fullscreenTakeover',\n  /**\n   * Whether a popover type Dialog's arrow should be hidden.\n   */\n  hideArrow?: boolean,\n  /** The ref of the element the Dialog should visually attach itself to. Defaults to the trigger button if not defined. */\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   \n  useEffect(() => {\n    return () => {\n      if ((wasOpen.current || isExiting.current) && type !== 'popover' && type !== 'tray' && process.env.NODE_ENV !== 'production') {\n        console.warn('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  // 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  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\n            state={state}\n            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// 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 Dialog's\n * open state with the trigger's press state. Additionally, it allows you to customize the type and\n * 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\n      {...props}\n      hideArrow={hideArrow}\n      triggerRef={targetRef || triggerRef}\n      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\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({type, state, isDismissable, dialogProps = {}, triggerProps = {}, overlay, trigger}: 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={state.isOpen && type !== 'modal' && type !== 'fullscreen' && type !== 'fullscreenTakeover'}>\n        {trigger}\n      </PressResponder>\n      <DialogContext.Provider value={context}>\n        {overlay}\n      </DialogContext.Provider>\n    </Fragment>\n  );\n}\n"],"names":[],"version":3,"file":"DialogTrigger.cjs.map"}