(react) add custom modal portal

In some apps this is mostly needed, for instance: when the
CunninghamProvider is nested in the DOM, we want the modal to still
be displayed on top of anything else, then in those cases we will be
able to define a node directly in the body and tell cunningham to
render modals inside it.
This commit is contained in:
Nathan Vasse
2024-04-04 16:59:12 +02:00
committed by NathanVss
parent 6ebeb116d3
commit 2916dd2af9
5 changed files with 75 additions and 5 deletions

View File

@@ -34,6 +34,7 @@ interface Props extends PropsWithChildren {
customLocales?: Record<string, TranslationSet>;
currentLocale?: string;
theme?: string;
modalParentSelector?: () => HTMLElement;
}
export const DEFAULT_LOCALE = Locales.enUS;
@@ -53,6 +54,7 @@ export const CunninghamProvider = ({
currentLocale = DEFAULT_LOCALE,
customLocales,
theme = DEFAULT_THEME,
modalParentSelector,
children,
}: Props) => {
const locales: Record<string, TranslationSet> = useMemo(
@@ -102,7 +104,7 @@ export const CunninghamProvider = ({
return (
<CunninghamContext.Provider value={context}>
<ModalProvider>
<ModalProvider modalParentSelector={modalParentSelector}>
<div className="c__app">
<ToastProvider>{children}</ToastProvider>
</div>