2023-03-05 15:03:20 -06:00
|
|
|
import Link from "next/link";
|
2023-05-01 05:07:01 -05:00
|
|
|
import React, { ReactElement, useEffect, useState } from "react";
|
|
|
|
import { useRouter } from "next/router";
|
2023-02-24 11:32:28 -06:00
|
|
|
|
|
|
|
interface SidebarItemProps {
|
2023-03-05 15:03:20 -06:00
|
|
|
text: string;
|
2023-03-22 22:06:15 -05:00
|
|
|
icon: ReactElement;
|
2023-03-05 15:03:20 -06:00
|
|
|
path: string;
|
2023-05-25 09:17:20 -05:00
|
|
|
className?: string;
|
2023-06-02 06:59:52 -05:00
|
|
|
iconColor?: string;
|
2023-02-24 11:32:28 -06:00
|
|
|
}
|
|
|
|
|
2023-06-02 06:59:52 -05:00
|
|
|
export default function ({
|
|
|
|
text,
|
|
|
|
icon,
|
|
|
|
path,
|
|
|
|
className,
|
|
|
|
iconColor,
|
|
|
|
}: SidebarItemProps) {
|
2023-05-01 05:07:01 -05:00
|
|
|
const router = useRouter();
|
|
|
|
const [active, setActive] = useState(false);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (router.asPath === path) setActive(true);
|
|
|
|
else setActive(false);
|
|
|
|
}, [router]);
|
|
|
|
|
2023-02-24 11:32:28 -06:00
|
|
|
return (
|
2023-03-05 15:03:20 -06:00
|
|
|
<Link href={path}>
|
2023-05-01 05:07:01 -05:00
|
|
|
<div
|
|
|
|
className={`${
|
2023-05-28 17:06:49 -05:00
|
|
|
active ? "bg-sky-500" : "hover:bg-slate-200 bg-gray-100"
|
2023-06-02 06:59:52 -05:00
|
|
|
} duration-100 py-1 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md ${className}`}
|
2023-05-01 05:07:01 -05:00
|
|
|
>
|
2023-03-22 22:06:15 -05:00
|
|
|
{React.cloneElement(icon, {
|
2023-06-02 06:59:52 -05:00
|
|
|
className: "w-4 h-4",
|
|
|
|
style: {
|
|
|
|
color: active ? "white" : iconColor ? iconColor : "#7dd3fc",
|
|
|
|
},
|
2023-03-22 22:06:15 -05:00
|
|
|
})}
|
2023-05-28 17:06:49 -05:00
|
|
|
<p
|
|
|
|
className={`${active ? "text-white" : "text-sky-900"} truncate w-4/6`}
|
|
|
|
>
|
2023-05-26 14:52:18 -05:00
|
|
|
{text}
|
|
|
|
</p>
|
2023-03-05 15:03:20 -06:00
|
|
|
</div>
|
|
|
|
</Link>
|
2023-02-24 11:32:28 -06:00
|
|
|
);
|
|
|
|
}
|