Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
manni497 committed Oct 8, 2024
1 parent 30abd51 commit 0082ca4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Expose `mainContentBodyRef` in order to control main body behaviour (e.g. scroll to top on page change)

## [4.1.1] - 2024-07-18

### Fixed
Expand Down
12 changes: 10 additions & 2 deletions src/lib/Layout/PanelSideBarLayout/PanelSideBarLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from "classnames";
import { PropsWithChildren, ReactNode } from "react";
import { MutableRefObject, PropsWithChildren, ReactNode } from "react";
import "../../../../styles/Layout/index.scss";
import { PanelSideBar } from "./PanelSideBar/PanelSidebar";
import { PanelSideBarLayoutContent } from "./PanelSideBarLayoutContent";
Expand Down Expand Up @@ -38,6 +38,11 @@ export interface PanelSideBarLayoutProps extends PropsWithChildren {
* If use the responsive layout when the screen is sm in order to remove the sidebar overlay.
*/
useResponsiveLayout?: boolean;

/**
* the main content body ref
*/
mainContentBodyRef?: MutableRefObject<HTMLElement | null>;
}

export const PanelSideBarLayout = <TPanelItemId extends string, TPanelItem>(props: PanelSideBarLayoutProps) => {
Expand All @@ -50,6 +55,7 @@ export const PanelSideBarLayout = <TPanelItemId extends string, TPanelItem>(prop
collapsible = true,
useToggleButton = false,
useResponsiveLayout = false,
mainContentBodyRef,
} = props;

const { isSidebarOpen, toggleSidebar, renderFirstItemsLevelAsTiles } = usePanelSideBarContext<TPanelItemId, TPanelItem>();
Expand All @@ -76,7 +82,9 @@ export const PanelSideBarLayout = <TPanelItemId extends string, TPanelItem>(prop
>
<PanelSideBar<TPanelItemId, TPanelItem> />
{collapsible && !useToggleButton && <PanelSideBarToggle onClick={toggleSidebar} toggled={!isSidebarOpen} />}
<PanelSideBarLayoutContent footer={footer}>{children}</PanelSideBarLayoutContent>
<PanelSideBarLayoutContent footer={footer} mainContentBodyRef={mainContentBodyRef}>
{children}
</PanelSideBarLayoutContent>
</section>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { PropsWithChildren, ReactNode } from "react";
import { MutableRefObject, PropsWithChildren, ReactNode } from "react";

interface PanelSideBarLayoutContentProps extends PropsWithChildren {
footer?: ReactNode;
mainContentBodyRef?: MutableRefObject<HTMLElement | null>;
}

export const PanelSideBarLayoutContent = (props: PanelSideBarLayoutContentProps) => {
const { children, footer } = props;
const { children, footer, mainContentBodyRef } = props;

return (
<section id="main-content-body" className="content">
<section ref={mainContentBodyRef} id="main-content-body" className="content">
<main className="container-fluid">{children}</main>
<footer hidden={!footer} className="py-4 bg-light mt-auto">
<div className="mx-4">
Expand Down

0 comments on commit 0082ca4

Please sign in to comment.