Commit d6aa6995 authored by tom's avatar tom

autocollapse navigation for medium screens

parent 4599f784
...@@ -3,8 +3,8 @@ const breakpoints = { ...@@ -3,8 +3,8 @@ const breakpoints = {
// sm: '320px', // sm: '320px',
// md: '768px', // md: '768px',
lg: '1000px', lg: '1000px',
// these breakpoints are needed just to make "lg" work xl: '1440px',
xl: '2000px', // these breakpoint are needed just to make others work
'2xl': '3000px', '2xl': '3000px',
}; };
......
import { ChevronLeftIcon } from '@chakra-ui/icons'; import { ChevronLeftIcon } from '@chakra-ui/icons';
import { Flex, Box, VStack, useColorModeValue } from '@chakra-ui/react'; import { Flex, Box, VStack, useColorModeValue, useBreakpointValue } from '@chakra-ui/react';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import React from 'react'; import React from 'react';
...@@ -16,8 +16,16 @@ const NavigationDesktop = () => { ...@@ -16,8 +16,16 @@ const NavigationDesktop = () => {
const router = useRouter(); const router = useRouter();
const { mainNavItems, accountNavItems } = useNavItems(); const { mainNavItems, accountNavItems } = useNavItems();
const isLargeScreen = useBreakpointValue({ base: false, xl: true });
const cookieValue = cookies.get(cookies.NAMES.NAV_BAR_COLLAPSED);
const [ isCollapsed, setCollapsedState ] = React.useState(cookies.get(cookies.NAMES.NAV_BAR_COLLAPSED) === 'true'); const [ isCollapsed, setCollapsedState ] = React.useState(cookieValue === 'true');
React.useEffect(() => {
if (!cookieValue) {
setCollapsedState(!isLargeScreen);
}
}, [ isLargeScreen, cookieValue ]);
const handleTogglerClick = React.useCallback(() => { const handleTogglerClick = React.useCallback(() => {
setCollapsedState((flag) => !flag); setCollapsedState((flag) => !flag);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment