Skip to content

Commit

Permalink
Add active and hover states to navigation menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgall committed Apr 30, 2024
1 parent e80e17d commit 48561aa
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/components/ui/page/Navigation/NavigationLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@ import { Box, Flex } from '@chakra-ui/react';
import { Icon } from '@phosphor-icons/react';
import { TFunction } from 'i18next';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import { Link, useMatch } from 'react-router-dom';

function LinkContent({
labelKey,
NavigationIcon,
t,
isActive,
}: {
labelKey: string;
NavigationIcon: Icon;
t: TFunction;
isActive: boolean;
}) {
return (
<Flex
py={3}
pl="11px"
borderRadius={{ md: 8 }}
_hover={{ bgColor: 'neutral-3' }}
borderWidth={isActive ? '1px' : '0px'}
borderColor="neutral-4"
bgColor={isActive ? 'neutral-3' : 'auto'}
>
<Box w={6}>{<NavigationIcon size={24} />}</Box>
<Box
Expand Down Expand Up @@ -46,12 +53,14 @@ export function NavigationLink({
closeDrawer?: () => void;
}) {
const { t } = useTranslation('navigation');
const isActive = useMatch(href.substring(0, href.indexOf('?')));

const linkContent = (
<LinkContent
labelKey={labelKey}
NavigationIcon={NavigationIcon}
t={t}
isActive={!!isActive}
/>
);

Expand All @@ -62,7 +71,6 @@ export function NavigationLink({
aria-label={t(labelKey)}
to={href}
onClick={closeDrawer}
style={{ display: 'block' }}
{...rest}
>
{linkContent}
Expand All @@ -80,7 +88,6 @@ export function NavigationLink({
{...rest}
target="_blank"
rel="noreferrer noopener"
style={{ display: 'block' }}
>
{linkContent}
</a>
Expand Down

0 comments on commit 48561aa

Please sign in to comment.