feat: add sideBar active(#36)

This commit is contained in:
Ильназ 2024-11-23 18:34:53 +03:00
parent a9738c7d8a
commit 5d1a679c68

View File

@ -1,11 +1,14 @@
import { Box, Button, Heading, VStack, Divider } from '@chakra-ui/react'; import { Box, Button, Heading, VStack, Divider } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import { Link } from 'react-router-dom'; import { useLocation, Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { URLs } from '../../__data__/urls'; import { URLs } from '../../__data__/urls';
const Sidebar = () => { const Sidebar = () => {
const location = useLocation();
const isActive = (keyword: string) => location.pathname.includes(keyword);
const { t } = useTranslation('~', { const { t } = useTranslation('~', {
keyPrefix: 'dry-wash.arm.master.sideBar', keyPrefix: 'dry-wash.arm.master.sideBar',
}); });
@ -30,8 +33,8 @@ const Sidebar = () => {
as={Link} as={Link}
to={URLs.armOrder.url} to={URLs.armOrder.url}
w='100%' w='100%'
colorScheme='green' colorScheme={isActive('orders') ? 'green' : 'blue'}
variant='ghost' variant={isActive('orders') ? 'solid' : 'ghost'}
> >
{t('orders')} {t('orders')}
</Button> </Button>
@ -42,8 +45,8 @@ const Sidebar = () => {
as={Link} as={Link}
to={URLs.armMaster.url} to={URLs.armMaster.url}
w='100%' w='100%'
colorScheme='green' colorScheme={isActive('masters') ? 'green' : 'blue'}
variant='ghost' variant={isActive('masters') ? 'solid' : 'ghost'}
> >
{t('master')} {t('master')}
</Button> </Button>