2023-02-06 10:01:03 -08:00
|
|
|
import clsx from 'clsx';
|
2022-03-30 08:37:30 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { NavLink, useLocation } from 'react-router-dom';
|
|
|
|
|
2022-11-15 12:46:23 -08:00
|
|
|
import IconWithCounter from 'soapbox/components/icon-with-counter';
|
2022-03-30 08:37:30 -07:00
|
|
|
import { Icon, Text } from 'soapbox/components/ui';
|
|
|
|
|
|
|
|
interface IThumbNavigationLink {
|
2023-02-15 13:26:27 -08:00
|
|
|
count?: number
|
|
|
|
countMax?: number
|
|
|
|
src: string
|
|
|
|
text: string | React.ReactElement
|
|
|
|
to: string
|
|
|
|
exact?: boolean
|
|
|
|
paths?: Array<string>
|
2022-03-30 08:37:30 -07:00
|
|
|
}
|
|
|
|
|
2022-11-03 09:13:45 -07:00
|
|
|
const ThumbNavigationLink: React.FC<IThumbNavigationLink> = ({ count, countMax, src, text, to, exact, paths }): JSX.Element => {
|
2022-03-30 09:34:05 -07:00
|
|
|
const { pathname } = useLocation();
|
2022-03-30 08:37:30 -07:00
|
|
|
|
2022-03-30 09:34:05 -07:00
|
|
|
const isActive = (): boolean => {
|
|
|
|
if (paths) {
|
2022-07-22 10:30:16 -07:00
|
|
|
return paths.some(path => pathname.startsWith(path));
|
2022-03-30 09:34:05 -07:00
|
|
|
} else {
|
|
|
|
return exact ? pathname === to : pathname.startsWith(to);
|
|
|
|
}
|
|
|
|
};
|
2022-03-30 08:37:30 -07:00
|
|
|
|
2022-03-30 09:34:05 -07:00
|
|
|
const active = isActive();
|
2022-03-30 08:37:30 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<NavLink to={to} exact={exact} className='thumb-navigation__link'>
|
|
|
|
{count !== undefined ? (
|
|
|
|
<IconWithCounter
|
2022-04-10 13:20:43 -07:00
|
|
|
src={src}
|
2023-02-06 10:01:03 -08:00
|
|
|
className={clsx({
|
2022-03-30 08:37:30 -07:00
|
|
|
'h-5 w-5': true,
|
2022-07-22 10:30:16 -07:00
|
|
|
'text-gray-600': !active,
|
|
|
|
'text-primary-500': active,
|
2022-03-30 08:37:30 -07:00
|
|
|
})}
|
|
|
|
count={count}
|
2022-11-03 09:13:45 -07:00
|
|
|
countMax={countMax}
|
2022-03-30 08:37:30 -07:00
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<Icon
|
|
|
|
src={src}
|
2023-02-06 10:01:03 -08:00
|
|
|
className={clsx({
|
2022-03-30 08:37:30 -07:00
|
|
|
'h-5 w-5': true,
|
2022-07-22 10:30:16 -07:00
|
|
|
'text-gray-600': !active,
|
|
|
|
'text-primary-500': active,
|
2022-03-30 08:37:30 -07:00
|
|
|
})}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
2022-07-22 10:30:16 -07:00
|
|
|
<Text
|
|
|
|
tag='span'
|
|
|
|
size='xs'
|
|
|
|
weight='medium'
|
2023-02-06 10:01:03 -08:00
|
|
|
className={clsx({
|
2022-07-22 10:30:16 -07:00
|
|
|
'text-gray-600': !active,
|
|
|
|
'text-primary-500': active,
|
|
|
|
})}
|
|
|
|
>
|
2022-03-30 08:37:30 -07:00
|
|
|
{text}
|
|
|
|
</Text>
|
|
|
|
</NavLink>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ThumbNavigationLink;
|