1- import { useMemo , useRef } from "react" ;
1+ import React , { useMemo , useRef , useState , useCallback } from "react" ;
22import styled from "@emotion/styled" ;
33import DxcFooter from "../footer/Footer" ;
44import DxcHeader from "../header/Header" ;
@@ -8,62 +8,64 @@ import { bottomLinks, findChildType, socialLinks, year } from "./utils";
88import ApplicationLayoutContext from "./ApplicationLayoutContext" ;
99
1010const ApplicationLayoutContainer = styled . div < { header ?: React . ReactNode } > `
11- top: 0;
12- left: 0;
1311 display: grid;
14- grid-template-rows: ${ ( { header } ) => ( header ? "auto 1fr" : "1fr" ) } ;
15- height: 100vh;
16- width: 100vw;
17- position: absolute;
18- overflow: hidden;
12+ grid-template-rows: ${ ( { header } ) => ( header ? "auto 1fr auto" : "1fr auto" ) } ;
13+ min-height: 100vh;
1914` ;
2015
2116const HeaderContainer = styled . div `
17+ position: sticky;
18+ top: 0;
2219 width: 100%;
23- min-height: var(--height-xxxl);
2420 height: fit-content;
2521 z-index: var(--z-app-layout-header);
2622` ;
2723
2824const BodyContainer = styled . div < { hasSidenav ?: boolean } > `
25+ position: relative;
2926 display: grid;
3027 grid-template-columns: ${ ( { hasSidenav } ) => ( hasSidenav ? "auto 1fr" : "1fr" ) } ;
3128 grid-template-rows: 1fr;
32- overflow: hidden ;
29+ min-height: 100% ;
3330` ;
3431
35- const SidenavContainer = styled . div `
32+ const SidenavContainer = styled . div < { headerHeight : string } > `
3633 width: fit-content;
3734 height: 100%;
3835 z-index: var(--z-app-layout-sidenav);
3936 position: sticky;
37+ top: ${ ( { headerHeight } ) => headerHeight || "0" } ;
4038 overflow: auto;
39+ max-height: ${ ( { headerHeight } ) => `calc(100vh - ${ headerHeight || "0" } )` } ;
4140` ;
4241
43- const MainContainer = styled . div `
44- display: flex;
45- flex-grow: 1;
46- flex-direction: column;
42+ const MainContainer = styled . main `
43+ position: relative;
44+ display: grid;
4745 width: 100%;
4846 height: 100%;
49- position: relative;
50- overflow: auto;
5147` ;
5248
5349const FooterContainer = styled . div `
5450 height: fit-content;
5551 width: 100%;
5652` ;
5753
58- const MainContentContainer = styled . main `
59- height: 100%;
60- display: grid;
61- grid-template-rows: 1fr auto;
62- ` ;
63-
6454const Main = ( { children } : AppLayoutMainPropsType ) : JSX . Element => < div > { children } </ div > ;
6555
6656const DxcApplicationLayout = ( { logo, header, sidenav, footer, children } : ApplicationLayoutPropsType ) : JSX . Element => {
57+ const [ headerHeight , setHeaderHeight ] = useState ( "0px" ) ;
58+
59+ const handleHeaderHeight = useCallback (
60+ ( headerElement : HTMLDivElement | null ) => {
61+ if ( headerElement ) {
62+ const height = headerElement . offsetHeight ;
63+ setHeaderHeight ( `${ height } px` ) ;
64+ }
65+ } ,
66+ [ header ]
67+ ) ;
68+
6769 const contextValue = useMemo ( ( ) => {
6870 return {
6971 logo,
@@ -75,24 +77,20 @@ const DxcApplicationLayout = ({ logo, header, sidenav, footer, children }: Appli
7577 return (
7678 < ApplicationLayoutContainer ref = { ref } header = { header } >
7779 < ApplicationLayoutContext . Provider value = { contextValue } >
78- { header && < HeaderContainer > { header } </ HeaderContainer > }
80+ { header && < HeaderContainer ref = { handleHeaderHeight } > { header } </ HeaderContainer > }
7981 < BodyContainer hasSidenav = { ! ! sidenav } >
80- { sidenav && < SidenavContainer > { sidenav } </ SidenavContainer > }
81- < MainContainer >
82- < MainContentContainer >
83- { findChildType ( children , Main ) }
84- < FooterContainer >
85- { footer ?? (
86- < DxcFooter
87- copyright = { `© DXC Technology ${ year } . All rights reserved.` }
88- bottomLinks = { bottomLinks }
89- socialLinks = { socialLinks }
90- />
91- ) }
92- </ FooterContainer >
93- </ MainContentContainer >
94- </ MainContainer >
82+ { sidenav && < SidenavContainer headerHeight = { headerHeight } > { sidenav } </ SidenavContainer > }
83+ < MainContainer > { findChildType ( children , Main ) } </ MainContainer >
9584 </ BodyContainer >
85+ < FooterContainer >
86+ { footer ?? (
87+ < DxcFooter
88+ copyright = { `© DXC Technology ${ year } . All rights reserved.` }
89+ bottomLinks = { bottomLinks }
90+ socialLinks = { socialLinks }
91+ />
92+ ) }
93+ </ FooterContainer >
9694 </ ApplicationLayoutContext . Provider >
9795 </ ApplicationLayoutContainer >
9896 ) ;
0 commit comments