Skip to content

Commit

Permalink
chore: improve sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
diogomartino committed Jan 28, 2024
1 parent 7d74401 commit 96fd00f
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions frontend/src/components/sidebar/nav-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,25 @@ import { useLocation, useNavigate } from 'react-router';
import cx from 'classnames';

type TNavItemProps = {
forceActive?: boolean;
to?: string;
label: string;
onClick?: () => void;
iconComponent?: React.ComponentType<any>;
};

const NavItem = ({
forceActive,
to,
label,
onClick,
iconComponent
}: TNavItemProps) => {
const NavItem = ({ to, label, onClick, iconComponent }: TNavItemProps) => {
const navigate = useNavigate();
const { pathname } = useLocation();

const isActive = useMemo(() => {
if (forceActive) {
return true;
}

if (to) {
const rootPath = `/${pathname.split('/')[1]}`;

return to.trim().toLowerCase() === rootPath.trim().toLowerCase();
}

return false;
}, [forceActive, to, pathname]);
}, [to, pathname]);

const onItemClick = () => {
onClick?.();
Expand Down Expand Up @@ -63,7 +52,7 @@ const NavItem = ({
<p
className={cx(
'text-neutral-400',
isActive && 'text-neutral-200 font-bold'
isActive && 'text-[#f8fafc] font-bold' // hex is used here because tailwind is not as it should with text-neutral (maybe a bug)
)}
>
{label}
Expand Down

0 comments on commit 96fd00f

Please sign in to comment.