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oBACf,OAAO;wBACL,CAAC,CAAA,GAAA,sCAAW,EAAE,EAAE,CAAC;wBACjB,OAAO;4BAAC,GAAG,UAAU;4BAAE,OAAO;wBAAC;oBACjC;gBACF;aAAE;YACF;gBAAC,CAAA,GAAA,uCAAY;gBAAG;oBACd,OAAO;wBACL,CAAC,CAAA,GAAA,sCAAW,EAAE,EAAE,CAAC;wBACjB,OAAO;4BACL,SAAS,IAAM,OAAO;wBACxB;oBACF;gBACF;aAAE;SACH;OACA,YAAY,QAAQ;AAI7B","sources":["packages/react-aria-components/src/Dialog.tsx"],"sourcesContent":["/*\n * Copyright 2022 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 */\nimport {AriaDialogProps, useDialog} from 'react-aria/useDialog';\n\nimport {ButtonContext} from './Button';\nimport {ContextValue, DEFAULT_SLOT, dom, DOMRenderProps, Provider, SlotProps, StyleProps, useContextProps, useRenderProps} from './utils';\nimport {filterDOMProps} from 'react-aria/filterDOMProps';\nimport {forwardRefType, GlobalDOMAttributes} from '@react-types/shared';\nimport {HeadingContext} from './Heading';\nimport {mergeProps} from 'react-aria/mergeProps';\nimport {OverlayTriggerProps, OverlayTriggerState} from 'react-stately/useOverlayTriggerState';\nimport {PopoverContext} from './Popover';\nimport {PressResponder} from 'react-aria/private/interactions/PressResponder';\nimport React, {createContext, ForwardedRef, forwardRef, JSX, ReactNode, useCallback, useContext, useRef, useState} from 'react';\nimport {RootMenuTriggerStateContext} from './Menu';\nimport {useId} from 'react-aria/useId';\nimport {useMenuTriggerState} from 'react-stately/useMenuTriggerState';\nimport {useOverlayTrigger} from 'react-aria/useOverlayTrigger';\nimport {useResizeObserver} from 'react-aria/private/utils/useResizeObserver';\n\nexport interface DialogTriggerProps extends OverlayTriggerProps {\n  children: ReactNode\n}\n\nexport interface DialogRenderProps {\n  close: () => void\n}\n\nexport interface DialogProps extends AriaDialogProps, StyleProps, SlotProps, DOMRenderProps<'section', undefined>, GlobalDOMAttributes<HTMLElement> {\n  /**\n   * The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element.\n   * @default 'react-aria-Dialog'\n   */\n  className?: string,\n  /** Children of the dialog. A function may be provided to access a function to close the dialog. */\n  children?: ReactNode | ((opts: DialogRenderProps) => ReactNode)\n}\n\nexport const DialogContext = createContext<ContextValue<DialogProps, HTMLElement>>(null);\nexport const OverlayTriggerStateContext = createContext<OverlayTriggerState | null>(null);\n\n/**\n * A DialogTrigger opens a dialog when a trigger element is pressed.\n */\nexport function DialogTrigger(props: DialogTriggerProps): JSX.Element {\n  // Use useMenuTriggerState instead of useOverlayTriggerState in case a menu is embedded in the dialog.\n  // This is needed to handle submenus.\n  let state = useMenuTriggerState(props);\n\n  let buttonRef = useRef<HTMLButtonElement>(null);\n  let {triggerProps, overlayProps} = useOverlayTrigger({type: 'dialog'}, state, buttonRef);\n\n  // Allows popover width to match trigger element\n  let [buttonWidth, setButtonWidth] = useState<string | null>(null);\n  let onResize = useCallback(() => {\n    if (buttonRef.current) {\n      setButtonWidth(buttonRef.current.offsetWidth + 'px');\n    }\n  }, [buttonRef]);\n\n  useResizeObserver({\n    ref: buttonRef,\n    onResize: onResize\n  });\n\n  // Label dialog by the trigger as a fallback if there is no title slot.\n  // This is done in RAC instead of hooks because otherwise we cannot distinguish\n  // between context and props. Normally aria-labelledby overrides the title\n  // but when sent by context we want the title to win.\n  triggerProps.id = useId();\n  overlayProps['aria-labelledby'] = triggerProps.id;\n\n  return (\n    <Provider\n      values={[\n        [OverlayTriggerStateContext, state],\n        [RootMenuTriggerStateContext, state],\n        [DialogContext, overlayProps],\n        [PopoverContext, {\n          trigger: 'DialogTrigger',\n          triggerRef: buttonRef,\n          'aria-labelledby': overlayProps['aria-labelledby'],\n          style: {'--trigger-width': buttonWidth} as React.CSSProperties\n        }]\n      ]}>\n      <PressResponder {...triggerProps} ref={buttonRef} isPressed={state.isOpen}>\n        {props.children}\n      </PressResponder>\n    </Provider>\n  );\n}\n\n/**\n * A dialog is an overlay shown above other content in an application.\n */\nexport const Dialog = /*#__PURE__*/ (forwardRef as forwardRefType)(function Dialog(props: DialogProps, ref: ForwardedRef<HTMLElement>) {\n  let originalAriaLabelledby = props['aria-labelledby'];\n  [props, ref] = useContextProps(props, ref, DialogContext);\n  let {dialogProps, titleProps} = useDialog({\n    ...props,\n    // Only pass aria-labelledby from props, not context.\n    // Context is used as a fallback below.\n    'aria-labelledby': originalAriaLabelledby\n  }, ref);\n  let state = useContext(OverlayTriggerStateContext);\n\n  if (!dialogProps['aria-label'] && !dialogProps['aria-labelledby']) {\n    // If aria-labelledby exists on props, we know it came from context.\n    // Use that as a fallback in case there is no title slot.\n    if (props['aria-labelledby']) {\n      dialogProps['aria-labelledby'] = props['aria-labelledby'];\n    } else if (process.env.NODE_ENV !== 'production') {\n      console.warn('If a Dialog does not contain a <Heading slot=\"title\">, it must have an aria-label or aria-labelledby attribute for accessibility.');\n    }\n  }\n\n  let renderProps = useRenderProps({\n    defaultClassName: 'react-aria-Dialog',\n    className: props.className,\n    style: props.style,\n    children: props.children,\n    values: {\n      close: state?.close || (() => {})\n    }\n  });\n\n  let DOMProps = filterDOMProps(props, {global: true});\n\n  return (\n    <dom.section\n      {...mergeProps(DOMProps, renderProps, dialogProps)}\n      render={props.render}\n      ref={ref}\n      slot={props.slot || undefined}>\n      <Provider\n        values={[\n          [HeadingContext, {\n            slots: {\n              [DEFAULT_SLOT]: {},\n              title: {...titleProps, level: 2}\n            }\n          }],\n          [ButtonContext, {\n            slots: {\n              [DEFAULT_SLOT]: {},\n              close: {\n                onPress: () => state?.close()\n              }\n            }\n          }]\n        ]}>\n        {renderProps.children}\n      </Provider>\n    </dom.section>\n  );\n});\n"],"names":[],"version":3,"file":"Dialog.cjs.map"}