-
Notifications
You must be signed in to change notification settings - Fork 3
/
NavBar.js
45 lines (39 loc) · 1.36 KB
/
NavBar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import AppBar from '@mui/material/AppBar';
import Box from '@mui/material/Box';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import Button from '@mui/material/Button';
import { createContext, useContext } from 'react';
const OnNavigateContext = createContext();
function NavButton({ to, href, children }) {
const navigate = useContext(OnNavigateContext);
return <Button color="inherit" onClick={to ? (() => navigate(to)) : (() => window.location.href = href)}>{children}</Button>;
}
function NavBar({ onNavigate, children }) {
return (
<Box sx={{ flexGrow: 1, boxShadow: 112 }}>
<AppBar position="sticky">
<Toolbar>
<Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>
Chess No. 25
</Typography>
<OnNavigateContext.Provider value={onNavigate}>
{children}
</OnNavigateContext.Provider>
</Toolbar>
</AppBar>
</Box>
);
}
function ChessNavBar({ onNavigate }) {
return (
<NavBar onNavigate={onNavigate}>
<NavButton to="/">Home</NavButton>
<NavButton to="/themes">Themes</NavButton>
<NavButton to="/play">Play</NavButton>
<NavButton href="https://chess-no-25-docs.vercel.app">Docs</NavButton>
<NavButton href="https://github.com/romw314/chess-no-25">GitHub</NavButton>
</NavBar>
);
};
export default ChessNavBar;