diff --git a/frontend/src/component/layout/MainLayout/NavigationSidebar/NavigationSidebar.tsx b/frontend/src/component/layout/MainLayout/NavigationSidebar/NavigationSidebar.tsx index 6dc73da4e1..9358d84fbd 100644 --- a/frontend/src/component/layout/MainLayout/NavigationSidebar/NavigationSidebar.tsx +++ b/frontend/src/component/layout/MainLayout/NavigationSidebar/NavigationSidebar.tsx @@ -43,7 +43,13 @@ import EmptyIcon from '@mui/icons-material/CheckBoxOutlineBlankOutlined'; import CorsIcon from '@mui/icons-material/StorageOutlined'; import BillingIcon from '@mui/icons-material/CreditCardOutlined'; import { ReactComponent as ProjectIcon } from 'assets/icons/projectIconSmall.svg'; -import { type FC, type ReactNode, useCallback } from 'react'; +import { + type FC, + type ReactNode, + useCallback, + useEffect, + useState, +} from 'react'; import { getCondensedRoutes, getRoutes } from '../../../menu/routes'; import { useAdminRoutes } from '../../../admin/useAdminRoutes'; import { filterByConfig, mapRouteLink } from 'component/common/util'; @@ -74,7 +80,7 @@ const EnterprisePlanBadge = () => ( ); -const StyledListItem: FC<{ href: string; text: string; badge?: ReactNode }> = ({ +const FullListItem: FC<{ href: string; text: string; badge?: ReactNode }> = ({ href, text, badge, @@ -93,6 +99,26 @@ const StyledListItem: FC<{ href: string; text: string; badge?: ReactNode }> = ({ ); }; +const MiniListItem: FC<{ href: string; text: string }> = ({ + href, + text, + children, +}) => { + return ( + + + + ({ minWidth: theme.spacing(4) })} + > + {children} + + + + + ); +}; + export const StyledBox = styled(Box)(({ theme }) => ({ backgroundColor: theme.palette.background.paper, pt: theme.spacing(3), @@ -166,62 +192,95 @@ const useRoutes = () => { return { routes: filteredMainRoutes, showBadge }; }; +const useNavigationMode = () => { + const [mode, setMode] = useState<'mini' | 'full'>('full'); + useEffect(() => { + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === 'b' && (event.metaKey || event.ctrlKey)) { + event.preventDefault(); + setMode(mode === 'mini' ? 'full' : 'mini'); + } + }; + + document.addEventListener('keydown', handleKeyDown); + + return () => { + document.removeEventListener('keydown', handleKeyDown); + }; + }, [mode]); + + return mode; +}; + export const NavigationSidebar = () => { const { routes, showBadge } = useRoutes(); + const mode = useNavigationMode(); + + const DynamicListItem = mode === 'mini' ? MiniListItem : FullListItem; + return ( - + - - + + - - + + - - + + - + - } - aria-controls='configure-content' - id='configure-header' - > - - Configure - - + {mode === 'full' && ( + } + aria-controls='configure-content' + id='configure-header' + > + + Configure + + + )} {routes.mainNavRoutes.map((route) => ( - - + ))} - } - aria-controls='admin-content' - id='admin-header' - > - - Admin - - + {mode === 'full' && ( + } + aria-controls='admin-content' + id='admin-header' + > + + Admin + + + )} + {routes.adminRoutes.map((route) => ( - { } > - + ))}