Files
Desktop/ts/components/ModalContainer.dom.tsx
Jamie b405e3d83d Prepare for upgrade to React 19
Co-authored-by: ayumi-signal <ayumi@signal.org>
2025-12-23 13:42:56 -08:00

34 lines
968 B
TypeScript

// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import type { ReactNode } from 'react';
import ReactDOM from 'react-dom';
import { ModalContainerContext } from './ModalHost.dom.js';
type Props = {
children: ReactNode;
className?: string;
};
/**
* Provide a div directly under the document.body that Modals can use as a DOM parent.
*
* Useful when you want to control the stacking context of all children, by customizing
* the styles of the container in way that also applies to modals.
*/
export const ModalContainer = ({
children,
className,
}: Props): React.JSX.Element => {
const containerRef = React.useRef<HTMLDivElement | null>(null);
return ReactDOM.createPortal(
<div ref={containerRef} className={className}>
<ModalContainerContext.Provider value={containerRef.current}>
{children}
</ModalContainerContext.Provider>
</div>,
document.body
);
};