fix : different approach for NavBar links (#29)
This commit is contained in:
@@ -3,18 +3,32 @@ import Box from "@mui/material/Box";
|
|||||||
import Toolbar from "@mui/material/Toolbar";
|
import Toolbar from "@mui/material/Toolbar";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import IconButton from "@mui/material/IconButton";
|
import IconButton from "@mui/material/IconButton";
|
||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import NavMenu from "./NavMenu";
|
import NavMenu from "./NavMenu";
|
||||||
import { Icon } from "@iconify/react";
|
import { Icon } from "@iconify/react";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import NavLink from "@/components/NavLink";
|
import NavLink from "@/components/NavLink";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
|
import { styled } from "@mui/material/styles";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
darkMode: boolean;
|
darkMode: boolean;
|
||||||
switchDarkMode: () => void;
|
switchDarkMode: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Styled component to make the link look like a button
|
||||||
|
const StyledIconButtonLink = styled("a")({
|
||||||
|
color: "inherit",
|
||||||
|
display: "inline-flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
textDecoration: "none", // Remove underline from link
|
||||||
|
// Add any other styles to make it look like a button, e.g., padding, borderRadius
|
||||||
|
"&:hover": {
|
||||||
|
cursor: "pointer", // Change cursor on hover
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
export default function NavBar({ darkMode, switchDarkMode }: Props) {
|
export default function NavBar({ darkMode, switchDarkMode }: Props) {
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -23,17 +37,6 @@ export default function NavBar({ darkMode, switchDarkMode }: Props) {
|
|||||||
setDrawerOpen(false);
|
setDrawerOpen(false);
|
||||||
}, [router.pathname]);
|
}, [router.pathname]);
|
||||||
|
|
||||||
const handleIconClick = useCallback((url: string, event: React.MouseEvent) => {
|
|
||||||
if (event.button === 0 || event.button === 1) {
|
|
||||||
// Left click (0) or middle click (1)
|
|
||||||
window.open(url, "_blank", "noopener,noreferrer");
|
|
||||||
if (event.button === 0) {
|
|
||||||
// If left click, focus the new tab
|
|
||||||
window.focus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ flexGrow: 1, display: "flex" }}>
|
<Box sx={{ flexGrow: 1, display: "flex" }}>
|
||||||
<AppBar
|
<AppBar
|
||||||
@@ -75,23 +78,28 @@ export default function NavBar({ darkMode, switchDarkMode }: Props) {
|
|||||||
Chesskit
|
Chesskit
|
||||||
</Typography>
|
</Typography>
|
||||||
</NavLink>
|
</NavLink>
|
||||||
<IconButton
|
|
||||||
color="inherit"
|
<StyledIconButtonLink
|
||||||
onClick={(event) =>
|
href="https://discord.gg/Yr99abAcUr"
|
||||||
handleIconClick("https://discord.gg/Yr99abAcUr", event)
|
target="_blank"
|
||||||
}
|
rel="noopener noreferrer"
|
||||||
>
|
>
|
||||||
<Icon icon="ri:discord-fill" />
|
<IconButton color="inherit" component="span">
|
||||||
</IconButton>
|
<Icon icon="ri:discord-fill" />
|
||||||
<IconButton
|
</IconButton>
|
||||||
color="inherit"
|
</StyledIconButtonLink>
|
||||||
|
|
||||||
|
<StyledIconButtonLink
|
||||||
|
href="https://github.com/GuillaumeSD/Chesskit"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
sx={{ ml: "min(0.6rem, 0.8vw)" }}
|
sx={{ ml: "min(0.6rem, 0.8vw)" }}
|
||||||
onClick={(event) =>
|
|
||||||
handleIconClick("https://github.com/GuillaumeSD/Chesskit", event)
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<Icon icon="mdi:github" />
|
<IconButton color="inherit" component="span">
|
||||||
</IconButton>
|
<Icon icon="mdi:github" />
|
||||||
|
</IconButton>
|
||||||
|
</StyledIconButtonLink>
|
||||||
|
|
||||||
<IconButton
|
<IconButton
|
||||||
sx={{ ml: "min(0.6rem, 0.8vw)" }}
|
sx={{ ml: "min(0.6rem, 0.8vw)" }}
|
||||||
onClick={switchDarkMode}
|
onClick={switchDarkMode}
|
||||||
|
|||||||
Reference in New Issue
Block a user