-
Notifications
You must be signed in to change notification settings - Fork 0
/
SidebarItem.tsx
62 lines (56 loc) · 1.57 KB
/
SidebarItem.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React, { useState } from 'react';
interface ISidebarItemProps {
name: string;
route: string;
}
function SidebarItem({
children,
name,
route,
}: React.PropsWithChildren<ISidebarItemProps>) {
const [isActive, setIsActive] = useState(false);
const dropdownIcon = (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill={children ? 'currentColor' : 'white'}
className="h-5 w-5"
transform={isActive ? '' : 'rotate(270)'}
>
<path
fillRule="evenodd"
d="M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z"
clipRule="evenodd"
/>
</svg>
);
const dropdownIconDiv = (
<div
onClick={() => {
setIsActive((prev) => !prev);
}}
>
{dropdownIcon}
</div>
);
return (
<>
<ul className="flex border-l-2 left-1/2">
{dropdownIconDiv}
<li>
<a
href={`${route}`}
onClick={(e) => {
e.preventDefault();
setIsActive((prev) => !prev);
}}
>
{name}
</a>
{isActive ? <>{children}</> : null}
</li>
</ul>
</>
);
}
export default SidebarItem;