2023-02-06 10:01:03 -08:00
|
|
|
import clsx from 'clsx';
|
2022-03-21 11:09:01 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { NavLink } from 'react-router-dom';
|
|
|
|
|
2022-11-03 09:48:17 -07:00
|
|
|
import { Icon, Text } from './ui';
|
2022-03-21 11:09:01 -07:00
|
|
|
|
|
|
|
interface ISidebarNavigationLink {
|
2022-05-12 09:55:13 -07:00
|
|
|
/** Notification count, if any. */
|
2022-03-21 11:09:01 -07:00
|
|
|
count?: number,
|
2022-11-03 09:13:45 -07:00
|
|
|
/** Optional max to cap count (ie: N+) */
|
|
|
|
countMax?: number
|
2022-05-12 09:55:13 -07:00
|
|
|
/** URL to an SVG icon. */
|
2022-03-21 11:09:01 -07:00
|
|
|
icon: string,
|
2022-05-12 09:55:13 -07:00
|
|
|
/** Link label. */
|
2022-11-25 12:38:09 -08:00
|
|
|
text: React.ReactNode,
|
2022-05-12 09:55:13 -07:00
|
|
|
/** Route to an internal page. */
|
2022-04-14 11:16:08 -07:00
|
|
|
to?: string,
|
2022-05-12 09:55:13 -07:00
|
|
|
/** Callback when the link is clicked. */
|
2022-04-14 11:16:08 -07:00
|
|
|
onClick?: React.EventHandler<React.MouseEvent>,
|
2022-03-21 11:09:01 -07:00
|
|
|
}
|
|
|
|
|
2022-05-12 09:55:13 -07:00
|
|
|
/** Desktop sidebar navigation link. */
|
2022-04-14 11:16:08 -07:00
|
|
|
const SidebarNavigationLink = React.forwardRef((props: ISidebarNavigationLink, ref: React.ForwardedRef<HTMLAnchorElement>): JSX.Element => {
|
2022-11-03 09:13:45 -07:00
|
|
|
const { icon, text, to = '', count, countMax, onClick } = props;
|
2022-03-21 11:09:01 -07:00
|
|
|
const isActive = location.pathname === to;
|
|
|
|
|
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}
|
2023-02-06 10:01:03 -08:00
|
|
|
className={clsx({
|
2022-11-25 09:04:11 -08:00
|
|
|
'flex items-center px-4 py-3.5 text-base font-semibold space-x-4 rtl:space-x-reverse rounded-full group text-gray-600 hover:text-gray-900 dark:text-gray-500 dark:hover:text-gray-100 hover:bg-primary-200 dark:hover:bg-primary-900': true,
|
2022-11-07 12:41:14 -08:00
|
|
|
'dark:text-gray-100 text-gray-900': isActive,
|
2022-03-21 11:09:01 -07:00
|
|
|
})}
|
|
|
|
>
|
2022-05-16 05:58:16 -07:00
|
|
|
<span className='relative'>
|
2022-04-07 11:47:06 -07:00
|
|
|
<Icon
|
|
|
|
src={icon}
|
2022-11-03 09:48:17 -07:00
|
|
|
count={count}
|
|
|
|
countMax={countMax}
|
2023-02-06 10:01:03 -08:00
|
|
|
className={clsx('h-5 w-5', {
|
2022-11-07 12:41:14 -08:00
|
|
|
'text-gray-600 dark:text-gray-500 group-hover:text-primary-500 dark:group-hover:text-primary-400': !isActive,
|
|
|
|
'text-primary-500 dark:text-primary-400': isActive,
|
2022-04-07 11:47:06 -07:00
|
|
|
})}
|
|
|
|
/>
|
2022-03-21 11:09:01 -07:00
|
|
|
</span>
|
|
|
|
|
2022-11-03 09:48:17 -07:00
|
|
|
<Text weight='semibold' theme='inherit'>{text}</Text>
|
2022-03-21 11:09:01 -07:00
|
|
|
</NavLink>
|
|
|
|
);
|
2022-04-14 11:16:08 -07:00
|
|
|
});
|
2022-03-21 11:09:01 -07:00
|
|
|
|
|
|
|
export default SidebarNavigationLink;
|