{"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AA4BM,SAAS,0CAAgB,KAAmC;IACjE,IAAI,YACF,QAAQ,QACR,OAAO,oBACP,SAAS,iBACT,aAAa,6BACb,yBAAyB,EAC1B,GAAG;IAEJ,IAAI,aAAa,CAAA,GAAA,sCAAI,EAAE,QAAQ,CAAC,OAAO,CAAC;IACxC,IAAI,WAAW,MAAM,GAAG,GACtB,MAAM,IAAI,MAAM;IAGlB,IAAI,CAAC,WAAW,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAuB;IAE9D,6EAA6E;IAC7E,0DAA0D;IAC1D,IAAI,QAAkC;IACtC,IAAI,MAAM,OAAO,CAAC,WAChB,QAAQ,SAAS,IAAI,CAAC,CAAA,GAAA,sCAAI,EAAE,cAAc;SACrC,kBAAI,CAAA,GAAA,sCAAI,EAAE,cAAc,CAAC,WAC9B,QAAQ;IAGV,IAAI,SAAS,UAAU,WACrB,aAAa;IAGf,IAAI,UAAU;cACZ;QACA,SAAS;uBACT;IACF;IAEA,IAAI,QAAQ,CAAA,GAAA,gEAAqB,EAAE;QACjC,QAAQ,CAAC,CAAC;QACV,cAAc,CAAA;YACZ,IAAI,CAAC,QACH;QAEJ;IACF;IAEA,qBACE,0DAAC,CAAA,GAAA,+BAAI;QACH,OAAO;QACP,MAAM;QACN,eAAe;QACf,2BAA2B;qBAC3B,0DAAC,CAAA,GAAA,uCAAY,EAAE,QAAQ;QAAC,OAAO;OAC5B;AAIT","sources":["packages/@adobe/react-spectrum/src/dialog/DialogContainer.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 React, {JSX, ReactElement, ReactNode, useState} from 'react';\nimport {useOverlayTriggerState} from 'react-stately/useOverlayTriggerState';\n\nexport interface SpectrumDialogContainerProps {\n  /** The Dialog to display, if any. */\n  children: ReactNode,\n  /** Handler that is called when the 'x' button of a dismissable Dialog is clicked. */\n  onDismiss: () => void,\n  /**\n   * The type of Dialog that should be rendered. See the visual options below for examples of each.\n   * @default 'modal'\n   */\n  type?: 'modal' | 'fullscreen' | 'fullscreenTakeover',\n  /** Whether the Dialog is dismissable. See the [Dialog docs](Dialog.html#dismissable-dialogs) for more details. */\n  isDismissable?: boolean,\n  /** Whether pressing the escape key to close the dialog should be disabled. */\n  isKeyboardDismissDisabled?: boolean\n}\n\n/**\n * A DialogContainer accepts a single Dialog as a child, and manages showing and hiding\n * it in a modal. Useful in cases where there is no trigger element\n * or when the trigger unmounts while the dialog is open.\n */\nexport function DialogContainer(props: SpectrumDialogContainerProps): JSX.Element {\n  let {\n    children,\n    type = 'modal',\n    onDismiss,\n    isDismissable,\n    isKeyboardDismissDisabled\n  } = props;\n\n  let childArray = React.Children.toArray(children);\n  if (childArray.length > 1) {\n    throw new Error('Only a single child can be passed to DialogContainer.');\n  }\n\n  let [lastChild, setLastChild] = useState<ReactElement | null>(null);\n\n  // React.Children.toArray mutates the children, and we need them to be stable\n  // between renders so that the lastChild comparison works.\n  let child: ReactElement | undefined = undefined;\n  if (Array.isArray(children)) {\n    child = children.find(React.isValidElement);\n  } else if (React.isValidElement(children)) {\n    child = children;\n  }\n\n  if (child && child !== lastChild) {\n    setLastChild(child);\n  }\n\n  let context = {\n    type,\n    onClose: onDismiss,\n    isDismissable\n  };\n\n  let state = useOverlayTriggerState({\n    isOpen: !!child,\n    onOpenChange: isOpen => {\n      if (!isOpen) {\n        onDismiss();\n      }\n    }\n  });\n\n  return (\n    <Modal\n      state={state}\n      type={type}\n      isDismissable={isDismissable}\n      isKeyboardDismissDisabled={isKeyboardDismissDisabled}>\n      <DialogContext.Provider value={context}>\n        {lastChild}\n      </DialogContext.Provider>\n    </Modal>\n  );\n}\n"],"names":[],"version":3,"file":"DialogContainer.cjs.map"}