Commit ee17ad79 authored by tom's avatar tom

nav bar collapsing

parent 621101e6
import { VStack, Text, HStack, Icon, Link, useColorModeValue } from '@chakra-ui/react'; import { VStack, Text, Stack, Icon, Link, useColorModeValue } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import ghIcon from 'icons/social/git.svg'; import ghIcon from 'icons/social/git.svg';
...@@ -14,7 +14,11 @@ const SOCIAL_LINKS = [ ...@@ -14,7 +14,11 @@ const SOCIAL_LINKS = [
{ link: '#stats', icon: statsIcon }, { link: '#stats', icon: statsIcon },
]; ];
const NavFooter = () => { interface Props {
isCollapsed: boolean;
}
const NavFooter = ({ isCollapsed }: Props) => {
return ( return (
<VStack <VStack
as="footer" as="footer"
...@@ -23,25 +27,29 @@ const NavFooter = () => { ...@@ -23,25 +27,29 @@ const NavFooter = () => {
borderColor={ useColorModeValue('blackAlpha.200', 'whiteAlpha.200') } borderColor={ useColorModeValue('blackAlpha.200', 'whiteAlpha.200') }
paddingTop={ 8 } paddingTop={ 8 }
marginTop={ 20 } marginTop={ 20 }
w="100%" // w="100%"
alignItems="baseline" alignItems="baseline"
color="gray.500" color="gray.500"
fontSize="xs" fontSize="xs"
{ ...getDefaultTransitionProps() } { ...getDefaultTransitionProps() }
> >
<HStack> <Stack direction={ isCollapsed ? 'column' : 'row' }>
{ SOCIAL_LINKS.map(sl => { { SOCIAL_LINKS.map(sl => {
return ( return (
<Link href={ sl.link } key={ sl.link } variant="secondary"> <Link href={ sl.link } key={ sl.link } variant="secondary" w={ 5 } h={ 5 }>
<Icon as={ sl.icon } boxSize={ 5 }/> <Icon as={ sl.icon } boxSize={ 5 }/>
</Link> </Link>
); );
}) } }) }
</HStack> </Stack>
<Text variant="secondary"> { !isCollapsed && (
Blockscout is a tool for inspecting and analyzing EVM based blockchains. Blockchain explorer for Ethereum Networks. <>
</Text> <Text variant="secondary">
<Text variant="secondary">Version: <Link>v4.2.1-beta</Link></Text> Blockscout is a tool for inspecting and analyzing EVM based blockchains. Blockchain explorer for Ethereum Networks.
</Text>
<Text variant="secondary">Version: <Link>v4.2.1-beta</Link></Text>
</>
) }
</VStack> </VStack>
); );
}; };
......
...@@ -6,12 +6,13 @@ import React from 'react'; ...@@ -6,12 +6,13 @@ import React from 'react';
import useColors from './useColors'; import useColors from './useColors';
interface Props { interface Props {
isCollapsed: boolean;
pathname: string; pathname: string;
text: string; text: string;
icon: React.FunctionComponent<React.SVGAttributes<SVGElement>>; icon: React.FunctionComponent<React.SVGAttributes<SVGElement>>;
} }
const NavLink = ({ text, pathname, icon }: Props) => { const NavLink = ({ text, pathname, icon, isCollapsed }: Props) => {
const router = useRouter(); const router = useRouter();
const isActive = router.pathname === pathname; const isActive = router.pathname === pathname;
...@@ -22,8 +23,8 @@ const NavLink = ({ text, pathname, icon }: Props) => { ...@@ -22,8 +23,8 @@ const NavLink = ({ text, pathname, icon }: Props) => {
<Link <Link
as="li" as="li"
listStyleType="none" listStyleType="none"
w="180px" w={ isCollapsed ? '60px' : '180px' }
px={ 3 } px={ isCollapsed ? '15px' : 3 }
py={ 2.5 } py={ 2.5 }
color={ isActive ? colors.text.active : colors.text.default } color={ isActive ? colors.text.active : colors.text.default }
bgColor={ isActive ? colors.bg.active : colors.bg.default } bgColor={ isActive ? colors.bg.active : colors.bg.default }
...@@ -32,7 +33,7 @@ const NavLink = ({ text, pathname, icon }: Props) => { ...@@ -32,7 +33,7 @@ const NavLink = ({ text, pathname, icon }: Props) => {
> >
<HStack spacing={ 3 }> <HStack spacing={ 3 }>
<Icon as={ icon } boxSize="30px"/> <Icon as={ icon } boxSize="30px"/>
<Text variant="inherit">{ text }</Text> { !isCollapsed && <Text variant="inherit">{ text }</Text> }
</HStack> </HStack>
</Link> </Link>
</NextLink> </NextLink>
......
...@@ -36,26 +36,43 @@ const accountNavItems = [ ...@@ -36,26 +36,43 @@ const accountNavItems = [
]; ];
const Navigation = () => { const Navigation = () => {
const [ isCollapsed, setCollapsedState ] = React.useState(false);
const handleTogglerClick = React.useCallback(() => {
setCollapsedState((flag) => !flag);
}, []);
const logoColor = useColorModeValue('blue.600', 'white');
return ( return (
<Flex <Flex
position="relative" position="relative"
flexDirection="column" flexDirection="column"
alignItems="flex-start" alignItems="center"
borderRight="1px solid" borderRight="1px solid"
borderColor={ useColorModeValue('blackAlpha.200', 'whiteAlpha.200') } borderColor={ useColorModeValue('blackAlpha.200', 'whiteAlpha.200') }
px={ 6 } px={ isCollapsed ? 4 : 6 }
py={ 12 } py={ 12 }
width="300px" width={ isCollapsed ? '92px' : '229px' }
{ ...getDefaultTransitionProps() } { ...getDefaultTransitionProps() }
> >
<HStack as="header" justifyContent="space-between" w="100%" px={ 3 } h={ 10 } alignItems="center"> <HStack
<Icon as="header"
as={ logoIcon } justifyContent={ isCollapsed ? 'center' : 'space-between' }
width="113px" alignItems="center"
height="20px" w="100%"
color={ useColorModeValue('blue.600', 'white') } px={ 3 }
{ ...getDefaultTransitionProps() } h={ 10 }
/> >
{ !isCollapsed && (
<Icon
as={ logoIcon }
width="113px"
height="20px"
color={ logoColor }
{ ...getDefaultTransitionProps() }
/>
) }
<Icon <Icon
as={ networksIcon } as={ networksIcon }
width="16px" width="16px"
...@@ -66,15 +83,15 @@ const Navigation = () => { ...@@ -66,15 +83,15 @@ const Navigation = () => {
</HStack> </HStack>
<Box as="nav" mt={ 14 }> <Box as="nav" mt={ 14 }>
<VStack as="ul" spacing="2"> <VStack as="ul" spacing="2">
{ mainNavItems.map((item) => <NavLink key={ item.text } { ...item }/>) } { mainNavItems.map((item) => <NavLink key={ item.text } { ...item } isCollapsed={ isCollapsed }/>) }
</VStack> </VStack>
</Box> </Box>
<Box as="nav" mt={ 12 }> <Box as="nav" mt={ 12 }>
<VStack as="ul" spacing="2"> <VStack as="ul" spacing="2">
{ accountNavItems.map((item) => <NavLink key={ item.text } { ...item }/>) } { accountNavItems.map((item) => <NavLink key={ item.text } { ...item } isCollapsed={ isCollapsed }/>) }
</VStack> </VStack>
</Box> </Box>
<NavFooter/> <NavFooter isCollapsed={ isCollapsed }/>
<ChevronLeftIcon <ChevronLeftIcon
width={ 6 } width={ 6 }
height={ 6 } height={ 6 }
...@@ -83,10 +100,13 @@ const Navigation = () => { ...@@ -83,10 +100,13 @@ const Navigation = () => {
color={ useColorModeValue('blackAlpha.400', 'whiteAlpha.400') } color={ useColorModeValue('blackAlpha.400', 'whiteAlpha.400') }
borderColor={ useColorModeValue('blackAlpha.200', 'whiteAlpha.200') } borderColor={ useColorModeValue('blackAlpha.200', 'whiteAlpha.200') }
borderRadius="base" borderRadius="base"
transform={ isCollapsed ? 'rotate(180deg)' : 'rotate(0)' }
transformOrigin="center"
position="absolute" position="absolute"
top="104px" top="104px"
right={ -3 } right={ -3 }
cursor="pointer" cursor="pointer"
onClick={ handleTogglerClick }
/> />
</Flex> </Flex>
); );
......
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