umami/src/components/layout/SideNav.tsx

47 lines
1 KiB
TypeScript
Raw Normal View History

2023-04-17 03:46:38 +00:00
import classNames from 'classnames';
2023-03-23 18:46:49 +00:00
import { Menu, Item } from 'react-basics';
2023-09-29 12:29:22 +00:00
import { usePathname } from 'next/navigation';
2023-03-23 18:46:49 +00:00
import Link from 'next/link';
import styles from './SideNav.module.css';
2023-12-03 11:07:03 +00:00
export interface SideNavProps {
selectedKey: string;
items: any[];
shallow?: boolean;
scroll?: boolean;
className?: boolean;
onSelect?: () => void;
}
2023-08-26 19:46:27 +00:00
export function SideNav({
selectedKey,
items,
shallow = true,
scroll = false,
2023-10-17 04:55:59 +00:00
className,
2023-08-26 19:46:27 +00:00
onSelect = () => {},
2023-12-03 11:07:03 +00:00
}: SideNavProps) {
2023-09-29 12:29:22 +00:00
const pathname = usePathname();
2023-03-23 18:46:49 +00:00
return (
2023-10-17 04:55:59 +00:00
<Menu
items={items}
selectedKey={selectedKey}
className={classNames(styles.menu, className)}
onSelect={onSelect}
>
2023-03-23 18:46:49 +00:00
{({ key, label, url }) => (
2023-04-17 03:46:38 +00:00
<Item
key={key}
2023-09-29 12:29:22 +00:00
className={classNames(styles.item, { [styles.selected]: pathname.startsWith(url) })}
2023-04-17 03:46:38 +00:00
>
2023-08-26 19:46:27 +00:00
<Link href={url} shallow={shallow} scroll={scroll}>
2023-03-23 18:46:49 +00:00
{label}
</Link>
</Item>
)}
</Menu>
);
}
2023-04-21 15:00:42 +00:00
export default SideNav;