umami/components/layout/NavBar.js

57 lines
1.9 KiB
JavaScript
Raw Normal View History

import { useState } from 'react';
2023-01-31 06:44:07 +01:00
import { Icon, Text } from 'react-basics';
2023-03-22 05:28:36 +01:00
import Link from 'next/link';
import classNames from 'classnames';
2023-01-31 06:44:07 +01:00
import Icons from 'components/icons';
2023-02-04 17:59:52 +01:00
import ThemeButton from 'components/input/ThemeButton';
import LanguageButton from 'components/input/LanguageButton';
2023-03-22 05:28:36 +01:00
import ProfileButton from 'components/input/ProfileButton';
import styles from './NavBar.module.css';
2023-02-28 05:03:04 +01:00
import useConfig from 'hooks/useConfig';
2023-03-22 05:28:36 +01:00
import useMessages from 'hooks/useMessages';
2023-03-23 19:46:49 +01:00
import { useRouter } from 'next/router';
export default function NavBar() {
2023-03-23 19:46:49 +01:00
const { pathname } = useRouter();
2023-02-28 05:03:04 +01:00
const { cloudMode } = useConfig();
2023-03-22 05:28:36 +01:00
const { formatMessage, labels } = useMessages();
const [minimized, setMinimized] = useState(false);
2023-03-22 05:28:36 +01:00
const links = [
2023-01-31 06:44:07 +01:00
{ label: formatMessage(labels.dashboard), url: '/dashboard', icon: <Icons.Dashboard /> },
{ label: formatMessage(labels.realtime), url: '/realtime', icon: <Icons.Clock /> },
2023-03-22 05:28:36 +01:00
!cloudMode && { label: formatMessage(labels.settings), url: '/settings', icon: <Icons.Gear /> },
2023-01-31 06:44:07 +01:00
].filter(n => n);
const handleMinimize = () => setMinimized(state => !state);
return (
<div className={classNames(styles.navbar, { [styles.minimized]: minimized })}>
2023-03-22 05:28:36 +01:00
<div className={styles.logo} onClick={handleMinimize}>
<Icon size="lg">
2023-01-31 06:44:07 +01:00
<Icons.Logo />
</Icon>
<Text className={styles.text}>umami</Text>
</div>
2023-03-22 05:28:36 +01:00
<div className={styles.links}>
{links.map(({ url, icon, label }) => {
return (
2023-03-23 19:46:49 +01:00
<Link
key={url}
href={url}
className={classNames({ [styles.selected]: pathname.startsWith(url) })}
>
2023-03-22 05:28:36 +01:00
<Text>{label}</Text>
</Link>
);
})}
</div>
<div className={styles.actions}>
<ThemeButton />
<LanguageButton />
{!cloudMode && <ProfileButton />}
</div>
</div>
);
}