From 0082ca447f15d2fb3911340ebf6dfa52aa6dee52 Mon Sep 17 00:00:00 2001 From: Gianmarco Manni Date: Tue, 8 Oct 2024 14:29:20 +0200 Subject: [PATCH 1/3] x --- CHANGELOG.md | 4 ++++ .../Layout/PanelSideBarLayout/PanelSideBarLayout.tsx | 12 ++++++++++-- .../PanelSideBarLayout/PanelSideBarLayoutContent.tsx | 7 ++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e000bfb..42d047f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/lib/Layout/PanelSideBarLayout/PanelSideBarLayout.tsx b/src/lib/Layout/PanelSideBarLayout/PanelSideBarLayout.tsx index d862b76..feec452 100644 --- a/src/lib/Layout/PanelSideBarLayout/PanelSideBarLayout.tsx +++ b/src/lib/Layout/PanelSideBarLayout/PanelSideBarLayout.tsx @@ -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"; @@ -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; } export const PanelSideBarLayout = (props: PanelSideBarLayoutProps) => { @@ -50,6 +55,7 @@ export const PanelSideBarLayout = (prop collapsible = true, useToggleButton = false, useResponsiveLayout = false, + mainContentBodyRef, } = props; const { isSidebarOpen, toggleSidebar, renderFirstItemsLevelAsTiles } = usePanelSideBarContext(); @@ -76,7 +82,9 @@ export const PanelSideBarLayout = (prop > /> {collapsible && !useToggleButton && } - {children} + + {children} + ); diff --git a/src/lib/Layout/PanelSideBarLayout/PanelSideBarLayoutContent.tsx b/src/lib/Layout/PanelSideBarLayout/PanelSideBarLayoutContent.tsx index fc371be..ae0d33d 100644 --- a/src/lib/Layout/PanelSideBarLayout/PanelSideBarLayoutContent.tsx +++ b/src/lib/Layout/PanelSideBarLayout/PanelSideBarLayoutContent.tsx @@ -1,14 +1,15 @@ -import { PropsWithChildren, ReactNode } from "react"; +import { MutableRefObject, PropsWithChildren, ReactNode } from "react"; interface PanelSideBarLayoutContentProps extends PropsWithChildren { footer?: ReactNode; + mainContentBodyRef?: MutableRefObject; } export const PanelSideBarLayoutContent = (props: PanelSideBarLayoutContentProps) => { - const { children, footer } = props; + const { children, footer, mainContentBodyRef } = props; return ( -
+
{children}