mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
autocollapse navigation for medium screens
This commit is contained in:
@@ -3,8 +3,8 @@ const breakpoints = {
|
||||
// sm: '320px',
|
||||
// md: '768px',
|
||||
lg: '1000px',
|
||||
// these breakpoints are needed just to make "lg" work
|
||||
xl: '2000px',
|
||||
xl: '1440px',
|
||||
// these breakpoint are needed just to make others work
|
||||
'2xl': '3000px',
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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 React from 'react';
|
||||
|
||||
@@ -16,8 +16,16 @@ const NavigationDesktop = () => {
|
||||
const router = useRouter();
|
||||
|
||||
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(() => {
|
||||
setCollapsedState((flag) => !flag);
|
||||
|
||||
Reference in New Issue
Block a user