Files
omni-tools/src/components/Navbar/index.tsx

162 lines
4.2 KiB
TypeScript
Raw Normal View History

2025-03-02 17:28:45 +00:00
import React, { ReactNode, useState } from 'react';
2024-06-19 19:10:14 +01:00
import AppBar from '@mui/material/AppBar';
import Toolbar from '@mui/material/Toolbar';
import Button from '@mui/material/Button';
import IconButton from '@mui/material/IconButton';
2024-06-26 00:29:53 +01:00
import MenuIcon from '@mui/icons-material/Menu';
2024-06-22 22:06:16 +01:00
import { Link, useNavigate } from 'react-router-dom';
2025-02-23 14:11:21 +00:00
import logo from 'assets/logo.png';
2024-06-26 00:29:53 +01:00
import {
Drawer,
List,
2025-03-02 17:28:45 +00:00
ListItem,
2024-06-26 09:02:05 +01:00
ListItemButton,
2024-06-26 00:29:53 +01:00
ListItemText,
2024-06-26 09:02:05 +01:00
Stack
2024-06-26 00:29:53 +01:00
} from '@mui/material';
import useMediaQuery from '@mui/material/useMediaQuery';
import { useTheme } from '@mui/material/styles';
2025-03-02 17:28:45 +00:00
import { Icon } from '@iconify/react';
2025-03-31 01:27:44 +00:00
import DarkModeIcon from '@mui/icons-material/DarkMode';
2024-06-19 19:10:14 +01:00
2025-03-31 01:27:44 +00:00
interface NavbarProps {
onSwitchTheme: () => void;
}
const Navbar: React.FC<NavbarProps> = ({ onSwitchTheme }) => {
2024-06-19 19:38:26 +01:00
const navigate = useNavigate();
2024-06-26 00:29:53 +01:00
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
const [drawerOpen, setDrawerOpen] = useState(false);
const toggleDrawer = (open: boolean) => () => {
setDrawerOpen(open);
};
2025-02-23 00:41:04 +01:00
const navItems: { label: string; path: string }[] = [
// { label: 'Features', path: '/features' }
// { label: 'About Us', path: '/about-us' }
];
2025-03-31 01:27:44 +00:00
2025-03-02 17:28:45 +00:00
const buttons: ReactNode[] = [
2025-03-31 01:27:44 +00:00
<DarkModeIcon onClick={onSwitchTheme} style={{ cursor: 'pointer' }} />,
2025-03-02 17:28:45 +00:00
<Icon
onClick={() => window.open('https://discord.gg/SDbbn3hT4b', '_blank')}
style={{ cursor: 'pointer' }}
fontSize={30}
icon={'ic:baseline-discord'}
/>,
<iframe
src="https://ghbtns.com/github-btn.html?user=iib0011&repo=omni-tools&type=star&count=true&size=large"
frameBorder="0"
scrolling="0"
2025-04-01 01:27:06 +00:00
width="150"
2025-03-02 17:28:45 +00:00
height="30"
title="GitHub"
></iframe>,
<Button
onClick={() => {
window.open('https://buymeacoffee.com/iib0011', '_blank');
}}
sx={{ borderRadius: '100px' }}
variant={'contained'}
startIcon={
<Icon
style={{ cursor: 'pointer' }}
fontSize={25}
icon={'mdi:heart-outline'}
/>
}
>
Buy me a coffee
</Button>
];
2024-06-26 00:29:53 +01:00
const drawerList = (
<List>
2025-02-23 00:41:04 +01:00
{navItems.map((navItem) => (
2025-03-02 17:28:45 +00:00
<ListItemButton
key={navItem.path}
onClick={() => navigate(navItem.path)}
>
2025-02-23 00:41:04 +01:00
<ListItemText primary={navItem.label} />
</ListItemButton>
))}
2025-03-02 17:28:45 +00:00
{buttons.map((button) => (
<ListItem>{button}</ListItem>
))}
2024-06-26 00:29:53 +01:00
</List>
);
2024-06-19 19:10:14 +01:00
return (
2024-06-22 22:06:16 +01:00
<AppBar
position="static"
2025-03-31 01:27:44 +00:00
sx={{
background: 'transparent',
boxShadow: 'none',
color: 'text.primary'
2025-02-25 06:17:10 +00:00
}}
2024-06-22 22:06:16 +01:00
>
2025-02-25 06:17:10 +00:00
<Toolbar
sx={{
justifyContent: 'space-between',
2025-03-02 17:28:45 +00:00
alignItems: 'center'
2025-02-25 06:17:10 +00:00
}}
>
2025-05-27 11:56:31 +02:00
<Link to="/">
2025-05-25 16:31:31 +02:00
<img
src={logo}
width={isMobile ? '80px' : '150px'}
style={{ pointerEvents: 'none' }}
/>
2025-05-27 11:56:31 +02:00
</Link>
2024-06-26 00:29:53 +01:00
{isMobile ? (
<>
2025-02-23 00:41:04 +01:00
<IconButton
color="inherit"
onClick={toggleDrawer(true)}
sx={{
'&:hover': {
backgroundColor: theme.palette.primary.main
}
}}
>
2024-06-26 00:29:53 +01:00
<MenuIcon />
</IconButton>
<Drawer
anchor="right"
open={drawerOpen}
onClose={toggleDrawer(false)}
2024-06-25 01:26:53 +01:00
>
2024-06-26 00:29:53 +01:00
{drawerList}
</Drawer>
</>
) : (
2025-03-02 17:28:45 +00:00
<Stack direction={'row'} spacing={3} alignItems={'center'}>
2025-02-23 00:41:04 +01:00
{navItems.map((item) => (
<Button
key={item.label}
color="inherit"
sx={{
'&:hover': {
color: theme.palette.primary.main,
transition: 'color 0.3s ease',
backgroundColor: 'white'
}
}}
2024-06-26 00:29:53 +01:00
>
2025-02-23 00:41:04 +01:00
<Link
to={item.path}
style={{ textDecoration: 'none', color: 'inherit' }}
>
{item.label}
</Link>
</Button>
))}
2025-03-02 17:28:45 +00:00
{buttons}
2024-06-26 00:29:53 +01:00
</Stack>
)}
2024-06-19 19:10:14 +01:00
</Toolbar>
</AppBar>
);
};
export default Navbar;