Skip to content

Commit ba3dcdf

Browse files
committed
Fixed layout problems after conflicts
1 parent 92b84fc commit ba3dcdf

4 files changed

Lines changed: 36 additions & 10 deletions

File tree

packages/lib/src/layout/ApplicationLayout.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const BodyContainer = styled.div<{ hasSidenav?: boolean }>`
3434
}
3535
`;
3636

37-
const SidenavContainer = styled.div<{ headerHeight: string }>`
37+
const SidenavContainer = styled.div<{ headerHeight: string; footerHeight: string }>`
3838
width: fit-content;
3939
height: 100%;
4040
z-index: var(--z-app-layout-sidenav);
@@ -44,6 +44,7 @@ const SidenavContainer = styled.div<{ headerHeight: string }>`
4444
max-height: ${({ headerHeight }) => `calc(100vh - ${headerHeight || "0"})`};
4545
@media (max-width: ${responsiveSizes.medium}rem) {
4646
width: 100%;
47+
max-height: ${({ headerHeight, footerHeight }) => `calc(100vh - ${headerHeight || "0"} - ${footerHeight || "0"})`};
4748
}
4849
`;
4950

@@ -63,7 +64,8 @@ const Main = ({ children }: AppLayoutMainPropsType): JSX.Element => <div>{childr
6364

6465
const DxcApplicationLayout = ({ logo, header, sidenav, footer, children }: ApplicationLayoutPropsType): JSX.Element => {
6566
const [headerHeight, setHeaderHeight] = useState("0px");
66-
67+
const [footerHeight, setFooterHeight] = useState("0px");
68+
const [hideMainContent, setHideMainContent] = useState(false);
6769
const handleHeaderHeight = useCallback(
6870
(headerElement: HTMLDivElement | null) => {
6971
if (headerElement) {
@@ -74,10 +76,21 @@ const DxcApplicationLayout = ({ logo, header, sidenav, footer, children }: Appli
7476
[header]
7577
);
7678

79+
const handleFooterHeight = useCallback(
80+
(footerElement: HTMLDivElement | null) => {
81+
if (footerElement) {
82+
const height = footerElement.offsetHeight;
83+
setFooterHeight(`${height}px`);
84+
}
85+
},
86+
[footer]
87+
);
88+
7789
const contextValue = useMemo(() => {
7890
return {
7991
logo,
8092
headerExists: !!header,
93+
setHideMainContent,
8194
};
8295
}, [header, logo]);
8396
const ref = useRef(null);
@@ -87,10 +100,14 @@ const DxcApplicationLayout = ({ logo, header, sidenav, footer, children }: Appli
87100
<ApplicationLayoutContext.Provider value={contextValue}>
88101
{header && <HeaderContainer ref={handleHeaderHeight}>{header}</HeaderContainer>}
89102
<BodyContainer hasSidenav={!!sidenav}>
90-
{sidenav && <SidenavContainer headerHeight={headerHeight}>{sidenav}</SidenavContainer>}
91-
<MainContainer>{findChildType(children, Main)}</MainContainer>
103+
{sidenav && (
104+
<SidenavContainer headerHeight={headerHeight} footerHeight={footerHeight}>
105+
{sidenav}
106+
</SidenavContainer>
107+
)}
108+
{!hideMainContent && <MainContainer>{findChildType(children, Main)}</MainContainer>}
92109
</BodyContainer>
93-
<FooterContainer>
110+
<FooterContainer ref={handleFooterHeight}>
94111
{footer ?? (
95112
<DxcFooter
96113
copyright={`© DXC Technology ${year}. All rights reserved.`}

packages/lib/src/layout/ApplicationLayoutContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ import { ApplicationLayoutContextType } from "./types";
44
export default createContext<ApplicationLayoutContextType>({
55
logo: undefined,
66
headerExists: false,
7+
setHideMainContent: () => {},
78
});

packages/lib/src/layout/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export type ApplicationLayoutContextType = {
4747
* Indicates if the header exists.
4848
*/
4949
headerExists: boolean;
50+
/**
51+
* Allows the sidenav to hide the main content when needed
52+
*/
53+
setHideMainContent: (hide: boolean) => void;
5054
};
5155

5256
type ApplicationLayoutPropsType = {

packages/lib/src/sidenav/Sidenav.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const SidenavContainer = styled.div<{
2424
width: number;
2525
showBorder?: boolean;
2626
side?: "left" | "right";
27-
hasHeader?: boolean;
2827
}>`
2928
position: relative;
3029
box-sizing: border-box;
@@ -39,8 +38,6 @@ const SidenavContainer = styled.div<{
3938
background-color: var(--color-bg-neutral-lightest);
4039
@media (max-width: ${responsiveSizes.medium}rem) {
4140
width: 100%;
42-
${({ expanded, hasHeader }) =>
43-
expanded && (hasHeader ? "height: calc(100vh - var(--height-xxxl));" : "height: 100vh;")}
4441
}
4542
`;
4643

@@ -108,7 +105,7 @@ const DxcSidenav = ({
108105
}: SidenavPropsType): JSX.Element => {
109106
const isBelowLarge = useBreakpoint("large");
110107
const isBelowMedium = useBreakpoint("medium");
111-
const { logo, headerExists } = useContext(ApplicationLayoutContext);
108+
const { logo, headerExists, setHideMainContent } = useContext(ApplicationLayoutContext);
112109
const isControlled = expanded !== undefined;
113110
const { width, sidenavRef, isResizing, startResize } = useResize({
114111
minWidth: MIN_WIDTH,
@@ -127,6 +124,14 @@ const DxcSidenav = ({
127124
const isExpanded = isControlled ? !!expanded : internalExpanded;
128125
const shouldFocusSearchBar = useRef(false);
129126

127+
useEffect(() => {
128+
if (isBelowMedium && isExpanded) {
129+
setHideMainContent(true);
130+
} else {
131+
setHideMainContent(false);
132+
}
133+
}, [isBelowMedium, isExpanded]);
134+
130135
const handleToggle = () => {
131136
const nextState = !isExpanded;
132137
if (!isControlled) setInternalExpanded(nextState);
@@ -148,7 +153,6 @@ const DxcSidenav = ({
148153
showBorder={!(isBelowMedium && !isExpanded)}
149154
ref={sidenavRef}
150155
side="left"
151-
hasHeader={headerExists}
152156
>
153157
<SidenavContent>
154158
<DxcFlex

0 commit comments

Comments
 (0)