import React, { ReactNode, useEffect } from 'react'; import classNames from 'classnames'; import noop from 'lodash/noop'; import { BreakpointWidth } from 'src/global/globalConfig'; import usePrevious from 'src/shared/hooks/usePrevious'; import { ReactComponent as Chevron } from 'static/img/shared/chevron-right.svg'; import { ReactComponent as CloseIcon } from 'static/img/shared/close.svg'; import styles from './StandardAppLayout.scss'; enum SidebarModeToggleAction { OPEN = 'open', CLOSE = 'close' } export enum SidebarBehaviourType { PUSH = 'push', SLIDEOVER = 'slideover' } type SidebarModeToggleProps = { onClick: () => void; showAction: SidebarModeToggleAction; }; type StandardAppLayoutProps = { mainContent: ReactNode; sidebarContent: ReactNode; sidebarToolstripContent?: ReactNode; sidebarNavigation: ReactNode; topbarContent: ReactNode; sidebarBehaviour: SidebarBehaviourType; isSidebarOpen: boolean; onSidebarToggle: () => void; isDrawerOpen: boolean; drawerContent?: ReactNode; onDrawerClose: () => void; viewportWidth: BreakpointWidth; }; const StandardAppLayout = (props: StandardAppLayoutProps) => { // TODO: is there any way to run this smarter? // Ideally, it should run only once per app life cycle to check whether user is on small screen and close the sidebar if they are useEffect(() => { if (props.viewportWidth < BreakpointWidth.DESKTOP && props.isSidebarOpen) { props.onSidebarToggle(); } }, []); const mainClassNames = classNames( styles.main, { [styles.mainDefault]: props.isSidebarOpen && props.sidebarBehaviour === SidebarBehaviourType.PUSH }, { [styles.mainFullWidth]: !props.isSidebarOpen || props.sidebarBehaviour === SidebarBehaviourType.SLIDEOVER } ); const shouldShowSidebarNavigation = props.viewportWidth > BreakpointWidth.LAPTOP || props.isSidebarOpen; const topbarClassnames = classNames( styles.topbar, { [styles.topbar_withSidebarNavigation]: shouldShowSidebarNavigation }, { [styles.topbar_withoutSidebarNavigation]: !shouldShowSidebarNavigation } ); const sidebarWrapperClassnames = useSidebarWrapperClassNames(props); return (