Skip to content

Commit

Permalink
feat(web): adjust breakpoint and manage sidebar
Browse files Browse the repository at this point in the history
There is a lot of room for improvements, but this commits start changing
a bit the breakpoints values and the sidebar behavior becuase most
probably Agama will target a lot of 1024x768 screen resolutions, for
which is dedired to start with the sidebar open and fixed.
  • Loading branch information
dgdavid committed Jan 22, 2025
1 parent 1cf40bf commit 2308ad7
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 7 deletions.
17 changes: 17 additions & 0 deletions web/src/assets/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@

// Temporary CSS rules written during migration to PFv6

// Reserve the sidebar space also for "lg" breakpoint
@media (width >= 64rem) {
.pf-v6-c-page.agm-full-layout {
--pf-v6-c-page__sidebar--Width: 12rem; // var(--pf-v6-c-page__sidebar--xl--Width);
grid-template-areas:
"header header"
"sidebar main ";
grid-template-columns: var(--pf-v6-c-page__sidebar--Width) 1fr;
}

.pf-v6-c-page__sidebar.pf-m-collapsed + .pf-v6-c-page__drawer {
--pf-v6-c-page__main-container--GridArea: var(
--pf-v6-c-page--masthead--main-container--GridArea
);
}
}

#productSelectionForm img {
max-inline-size: 100px;
}
Expand Down
6 changes: 6 additions & 0 deletions web/src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export type HeaderProps = {
showInstallerOptions?: boolean;
/** Callback to be triggered for toggling the IssuesDrawer visibility */
toggleIssuesDrawer?: () => void;
isSidebarOpen?: boolean;
toggleSidebar?: () => void;
};

const OptionsDropdown = ({ showInstallerOptions }) => {
Expand Down Expand Up @@ -123,6 +125,8 @@ export default function Header({
showSidebarToggle = true,
showProductName = true,
toggleIssuesDrawer,
isSidebarOpen,
toggleSidebar,
}: HeaderProps): React.ReactNode {
const location = useLocation();
const { selectedProduct } = useProduct();
Expand All @@ -143,6 +147,8 @@ export default function Header({
{showSidebarToggle && (
<MastheadToggle>
<PageToggleButton
isSidebarOpen={isSidebarOpen}
onSidebarToggle={toggleSidebar}
id="uncontrolled-nav-toggle"
variant="plain"
aria-label={_("Main navigation")}
Expand Down
24 changes: 22 additions & 2 deletions web/src/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import Header, { HeaderProps } from "~/components/layout/Header";
import { Loading, Sidebar } from "~/components/layout";
import { IssuesDrawer } from "~/components/core";
import { ROOT } from "~/routes/paths";
import { agamaWidthBreakpoints, getBreakpoint } from "~/utils";

export type LayoutProps = React.PropsWithChildren<{
className?: string;
mountHeader?: boolean;
mountSidebar?: boolean;
headerOptions?: HeaderProps;
Expand All @@ -56,21 +58,35 @@ const Layout = ({
mountSidebar = true,
headerOptions = {},
children,
...props
}: LayoutProps) => {
const drawerRef = useRef();
const location = useLocation();
const [issuesDrawerVisible, setIssuesDrawerVisible] = useState<boolean>(false);
const closeIssuesDrawer = () => setIssuesDrawerVisible(false);
const toggleIssuesDrawer = () => setIssuesDrawerVisible(!issuesDrawerVisible);
const [isSidebarOpen, setIsSidebarOpen] = useState<boolean>(true);
const [windowSize, setWindowSize] = useState<number>();

const onPageResize = (_, { windowSize: newWindowSize }: { windowSize: number }) => {
if (newWindowSize === windowSize) return;
setWindowSize(newWindowSize);
mountSidebar && setIsSidebarOpen(newWindowSize >= agamaWidthBreakpoints.lg);
};

const pageProps: Omit<PageProps, keyof React.HTMLProps<HTMLDivElement>> = {
isManagedSidebar: true,
};

if (mountSidebar) pageProps.sidebar = <Sidebar />;
if (mountSidebar) {
pageProps.sidebar = <Sidebar isManagedSidebar={false} isSidebarOpen={isSidebarOpen} />;
pageProps.isManagedSidebar = false;
}
if (mountHeader) {
pageProps.masthead = (
<Header
isSidebarOpen={isSidebarOpen}
toggleSidebar={() => setIsSidebarOpen(!isSidebarOpen)}
showSidebarToggle={mountSidebar}
toggleIssuesDrawer={toggleIssuesDrawer}
{...headerOptions}
Expand All @@ -90,10 +106,12 @@ const Layout = ({
return (
<>
<Page
onPageResize={onPageResize}
getBreakpoint={getBreakpoint}
isContentFilled
{...pageProps}
{...props}
onNotificationDrawerExpand={() => focusDrawer(drawerRef.current)}
className="agm-layout"
>
<Suspense fallback={<Loading />}>{children || <Outlet />}</Suspense>
</Page>
Expand All @@ -104,6 +122,7 @@ const Layout = ({

/** Default props for FullLayout */
const fullProps: LayoutProps = {
className: "agm-full-layout",
mountHeader: true,
mountSidebar: true,
headerOptions: {
Expand All @@ -120,6 +139,7 @@ const Full = (props: LayoutProps) => <Layout {...fullProps} {...props} />;

/** Default props for PlainLayout */
const plainProps: LayoutProps = {
className: "agm-plain-layout",
mountHeader: true,
mountSidebar: false,
headerOptions: {
Expand Down
16 changes: 12 additions & 4 deletions web/src/components/layout/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) [2024] SUSE LLC
* Copyright (c) [2024-2025] SUSE LLC
*
* All Rights Reserved.
*
Expand All @@ -22,7 +22,15 @@

import React from "react";
import { NavLink } from "react-router-dom";
import { Nav, NavItem, NavList, PageSidebar, PageSidebarBody, Stack } from "@patternfly/react-core";
import {
Nav,
NavItem,
NavList,
PageSidebar,
PageSidebarBody,
PageSidebarProps,
Stack,
} from "@patternfly/react-core";
import { Icon } from "~/components/layout";
import { ChangeProductLink } from "~/components/core";
import { rootRoutes } from "~/router";
Expand Down Expand Up @@ -62,9 +70,9 @@ const MainNavigation = (): React.ReactNode => {
);
};

export default function Sidebar(): React.ReactNode {
export default function Sidebar(props: PageSidebarProps): React.ReactNode {
return (
<PageSidebar id="agama-sidebar">
<PageSidebar id="agama-sidebar" {...props}>
<PageSidebarBody isFilled>
<MainNavigation />
</PageSidebarBody>
Expand Down
34 changes: 33 additions & 1 deletion web/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) [2022-2024] SUSE LLC
* Copyright (c) [2022-2025] SUSE LLC
*
* All Rights Reserved.
*
Expand Down Expand Up @@ -407,6 +407,36 @@ const mask = (value, visible = 4, character = "*") => {
return value.replace(regex, character);
};

const agamaWidthBreakpoints = {
sm: parseInt("36rem") * 16,
md: parseInt("48rem") * 16,
lg: parseInt("64rem") * 16,
xl: parseInt("75rem") * 16,
"2xl": parseInt("90rem") * 16,
};

const getBreakpoint = (width: number): "default" | "sm" | "md" | "lg" | "xl" | "2xl" => {
if (width === null) {
return null;
}
if (width >= agamaWidthBreakpoints["2xl"]) {
return "2xl";
}
if (width >= agamaWidthBreakpoints.xl) {
return "xl";
}
if (width >= agamaWidthBreakpoints.lg) {
return "lg";
}
if (width >= agamaWidthBreakpoints.md) {
return "md";
}
if (width >= agamaWidthBreakpoints.sm) {
return "sm";
}
return "default";
};

export {
noop,
identity,
Expand All @@ -428,4 +458,6 @@ export {
slugify,
timezoneTime,
mask,
getBreakpoint,
agamaWidthBreakpoints,
};

0 comments on commit 2308ad7

Please sign in to comment.