Commit 160fb865 authored by tom's avatar tom

tooltip when nav bar is collapsed

parent d1d24dac
import { Tooltip as TooltipComponent } from '@chakra-ui/react'; import { Tooltip as TooltipComponent } from '@chakra-ui/react';
import type { ComponentStyleConfig } from '@chakra-ui/theme'; import type { ComponentStyleConfig } from '@chakra-ui/theme';
import type { SystemStyleFunction } from '@chakra-ui/theme-tools';
import { mode } from '@chakra-ui/theme-tools';
const variantNav: SystemStyleFunction = (props) => {
return {
bg: mode('blue.50', 'gray.800')(props),
color: 'blue.400',
padding: '15px 12px',
minWidth: '120px',
borderRadius: 'base',
fontSize: '14px',
lineHeight: '20px',
textAlign: 'center',
boxShadow: 'none',
fontWeight: '500',
};
};
const variants = {
nav: variantNav,
};
const Tooltip: ComponentStyleConfig = { const Tooltip: ComponentStyleConfig = {
variants,
baseStyle: { baseStyle: {
maxWidth: 'unset', maxWidth: 'unset',
}, },
......
import { Link, Icon, Text, HStack } from '@chakra-ui/react'; import { Link, Icon, Text, HStack, Tooltip } from '@chakra-ui/react';
import NextLink from 'next/link'; import NextLink from 'next/link';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import React from 'react'; import React from 'react';
...@@ -22,24 +22,34 @@ const NavLink = ({ text, pathname, icon, isCollapsed }: Props) => { ...@@ -22,24 +22,34 @@ const NavLink = ({ text, pathname, icon, isCollapsed }: Props) => {
return ( return (
<NextLink href={ pathname } passHref> <NextLink href={ pathname } passHref>
<Link <Tooltip
as="li" label={ text }
listStyleType="none" hasArrow={ false }
w={ isCollapsed ? '60px' : '180px' } isDisabled={ !isCollapsed }
px={ isCollapsed ? '15px' : 3 } placement="right"
py={ 2.5 } variant="nav"
color={ isActive ? colors.text.active : colors.text.default } gutter={ 0 }
bgColor={ isActive ? colors.bg.active : colors.bg.default } color={ isActive ? colors.text.active : colors.text.hover }
_hover={{ color: isActive ? colors.text.active : colors.text.hover }}
borderRadius="base"
whiteSpace="nowrap"
{ ...getDefaultTransitionProps({ transitionProperty: 'width, padding' }) }
> >
<HStack spacing={ 3 }> <Link
<Icon as={ icon } boxSize="30px"/> as="li"
{ !isCollapsed && <Text variant="inherit">{ text }</Text> } listStyleType="none"
</HStack> w={ isCollapsed ? '60px' : '180px' }
</Link> px={ isCollapsed ? '15px' : 3 }
py={ 2.5 }
color={ isActive ? colors.text.active : colors.text.default }
bgColor={ isActive ? colors.bg.active : colors.bg.default }
_hover={{ color: isActive ? colors.text.active : colors.text.hover }}
borderRadius="base"
whiteSpace="nowrap"
{ ...getDefaultTransitionProps({ transitionProperty: 'width, padding' }) }
>
<HStack spacing={ 3 }>
<Icon as={ icon } boxSize="30px"/>
{ !isCollapsed && <Text variant="inherit">{ text }</Text> }
</HStack>
</Link>
</Tooltip>
</NextLink> </NextLink>
); );
}; };
......
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