The previous layout nested two scroll regions, sidebar and main, each with its own scrollbar. Combined with the fixed 100vh flex container, any child overflow (notably the sidebar nav) spilled past bg-level-0 and exposed the browser's default white background -- most visible in dark mode as a white strip at the bottom of the viewport. Switch to a single page-level scroll: pin the header with fixed, let the wrapper grow with min-h-screen, and drop main's internal overflow. The drawer becomes fixed too so it stays pinned while the page scrolls and gets an opaque background to cover scrolled content behind it. Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
123 lines
3.5 KiB
TypeScript
123 lines
3.5 KiB
TypeScript
// Copyright (c) 2025-2026 Probo Inc <hello@getprobo.com>.
|
|
//
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
// copyright notice and this permission notice appear in all copies.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
// PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
import { clsx } from "clsx";
|
|
import {
|
|
createContext,
|
|
type PropsWithChildren,
|
|
type ReactNode,
|
|
useContext,
|
|
useEffect,
|
|
useMemo,
|
|
useState,
|
|
} from "react";
|
|
import { createPortal } from "react-dom";
|
|
import { Link } from "react-router";
|
|
|
|
import { Logo } from "../Atoms/Logo/Logo";
|
|
import { Sidebar } from "../Atoms/Sidebar/Sidebar";
|
|
import { Toasts } from "../Atoms/Toasts/Toasts";
|
|
import { ConfirmDialog } from "../Molecules/Dialog/ConfirmDialog";
|
|
|
|
type Props = PropsWithChildren<{
|
|
headerLeading?: ReactNode;
|
|
headerTrailing: ReactNode;
|
|
sidebar?: ReactNode;
|
|
}>;
|
|
|
|
const LayoutContext = createContext({
|
|
setDrawer: (() => {}) as (v: boolean) => void,
|
|
});
|
|
|
|
export function Layout({
|
|
headerLeading,
|
|
headerTrailing,
|
|
sidebar,
|
|
children,
|
|
}: Props) {
|
|
const [hasDrawer, setDrawer] = useState(false);
|
|
const layoutContext = useMemo(
|
|
() => ({
|
|
setDrawer,
|
|
}),
|
|
[],
|
|
);
|
|
return (
|
|
<LayoutContext value={layoutContext}>
|
|
<div className="text-txt-primary bg-level-0 min-h-screen">
|
|
<header className="fixed top-0 z-2 left-0 right-0 px-4 flex items-center border-b border-border-solid h-12 bg-level-0">
|
|
<Link to="/">
|
|
<Logo className="w-12 h-5" />
|
|
</Link>
|
|
{headerLeading && (
|
|
<>
|
|
<svg
|
|
className="mx-3 text-txt-tertiary"
|
|
width="8"
|
|
height="18"
|
|
viewBox="0 0 8 18"
|
|
fill="none"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
>
|
|
<path d="M1 17L7 1" stroke="currentColor" />
|
|
</svg>
|
|
{headerLeading}
|
|
</>
|
|
)}
|
|
<div className="ml-auto">{headerTrailing}</div>
|
|
</header>
|
|
<div className="flex min-h-screen" id="main">
|
|
{sidebar && <Sidebar>{sidebar}</Sidebar>}
|
|
<main
|
|
className={clsx(
|
|
"w-full mt-12 transition-all duration-300",
|
|
hasDrawer && "pr-105",
|
|
)}
|
|
>
|
|
<div className="py-12 px-8 max-w-[1200px] w-full mx-auto min-h-[calc(100vh-48px)]">
|
|
{children}
|
|
</div>
|
|
</main>
|
|
</div>
|
|
<Toasts />
|
|
<ConfirmDialog />
|
|
</div>
|
|
</LayoutContext>
|
|
);
|
|
}
|
|
|
|
export function Drawer({
|
|
children,
|
|
className,
|
|
}: PropsWithChildren<{ className?: string }>) {
|
|
const { setDrawer } = useContext(LayoutContext);
|
|
useEffect(() => {
|
|
setDrawer(true);
|
|
return () => {
|
|
setDrawer(false);
|
|
};
|
|
}, [setDrawer]);
|
|
return createPortal(
|
|
<aside
|
|
className={clsx(
|
|
"fixed pt-20 top-0 right-0 w-105 px-6 pb-8 border-border-solid border-l h-screen bg-level-0",
|
|
className,
|
|
)}
|
|
>
|
|
{children}
|
|
</aside>,
|
|
document.body,
|
|
);
|
|
}
|