2023-01-19 00:05:39 +01:00
|
|
|
import { useState } from 'react';
|
2023-06-16 05:15:31 +02:00
|
|
|
import { Icon, Text, TooltipPopup } from 'react-basics';
|
2023-01-19 00:05:39 +01:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import { useRouter } from 'next/router';
|
|
|
|
import Link from 'next/link';
|
2023-02-04 17:59:52 +01:00
|
|
|
import Icons from 'components/icons';
|
2023-01-19 00:05:39 +01:00
|
|
|
import styles from './NavGroup.module.css';
|
|
|
|
|
2023-04-21 17:00:42 +02:00
|
|
|
export function NavGroup({
|
2023-01-19 00:05:39 +01:00
|
|
|
title,
|
|
|
|
items,
|
|
|
|
defaultExpanded = true,
|
|
|
|
allowExpand = true,
|
|
|
|
minimized = false,
|
|
|
|
}) {
|
|
|
|
const { pathname } = useRouter();
|
|
|
|
const [expanded, setExpanded] = useState(defaultExpanded);
|
|
|
|
|
|
|
|
const handleExpand = () => setExpanded(state => !state);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classNames(styles.group, {
|
|
|
|
[styles.expanded]: expanded,
|
|
|
|
[styles.minimized]: minimized,
|
|
|
|
})}
|
|
|
|
>
|
2023-01-21 02:12:53 +01:00
|
|
|
{title && (
|
|
|
|
<div className={styles.header} onClick={allowExpand ? handleExpand : undefined}>
|
|
|
|
<Text>{title}</Text>
|
|
|
|
<Icon size="sm" rotate={expanded ? 0 : -90}>
|
2023-01-28 06:53:13 +01:00
|
|
|
<Icons.ChevronDown />
|
2023-01-21 02:12:53 +01:00
|
|
|
</Icon>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-01-19 00:05:39 +01:00
|
|
|
<div className={styles.body}>
|
2023-01-21 02:12:53 +01:00
|
|
|
{items.map(({ label, url, icon, divider }) => {
|
2023-01-19 00:05:39 +01:00
|
|
|
return (
|
2023-06-16 05:15:31 +02:00
|
|
|
<TooltipPopup key={label} label={label} position="right" disabled={!minimized}>
|
2023-03-09 19:39:59 +01:00
|
|
|
<Link
|
|
|
|
href={url}
|
|
|
|
className={classNames(styles.item, {
|
|
|
|
[styles.divider]: divider,
|
|
|
|
[styles.selected]: pathname.startsWith(url),
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<Icon>{icon}</Icon>
|
|
|
|
<Text className={styles.text}>{label}</Text>
|
2023-02-04 17:59:52 +01:00
|
|
|
</Link>
|
2023-06-16 05:15:31 +02:00
|
|
|
</TooltipPopup>
|
2023-01-19 00:05:39 +01:00
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2023-04-21 17:00:42 +02:00
|
|
|
|
|
|
|
export default NavGroup;
|