From 8d898c2ac9974bea1421ef7f7b3865333b47b4c9 Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Wed, 29 May 2024 10:47:57 +0200 Subject: [PATCH] feat: smart sticky expand/hide button (#7201) --- .../NavigationSidebar/NavigationSidebar.tsx | 89 +++++++++---------- .../MainLayout/NavigationSidebar/ShowHide.tsx | 61 +++++++------ 2 files changed, 78 insertions(+), 72 deletions(-) diff --git a/frontend/src/component/layout/MainLayout/NavigationSidebar/NavigationSidebar.tsx b/frontend/src/component/layout/MainLayout/NavigationSidebar/NavigationSidebar.tsx index b9649a023f..2f042ddcd1 100644 --- a/frontend/src/component/layout/MainLayout/NavigationSidebar/NavigationSidebar.tsx +++ b/frontend/src/component/layout/MainLayout/NavigationSidebar/NavigationSidebar.tsx @@ -41,9 +41,6 @@ export const StretchContainer = styled(Box)(({ theme }) => ({ backgroundColor: theme.palette.background.paper, padding: theme.spacing(2), alignSelf: 'stretch', -})); - -export const ScreenHeightBox = styled(Box)(({ theme }) => ({ display: 'flex', flexDirection: 'column', gap: theme.spacing(3), @@ -64,69 +61,67 @@ export const NavigationSidebar = () => { return ( - - + { + changeExpanded('configure', expand); + }} + mode={mode} + title='Configure' + > + + + {mode === 'full' && ( { - changeExpanded('configure', expand); + changeExpanded('admin', expand); }} mode={mode} - title='Configure' + title='Admin' > - {mode === 'full' && ( - { - changeExpanded('admin', expand); - }} - mode={mode} - title='Admin' - > - - - )} + )} - {mode === 'mini' && ( - { - changeExpanded('admin', true); - setMode('full'); - }} - /> - )} - - {showRecentProject && ( - setActiveItem('/projects')} - /> - )} - - { - setMode(mode === 'full' ? 'mini' : 'full'); + changeExpanded('admin', true); + setMode('full'); }} /> - + )} + + {showRecentProject && ( + setActiveItem('/projects')} + /> + )} + + { + setMode(mode === 'full' ? 'mini' : 'full'); + }} + /> ); }; diff --git a/frontend/src/component/layout/MainLayout/NavigationSidebar/ShowHide.tsx b/frontend/src/component/layout/MainLayout/NavigationSidebar/ShowHide.tsx index 7ee109dcdf..06ae806eaf 100644 --- a/frontend/src/component/layout/MainLayout/NavigationSidebar/ShowHide.tsx +++ b/frontend/src/component/layout/MainLayout/NavigationSidebar/ShowHide.tsx @@ -5,15 +5,24 @@ import HideIcon from '@mui/icons-material/KeyboardDoubleArrowLeft'; import ExpandIcon from '@mui/icons-material/KeyboardDoubleArrowRight'; import SettingsIcon from '@mui/icons-material/Settings'; -const ShowHideWrapper = styled(Box, { +const ShowHideRow = styled(Box, { shouldForwardProp: (prop) => prop !== 'mode', })<{ mode: NavigationMode }>(({ theme, mode }) => ({ display: 'flex', justifyContent: 'space-between', alignItems: 'center', padding: theme.spacing(2, 1, 0, mode === 'mini' ? 1.5 : 2), - marginTop: 'auto', cursor: 'pointer', + position: 'sticky', + bottom: theme.spacing(2), + width: '100%', +})); + +// This component is needed when the sticky item could overlap with nav items. You can replicate it on a short screen. +const ShowHideContainer = styled(Box)(({ theme }) => ({ + flexGrow: 1, + display: 'flex', + alignItems: 'end', })); export const ShowHide: FC<{ mode: NavigationMode; onChange: () => void }> = ({ @@ -21,30 +30,32 @@ export const ShowHide: FC<{ mode: NavigationMode; onChange: () => void }> = ({ onChange, }) => { return ( - - {mode === 'full' && ( - ({ - color: theme.palette.neutral.main, - fontSize: 'small', - })} - > - Hide (⌘ + B) - - )} - - {mode === 'full' ? ( - - ) : ( - - - + + + {mode === 'full' && ( + ({ + color: theme.palette.neutral.main, + fontSize: 'small', + })} + > + Hide (⌘ + B) + )} - - + + {mode === 'full' ? ( + + ) : ( + + + + )} + + + ); };