-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathsidenav.tsx
More file actions
63 lines (56 loc) · 1.7 KB
/
Copy pathsidenav.tsx
File metadata and controls
63 lines (56 loc) · 1.7 KB
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
63
import React from 'react';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { useToggle } from '@/src/layout/context';
import { ChildrenType } from '@/src/utils/globalTypes';
interface ISidenavSectionProps extends ChildrenType {
className?: string;
}
interface ISidenavItemProps extends ChildrenType {
href?: string | any;
isLink?: boolean;
}
const style = {
section: 'pl-5 text-2xl font-medium',
itemActive: 'bg-gray-100 dark:bg-[#1B2A31]',
item: `flex justify-start whitespace-pre text-sm cursor-pointer font-light pl-8 mb-5 py-2`,
sidenav: {
default: `flex flex-col h-screen fixed z-40 top-0 pb-32 right-0 lg:hidden overflow-x-hidden`,
close: `bg-gray-800 text-white hidden`,
open: `w-8/12 bg-light dark:bg-dark`,
},
};
function Sidenav({ children }: ChildrenType) {
const { open, ref } = useToggle();
return (
<aside
aria-hidden={!open}
id="sidebar"
aria-label="Sponsors"
ref={ref}
className={`${style.sidenav.default}
${open ? style.sidenav.open : style.sidenav.close}`}
>
<div className="mt-12">{children}</div>
</aside>
);
}
function SidenavSection({ children, className }: ISidenavSectionProps) {
return <div className={`${style.section} ${className}`}>{children}</div>;
}
function SidenavItem({ children, href, isLink = true }: ISidenavItemProps) {
const { asPath } = useRouter();
if (isLink) {
return (
<Link href={href}>
<a
className={`${style.item} ${asPath === href ? style.itemActive : ''}`}
>
{children}
</a>
</Link>
);
}
return <span className={style.item}>{children}</span>;
}
export { Sidenav, SidenavSection, SidenavItem };