umami/components/common/HamburgerButton.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

import { Button, Icon } from 'react-basics';
2022-03-01 03:39:37 +01:00
import { useState } from 'react';
2023-01-31 06:44:07 +01:00
import MobileMenu from './MobileMenu';
import Icons from 'components/icons';
2023-04-08 07:03:52 +02:00
import useMessages from 'hooks/useMessages';
2023-01-31 06:44:07 +01:00
import styles from './HamburgerButton.module.css';
2022-03-01 03:39:37 +01:00
export default function HamburgerButton() {
2023-04-08 07:03:52 +02:00
const { formatMessage, labels } = useMessages();
2022-03-01 03:39:37 +01:00
const [active, setActive] = useState(false);
2023-04-08 07:03:52 +02:00
const menuItems = [
{
label: formatMessage(labels.dashboard),
value: '/dashboard',
},
{ label: formatMessage(labels.realtime), value: '/realtime' },
{
label: formatMessage(labels.settings),
value: '/settings',
},
{
label: formatMessage(labels.profile),
value: '/settings/profile',
},
{ label: formatMessage(labels.logout), value: '/logout' },
];
2022-03-01 03:39:37 +01:00
function handleClick() {
setActive(state => !state);
}
function handleClose() {
setActive(false);
}
return (
<>
<Button className={styles.button} onClick={handleClick}>
2023-01-31 06:44:07 +01:00
<Icon>{active ? <Icons.Close /> : <Icons.Menu />}</Icon>
</Button>
2022-03-01 03:39:37 +01:00
{active && <MobileMenu items={menuItems} onClose={handleClose} />}
</>
);
}