Commit 20051052 authored by isstuev's avatar isstuev

fix2

parent 3dd7c48c
...@@ -28,11 +28,7 @@ export interface NavItem { ...@@ -28,11 +28,7 @@ export interface NavItem {
isNewUi?: boolean; isNewUi?: boolean;
} }
export interface NavGroupItem { export interface NavGroupItem extends Omit<NavItem, 'nextRoute'> {
text: string;
icon: React.FunctionComponent<React.SVGAttributes<SVGElement>>;
isActive?: boolean;
isNewUi?: boolean;
subItems: Array<NavItem>; subItems: Array<NavItem>;
} }
......
...@@ -4,9 +4,9 @@ import { route } from 'nextjs-routes'; ...@@ -4,9 +4,9 @@ import { route } from 'nextjs-routes';
import React from 'react'; import React from 'react';
import type { NavItem } from 'lib/hooks/useNavItems'; import type { NavItem } from 'lib/hooks/useNavItems';
import getDefaultTransitionProps from 'theme/utils/getDefaultTransitionProps';
import useColors from './useColors'; import useColors from './useColors';
import useNavLinkStyleProps from './useNavLinkStyleProps';
type Props = NavItem & { type Props = NavItem & {
isCollapsed?: boolean; isCollapsed?: boolean;
...@@ -15,23 +15,19 @@ type Props = NavItem & { ...@@ -15,23 +15,19 @@ type Props = NavItem & {
const NavLink = ({ text, nextRoute, icon, isCollapsed, isActive, px, isNewUi }: Props) => { const NavLink = ({ text, nextRoute, icon, isCollapsed, isActive, px, isNewUi }: Props) => {
const colors = useColors(); const colors = useColors();
const isExpanded = isCollapsed === false; const isExpanded = isCollapsed === false;
const styleProps = useNavLinkStyleProps({ isCollapsed, isExpanded, isActive });
const content = ( const content = (
<Link <Link
{ ...(isNewUi ? {} : { href: route(nextRoute) }) } { ...(isNewUi ? {} : { href: route(nextRoute) }) }
{ ...styleProps.itemProps }
w={{ base: '100%', lg: isExpanded ? '100%' : '60px', xl: isCollapsed ? '60px' : '100%' }} w={{ base: '100%', lg: isExpanded ? '100%' : '60px', xl: isCollapsed ? '60px' : '100%' }}
px={ px || { base: 3, lg: isExpanded ? 3 : '15px', xl: isCollapsed ? '15px' : 3 } }
py={ 2.5 }
display="flex" display="flex"
color={ isActive ? colors.text.active : colors.text.default } px={ px || { base: 3, lg: isExpanded ? 3 : '15px', xl: isCollapsed ? '15px' : 3 } }
bgColor={ isActive ? colors.bg.active : colors.bg.default }
_hover={{ color: isActive ? colors.text.active : colors.text.hover }}
borderRadius="base"
whiteSpace="nowrap"
aria-label={ `${ text } link` } aria-label={ `${ text } link` }
{ ...getDefaultTransitionProps({ transitionProperty: 'width, padding' }) } whiteSpace="nowrap"
> >
<Tooltip <Tooltip
label={ text } label={ text }
...@@ -44,15 +40,7 @@ const NavLink = ({ text, nextRoute, icon, isCollapsed, isActive, px, isNewUi }: ...@@ -44,15 +40,7 @@ const NavLink = ({ text, nextRoute, icon, isCollapsed, isActive, px, isNewUi }:
> >
<HStack spacing={ 3 } overflow="hidden"> <HStack spacing={ 3 } overflow="hidden">
<Icon as={ icon } boxSize="30px"/> <Icon as={ icon } boxSize="30px"/>
<Text <Text { ...styleProps.textProps }>
variant="inherit"
fontSize="sm"
lineHeight="20px"
opacity={{ base: '1', lg: isExpanded ? '1' : '0', xl: isCollapsed ? '0' : '1' }}
transitionProperty="opacity"
transitionDuration="normal"
transitionTimingFunction="ease"
>
{ text } { text }
</Text> </Text>
</HStack> </HStack>
......
...@@ -4,6 +4,7 @@ import { ...@@ -4,6 +4,7 @@ import {
HStack, HStack,
Flex, Flex,
Box, Box,
Link,
Popover, Popover,
PopoverTrigger, PopoverTrigger,
PopoverContent, PopoverContent,
...@@ -14,20 +15,19 @@ import React from 'react'; ...@@ -14,20 +15,19 @@ import React from 'react';
import chevronIcon from 'icons/arrows/east-mini.svg'; import chevronIcon from 'icons/arrows/east-mini.svg';
import type { NavGroupItem } from 'lib/hooks/useNavItems'; import type { NavGroupItem } from 'lib/hooks/useNavItems';
import getDefaultTransitionProps from 'theme/utils/getDefaultTransitionProps';
import NavLink from './NavLink'; import NavLink from './NavLink';
import useColors from './useColors'; import useNavLinkStyleProps from './useNavLinkStyleProps';
type Props = NavGroupItem & { type Props = NavGroupItem & {
isCollapsed?: boolean; isCollapsed?: boolean;
} }
const NavLinkGroupDesktop = ({ text, subItems, icon, isCollapsed, isActive }: Props) => { const NavLinkGroupDesktop = ({ text, subItems, icon, isCollapsed, isActive }: Props) => {
const colors = useColors();
const isExpanded = isCollapsed === false; const isExpanded = isCollapsed === false;
const styleProps = useNavLinkStyleProps({ isCollapsed, isExpanded, isActive });
return ( return (
<Box as="li" listStyleType="none" w="100%"> <Box as="li" listStyleType="none" w="100%">
<Popover <Popover
...@@ -36,31 +36,21 @@ const NavLinkGroupDesktop = ({ text, subItems, icon, isCollapsed, isActive }: Pr ...@@ -36,31 +36,21 @@ const NavLinkGroupDesktop = ({ text, subItems, icon, isCollapsed, isActive }: Pr
isLazy isLazy
> >
<PopoverTrigger> <PopoverTrigger>
<Box <Link
{ ...styleProps.itemProps }
w={{ lg: isExpanded ? '180px' : '60px', xl: isCollapsed ? '60px' : '180px' }} w={{ lg: isExpanded ? '180px' : '60px', xl: isCollapsed ? '60px' : '180px' }}
pl={{ lg: isExpanded ? 3 : '15px', xl: isCollapsed ? '15px' : 3 }} pl={{ lg: isExpanded ? 3 : '15px', xl: isCollapsed ? '15px' : 3 }}
pr={{ lg: isExpanded ? 0 : '15px', xl: isCollapsed ? '15px' : 0 }} pr={{ lg: isExpanded ? 0 : '15px', xl: isCollapsed ? '15px' : 0 }}
py={ 2.5 }
display="flex"
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"
aria-label={ `${ text } link group` } aria-label={ `${ text } link group` }
{ ...getDefaultTransitionProps({ transitionProperty: 'width, padding' }) } display="grid"
gridColumnGap={ 3 }
gridTemplateColumns="auto, 30px"
> >
<Flex justifyContent="space-between" width="100%" alignItems="center" pr={ 1 }> <Flex justifyContent="space-between" width="100%" alignItems="center" pr={ 1 }>
<HStack spacing={ 3 } overflow="hidden"> <HStack spacing={ 3 } overflow="hidden">
<Icon as={ icon } boxSize="30px"/> <Icon as={ icon } boxSize="30px"/>
<Text <Text
variant="inherit" { ...styleProps.textProps }
fontSize="sm"
lineHeight="20px"
opacity={{ lg: isExpanded ? '1' : '0', xl: isCollapsed ? '0' : '1' }}
transitionProperty="opacity"
transitionDuration="normal"
transitionTimingFunction="ease"
> >
{ text } { text }
</Text> </Text>
...@@ -69,10 +59,13 @@ const NavLinkGroupDesktop = ({ text, subItems, icon, isCollapsed, isActive }: Pr ...@@ -69,10 +59,13 @@ const NavLinkGroupDesktop = ({ text, subItems, icon, isCollapsed, isActive }: Pr
as={ chevronIcon } as={ chevronIcon }
transform="rotate(180deg)" transform="rotate(180deg)"
boxSize={ 6 } boxSize={ 6 }
display={{ lg: isExpanded ? 'block' : 'none', xl: isCollapsed ? 'none' : 'block' }} opacity={{ lg: isExpanded ? '1' : '0', xl: isCollapsed ? '0' : '1' }}
transitionProperty="opacity"
transitionDuration="normal"
transitionTimingFunction="ease"
/> />
</Flex> </Flex>
</Box> </Link>
</PopoverTrigger> </PopoverTrigger>
<PopoverContent width="auto" top={{ lg: isExpanded ? '-16px' : 0, xl: isCollapsed ? 0 : '-16px' }}> <PopoverContent width="auto" top={{ lg: isExpanded ? '-16px' : 0, xl: isCollapsed ? 0 : '-16px' }}>
<PopoverBody p={ 4 }> <PopoverBody p={ 4 }>
......
...@@ -9,9 +9,8 @@ import React from 'react'; ...@@ -9,9 +9,8 @@ import React from 'react';
import chevronIcon from 'icons/arrows/east-mini.svg'; import chevronIcon from 'icons/arrows/east-mini.svg';
import type { NavGroupItem } from 'lib/hooks/useNavItems'; import type { NavGroupItem } from 'lib/hooks/useNavItems';
import getDefaultTransitionProps from 'theme/utils/getDefaultTransitionProps';
import useColors from './useColors'; import useNavLinkStyleProps from './useNavLinkStyleProps';
type Props = NavGroupItem & { type Props = NavGroupItem & {
isCollapsed?: boolean; isCollapsed?: boolean;
...@@ -19,33 +18,21 @@ type Props = NavGroupItem & { ...@@ -19,33 +18,21 @@ type Props = NavGroupItem & {
} }
const NavLinkGroup = ({ text, icon, isActive, onClick }: Props) => { const NavLinkGroup = ({ text, icon, isActive, onClick }: Props) => {
const colors = useColors(); const styleProps = useNavLinkStyleProps({ isActive });
return ( return (
<Box as="li" listStyleType="none" w="100%" onClick={ onClick }> <Box as="li" listStyleType="none" w="100%" onClick={ onClick }>
<Box <Box
{ ...styleProps.itemProps }
w="100%" w="100%"
px={ 3 } px={ 3 }
py={ 2.5 }
display="flex"
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"
aria-label={ `${ text } link group` } aria-label={ `${ text } link group` }
{ ...getDefaultTransitionProps({ transitionProperty: 'width, padding' }) }
> >
<Flex justifyContent="space-between" width="100%" alignItems="center" pr={ 1 }> <Flex justifyContent="space-between" width="100%" alignItems="center" pr={ 1 }>
<HStack spacing={ 3 } overflow="hidden"> <HStack spacing={ 3 } overflow="hidden">
<Icon as={ icon } boxSize="30px"/> <Icon as={ icon } boxSize="30px"/>
<Text <Text
variant="inherit" { ...styleProps.textProps }
fontSize="sm"
lineHeight="20px"
transitionProperty="opacity"
transitionDuration="normal"
transitionTimingFunction="ease"
> >
{ text } { text }
</Text> </Text>
......
...@@ -80,7 +80,7 @@ test('with submenu +@desktop-xl +@dark-mode', async({ mount, page }) => { ...@@ -80,7 +80,7 @@ test('with submenu +@desktop-xl +@dark-mode', async({ mount, page }) => {
</TestApp>, </TestApp>,
{ hooksConfig }, { hooksConfig },
); );
await page.locator('div[aria-label="Blockchain link group"]').hover(); await page.locator('a[aria-label="Blockchain link group"]').hover();
await expect(component).toHaveScreenshot(); await expect(component).toHaveScreenshot();
}); });
......
import getDefaultTransitionProps from 'theme/utils/getDefaultTransitionProps';
import useColors from './useColors';
type Props = {
isExpanded?: boolean;
isCollapsed?: boolean;
isActive?: boolean;
px?: string | number;
}
export default function useNavLinkProps({ isExpanded, isCollapsed, isActive }: Props) {
const colors = useColors();
return {
itemProps: {
py: 2.5,
display: 'flex',
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',
...getDefaultTransitionProps({ transitionProperty: 'width, padding' }),
},
textProps: {
variant: 'inherit',
fontSize: 'sm',
lineHeight: '20px',
opacity: { base: '1', lg: isExpanded ? '1' : '0', xl: isCollapsed ? '0' : '1' },
transitionProperty: 'opacity',
transitionDuration: 'normal',
transitionTimingFunction: 'ease',
},
};
}
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