feat(PortalsProvider): add PortalsProvider

- will be used with ReactDOM.createPortal to render components to elements that are outside their tree hierarchy
This commit is contained in:
Aminejv 2021-09-24 17:57:51 +01:00
parent 4828c7ac02
commit 3be39eccc4
2 changed files with 45 additions and 25 deletions

View File

@ -49,6 +49,7 @@ import SidebarEditTags from "~/components/sidebars/SidebarEditTags";
import ApplicationHeader from "~/components/core/ApplicationHeader";
import ApplicationLayout from "~/components/core/ApplicationLayout";
import WebsitePrototypeWrapper from "~/components/core/WebsitePrototypeWrapper";
import PortalsProvider from "~/components/core/PortalsProvider";
import CTATransition from "~/components/core/CTATransition";
import { GlobalModal } from "~/components/system/components/GlobalModal";
@ -496,31 +497,34 @@ export default class ApplicationPage extends React.Component {
// }
return (
<React.Fragment>
<ApplicationLayout
sidebarName={this.state.sidebar}
page={page}
onAction={this._handleAction}
header={headerElement}
sidebar={sidebarElement}
onDismissSidebar={this._handleDismissSidebar}
isMobile={this.state.isMobile}
isMac={this.props.isMac}
viewer={this.state.viewer}
>
{this.state.loading ? (
<div
css={Styles.CONTAINER_CENTERED}
style={{
width: "100vw",
height: "100vh",
}}
>
<LoaderSpinner style={{ height: 32, width: 32 }} />
</div>
) : (
scene
)}
</ApplicationLayout>
<PortalsProvider>
<ApplicationLayout
sidebarName={this.state.sidebar}
page={page}
onAction={this._handleAction}
header={headerElement}
sidebar={sidebarElement}
onDismissSidebar={this._handleDismissSidebar}
fileLoading={this.state.fileLoading}
isMobile={this.state.isMobile}
isMac={this.props.isMac}
viewer={this.state.viewer}
>
{this.state.loading ? (
<div
css={Styles.CONTAINER_CENTERED}
style={{
width: "100vw",
height: "100vh",
}}
>
<LoaderSpinner style={{ height: 32, width: 32 }} />
</div>
) : (
scene
)}
</ApplicationLayout>
</PortalsProvider>
<GlobalModal />
<SearchModal
viewer={this.state.viewer}

View File

@ -0,0 +1,16 @@
import * as React from "react";
/**
* NOTE(amine): Component used to assign Portals in client side
*/
const LayoutContext = React.createContext({});
export default function PortalsProvider({ children }) {
const filterNavbar = React.useState();
const contextValue = React.useMemo(() => ({ filterNavbar }), [filterNavbar]);
return <LayoutContext.Provider value={contextValue}>{children}</LayoutContext.Provider>;
}
export const usePortals = () => React.useContext(LayoutContext);