2022-03-21 11:09:01 -07:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import React from 'react';
|
|
|
|
import { NavLink } from 'react-router-dom';
|
|
|
|
|
2022-04-28 14:29:15 -07:00
|
|
|
import { Icon, Text, Counter } from './ui';
|
2022-03-21 11:09:01 -07:00
|
|
|
|
|
|
|
interface ISidebarNavigationLink {
|
|
|
|
count?: number,
|
|
|
|
icon: string,
|
|
|
|
text: string | React.ReactElement,
|
2022-04-14 11:16:08 -07:00
|
|
|
to?: string,
|
|
|
|
onClick?: React.EventHandler<React.MouseEvent>,
|
2022-03-21 11:09:01 -07:00
|
|
|
}
|
|
|
|
|
2022-04-14 11:16:08 -07:00
|
|
|
const SidebarNavigationLink = React.forwardRef((props: ISidebarNavigationLink, ref: React.ForwardedRef<HTMLAnchorElement>): JSX.Element => {
|
|
|
|
const { icon, text, to = '', count, onClick } = props;
|
2022-03-21 11:09:01 -07:00
|
|
|
const isActive = location.pathname === to;
|
|
|
|
const withCounter = typeof count !== 'undefined';
|
|
|
|
|
2022-04-14 11:16:08 -07:00
|
|
|
const handleClick: React.EventHandler<React.MouseEvent> = (e) => {
|
|
|
|
if (onClick) {
|
|
|
|
onClick(e);
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
return (
|
|
|
|
<NavLink
|
|
|
|
exact
|
|
|
|
to={to}
|
2022-04-14 11:16:08 -07:00
|
|
|
ref={ref}
|
|
|
|
onClick={handleClick}
|
2022-03-21 11:09:01 -07:00
|
|
|
className={classNames({
|
|
|
|
'flex items-center py-2 text-sm font-semibold space-x-4': true,
|
|
|
|
'text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200': !isActive,
|
|
|
|
'text-gray-900 dark:text-white': isActive,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<span className={classNames({
|
|
|
|
'relative rounded-lg inline-flex p-3': true,
|
|
|
|
'bg-primary-50 dark:bg-slate-700': !isActive,
|
|
|
|
'bg-primary-600': isActive,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
{withCounter && count > 0 ? (
|
2022-04-28 14:29:15 -07:00
|
|
|
<span className='absolute -top-2 -right-2'>
|
|
|
|
<Counter count={count} />
|
2022-03-21 11:09:01 -07:00
|
|
|
</span>
|
|
|
|
) : null}
|
|
|
|
|
2022-04-07 11:47:06 -07:00
|
|
|
<Icon
|
|
|
|
src={icon}
|
|
|
|
className={classNames({
|
2022-04-10 10:25:53 -07:00
|
|
|
'h-5 w-5': true,
|
2022-04-07 11:47:06 -07:00
|
|
|
'text-primary-700 dark:text-white': !isActive,
|
|
|
|
'text-white': isActive,
|
|
|
|
})}
|
|
|
|
/>
|
2022-03-21 11:09:01 -07:00
|
|
|
</span>
|
|
|
|
|
|
|
|
<Text weight='semibold' theme='inherit'>{text}</Text>
|
|
|
|
</NavLink>
|
|
|
|
);
|
2022-04-14 11:16:08 -07:00
|
|
|
});
|
2022-03-21 11:09:01 -07:00
|
|
|
|
|
|
|
export default SidebarNavigationLink;
|