Skip to content

Commit

Permalink
use product layout container for overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenjwatkins committed Oct 23, 2023
1 parent 31e242e commit a53e833
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions easy-ui-react/src/ProductLayout/ProductLayout.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.ProductLayout {
@include component-token("product-shell", "sidebar-width", 216px);
display: flex;
position: relative;
}

.body {
Expand Down
7 changes: 5 additions & 2 deletions easy-ui-react/src/ProductLayout/ProductLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactNode, useMemo } from "react";
import React, { ReactNode, useMemo, useRef } from "react";
import { useOverlayTrigger } from "react-aria";
import { useOverlayTriggerState } from "react-stately";
import { ProductLayoutContent } from "./ProductLayoutContent";
Expand Down Expand Up @@ -33,6 +33,8 @@ export type ProductLayoutProps = {
export function ProductLayout(props: ProductLayoutProps) {
const { sidebar, header, content } = props;

const layoutRef = useRef<HTMLDivElement | null>(null);

const state = useOverlayTriggerState({});
const { triggerProps, overlayProps } = useOverlayTrigger(
{ type: "dialog" },
Expand All @@ -41,6 +43,7 @@ export function ProductLayout(props: ProductLayoutProps) {

const context = useMemo(() => {
return {
layoutRef,
sidebarTriggerState: state,
sidebarTriggerProps: triggerProps,
sidebarOverlayProps: overlayProps,
Expand All @@ -49,7 +52,7 @@ export function ProductLayout(props: ProductLayoutProps) {

return (
<ProductLayoutContext.Provider value={context}>
<div className={styles.ProductLayout}>
<div className={styles.ProductLayout} ref={layoutRef}>
{sidebar}
<div className={styles.body}>
{header}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}

.overlay {
position: fixed;
position: absolute;
z-index: 100;
top: 0;
left: 0;
Expand Down
6 changes: 4 additions & 2 deletions easy-ui-react/src/ProductLayout/ProductLayoutSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function SidebarAsDialog(props: ProductLayoutSidebarProps) {
function SidebarAsDialogOverlay(props: { children: ReactNode }) {
const { children } = props;

const { sidebarTriggerState } = useProductLayout();
const { layoutRef, sidebarTriggerState } = useProductLayout();

const ref = React.useRef(null);
const { modalProps, underlayProps } = useModalOverlay(
Expand All @@ -83,7 +83,9 @@ function SidebarAsDialogOverlay(props: { children: ReactNode }) {
);

return (
<Overlay>
<Overlay
portalContainer={layoutRef.current ? layoutRef.current : undefined}
>
<div className={styles.overlay} {...underlayProps}>
<div ref={ref} {...modalProps}>
{children}
Expand Down
3 changes: 2 additions & 1 deletion easy-ui-react/src/ProductLayout/context.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { DOMProps } from "@react-types/shared";
import { createContext, useContext } from "react";
import { MutableRefObject, createContext, useContext } from "react";
import { AriaButtonProps } from "react-aria";
import { OverlayTriggerState } from "react-stately";

export type ProductLayoutContextType = {
layoutRef: MutableRefObject<HTMLDivElement | null>;
sidebarTriggerState: OverlayTriggerState;
sidebarTriggerProps: AriaButtonProps;
sidebarOverlayProps: DOMProps;
Expand Down

0 comments on commit a53e833

Please sign in to comment.