2022-03-12 01:04:05 +01:00
|
|
|
import classNames from 'classnames';
|
2023-04-12 22:40:19 +02:00
|
|
|
import { useRouter } from 'next/router';
|
2023-01-31 06:44:07 +01:00
|
|
|
import Link from 'next/link';
|
2022-03-01 03:39:37 +01:00
|
|
|
import styles from './MobileMenu.module.css';
|
|
|
|
|
2023-04-21 17:00:42 +02:00
|
|
|
export function MobileMenu({ items = [], onClose }) {
|
2023-04-12 22:40:19 +02:00
|
|
|
const { pathname } = useRouter();
|
|
|
|
|
|
|
|
const Items = ({ items, className }) => (
|
|
|
|
<div className={classNames(styles.items, className)}>
|
2023-04-13 02:43:08 +02:00
|
|
|
{items.map(({ label, url, children }) => {
|
|
|
|
const selected = pathname.startsWith(url);
|
2023-04-12 22:40:19 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Link
|
2023-04-13 02:43:08 +02:00
|
|
|
key={url}
|
|
|
|
href={url}
|
2023-04-12 22:40:19 +02:00
|
|
|
className={classNames(styles.item, { [styles.selected]: selected })}
|
|
|
|
onClick={onClose}
|
|
|
|
>
|
|
|
|
{label}
|
|
|
|
</Link>
|
|
|
|
{children && <Items items={children} className={styles.submenu} />}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2022-03-01 03:39:37 +01:00
|
|
|
return (
|
2023-01-31 06:44:07 +01:00
|
|
|
<div className={classNames(styles.menu)}>
|
2023-04-12 22:40:19 +02:00
|
|
|
<Items items={items} />
|
2022-03-01 03:39:37 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2023-04-21 17:00:42 +02:00
|
|
|
|
|
|
|
export default MobileMenu;
|