Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vinvoor: added retro theme #49

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions vinvoor/src/navbar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
CreditCardMultipleOutline,
CreditCardScanOutline,
} from "mdi-material-ui";
import { useContext } from "react";
import { useContext, useState } from "react";
import { DarkModeToggle } from "../components/DarkModeToggle";
import { UserContext } from "../providers/UserProvider";
import { NavBarLogo } from "./NavBarLogo";
Expand All @@ -30,20 +30,27 @@ const userMenuPages: PageIcon[] = [

export const NavBar = () => {
const { user } = useContext(UserContext);
const [selectedPage, setSelectedPage] = useState<string>("");

const screenSize = {
mobile: { xs: "flex", md: "none" },
desktop: { xs: "none", md: "flex" },
};

const handleSelectedPage = (page: string) => setSelectedPage(page);

return (
<AppBar position="static">
<Container maxWidth="xl">
<Toolbar disableGutters>
{/* Display either the ZeSS logo or a sandwich menu */}

<Box sx={{ flexGrow: 1 }}>
<NavBarLogo sx={{ display: screenSize.desktop }} />
<NavBarLogo
sx={{ display: screenSize.desktop }}
selectedPage={selectedPage}
handleSelectedPage={handleSelectedPage}
/>

{user && (
<NavBarSandwich
Expand All @@ -60,6 +67,8 @@ export const NavBar = () => {
<NavBarPages
pageIcons={navBarPages}
sx={{ display: screenSize.desktop }}
selectedPage={selectedPage}
handleSelectedPage={handleSelectedPage}
/>
)}

Expand All @@ -70,7 +79,11 @@ export const NavBar = () => {

<Box sx={{ flexGrow: 0 }}>
<DarkModeToggle />
<NavBarUserMenu pageIcons={userMenuPages} />
<NavBarUserMenu
pageIcons={userMenuPages}
selectedPage={selectedPage}
handleSelectedPage={handleSelectedPage}
/>
</Box>
</Toolbar>
</Container>
Expand Down
18 changes: 16 additions & 2 deletions vinvoor/src/navbar/NavBarLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { ThemeContext } from "../providers/ThemeProvider";

interface NavBarLogoProps {
sx?: SxProps<Theme>;
selectedPage?: string;
handleSelectedPage?: (page: string) => void;
}

const CLICK_AMOUNT = 10;
Expand All @@ -14,9 +16,15 @@ const CLICK_TIME_MS = 1000;
let pressedAmount = 0;
let startTimePress = 0;

export const NavBarLogo: FC<NavBarLogoProps> = ({ sx }) => {
export const NavBarLogo: FC<NavBarLogoProps> = ({
sx,
selectedPage,
handleSelectedPage,
}) => {
const { setTheme } = useContext(ThemeContext);
const handleClick = () => {
if (handleSelectedPage) handleSelectedPage("home");

if (pressedAmount < CLICK_AMOUNT) {
if (pressedAmount === 0) startTimePress = Date.now();

Expand All @@ -26,7 +34,7 @@ export const NavBarLogo: FC<NavBarLogoProps> = ({ sx }) => {
pressedAmount === CLICK_AMOUNT &&
Date.now() - startTimePress <= CLICK_TIME_MS
)
setTheme("hidden");
setTheme("kak");
}
};

Expand All @@ -40,6 +48,12 @@ export const NavBarLogo: FC<NavBarLogoProps> = ({ sx }) => {
...sx,
textTransform: "none",
color: "secondary.contrastText",
borderTop: "2px solid transparent",
borderBottom: "2px solid transparent",
...(selectedPage === "home" && {
borderBottom: theme =>
`2px solid ${theme.palette.secondary.main}`,
}),
}}
>
<HexagonSlice6 sx={{ mr: ".3rem" }} />
Expand Down
17 changes: 16 additions & 1 deletion vinvoor/src/navbar/NavBarPages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,31 @@ import { PageIcon } from "./NavBar";
interface NavBarPagesProps {
pageIcons: readonly PageIcon[];
sx?: SxProps<Theme>;
selectedPage: string;
handleSelectedPage: (page: string) => void;
}

export const NavBarPages: FC<NavBarPagesProps> = ({ pageIcons, sx }) => {
export const NavBarPages: FC<NavBarPagesProps> = ({
pageIcons,
sx,
selectedPage,
handleSelectedPage,
}) => {
return (
<Box sx={{ ...sx }}>
{pageIcons.map(({ page, icon }) => (
<UnstyledLink key={page} to={page.toLowerCase()}>
<Button
onClick={() => handleSelectedPage(page)}
sx={{
color: "secondary.contrastText",
borderTop: "2px solid transparent",
borderBottom: "2px solid transparent",
...(selectedPage === page && {
borderBottom: theme =>
`2px solid ${theme.palette.secondary.main}`,
}),
mr: 1,
}}
>
{icon}
Expand Down
44 changes: 37 additions & 7 deletions vinvoor/src/navbar/NavBarUserMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
import { Button, Divider, Menu, MenuItem, Typography } from "@mui/material";
import {
Button,
Divider,
Menu,
MenuItem,
Typography,
useMediaQuery,
} from "@mui/material";
import { useTheme } from "@mui/material/styles";
import { Cow, ExitRun, ShieldAccountOutline } from "mdi-material-ui";
import { FC, MouseEvent, useContext, useState } from "react";
import { UnstyledLink } from "../components/UnstyledLink";
import { UserContext } from "../providers/UserProvider";
import { Optional } from "../types/general";
import { Login } from "../user/Login";
import { Logout } from "../user/Logout";
import { PageIcon } from "./NavBar";

interface NavBarUserMenuProps {
pageIcons: readonly PageIcon[];
selectedPage: string;
handleSelectedPage: (page: string) => void;
}

export const NavBarUserMenu: FC<NavBarUserMenuProps> = ({ pageIcons }) => {
export const NavBarUserMenu: FC<NavBarUserMenuProps> = ({
pageIcons,
selectedPage,
handleSelectedPage,
}) => {
const { user } = useContext(UserContext);
const [anchorElUser, setAnchorElUser] =
useState<Optional<HTMLElement>>(undefined);
const theme = useTheme();
const isBrowserView = useMediaQuery(theme.breakpoints.up("sm"));
const [anchorElUser, setAnchorElUser] = useState<HTMLElement | undefined>(
undefined,
);

const handleOpenUserMenu = (event: MouseEvent<HTMLElement>) => {
setAnchorElUser(event.currentTarget);
Expand All @@ -34,6 +50,12 @@ export const NavBarUserMenu: FC<NavBarUserMenuProps> = ({ pageIcons }) => {
sx={{
textTransform: "none",
color: "secondary.contrastText",
borderTop: "2px solid transparent",
borderBottom: "2px solid transparent",
...(selectedPage === "user" && {
borderBottom: theme =>
`2px solid ${theme.palette.secondary.main}`,
}),
}}
>
<ShieldAccountOutline sx={{ mr: "3px" }} />
Expand All @@ -56,7 +78,12 @@ export const NavBarUserMenu: FC<NavBarUserMenuProps> = ({ pageIcons }) => {
>
{pageIcons.map(({ page, icon }) => (
<UnstyledLink key={page} to={page.toLowerCase()}>
<MenuItem onClick={handleCloseUserMenu}>
<MenuItem
onClick={() => {
handleCloseUserMenu();
if (isBrowserView) handleSelectedPage("user");
}}
>
{icon}
<Typography>{page}</Typography>
</MenuItem>
Expand All @@ -66,7 +93,10 @@ export const NavBarUserMenu: FC<NavBarUserMenuProps> = ({ pageIcons }) => {
{user.admin && (
<UnstyledLink to="admin">
<MenuItem
onClick={handleCloseUserMenu}
onClick={() => {
handleCloseUserMenu();
if (isBrowserView) handleSelectedPage("user");
}}
sx={{
paddingX: "0",
justifyContent: "center",
Expand Down
4 changes: 4 additions & 0 deletions vinvoor/src/providers/CustomSnackbarProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export const CustomSnackbarProvider: FC<SnackbarProviderProps> = ({
"&.notistack-MuiContent-error": {
backgroundColor: theme.palette.error.dark,
},
"&.notistack-MuiContent-info": {
backgroundColor: theme.palette.primary.main,
},
}));

return (
Expand All @@ -29,6 +32,7 @@ export const CustomSnackbarProvider: FC<SnackbarProviderProps> = ({
Components={{
success: StyledMaterialDesignContent,
error: StyledMaterialDesignContent,
info: StyledMaterialDesignContent,
}}
>
{children}
Expand Down
77 changes: 73 additions & 4 deletions vinvoor/src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { createTheme, ThemeOptions } from "@mui/material";
const baseTheme: ThemeOptions = {
palette: {
secondary: {
main: "#002379",
main: "#ffffff",
contrastText: "#ffffff",
},
},
leaderboard: {
Expand Down Expand Up @@ -67,7 +68,7 @@ export const darkTheme = createTheme({
},
});

export const hiddenTheme = createTheme({
export const kakTheme = createTheme({
Topvennie marked this conversation as resolved.
Show resolved Hide resolved
palette: {
mode: "light",
primary: {
Expand Down Expand Up @@ -163,6 +164,73 @@ export const hiddenTheme = createTheme({
},
});

export const retroTheme = createTheme({
palette: {
mode: "light",
primary: {
main: "#244855",
},
secondary: {
main: "#E64833",
},
background: {
default: "#FBE9D0",
paper: "#F3DDC7",
},
success: {
main: "#008000",
},
error: {
main: "#ab0c26",
dark: "#7a0f20",
},
info: {
main: "#024950",
},
},
leaderboard: {
first: "#FFE55C",
second: "#E0E0E0",
third: "#DAAA5E",
},
heatmap: {
color0: { fill: "#e9ded1", stroke: "#ccc1b1" },
color1: { fill: "#ccc1b1", stroke: "#a5a59b" },
color2: { fill: "#a5a59b", stroke: "#778482" },
color3: { fill: "#778482", stroke: "#50686d" },
color4: { fill: "#50686d", stroke: "#244855" },
color5: { fill: "#244855", stroke: "#193540" },
colorActive: { fill: "#50686d", stroke: "#244855" },
colorInActive: { fill: "#e9ded1", stroke: "#ccc1b1" },
},
days: {
color0: "#a3bfd0",
color1: "#7f9dad",
color2: "#5b7c8a",
color3: "#406270",
color4: "#244855",
},
components: {
MuiTableCell: {
styleOverrides: {
root: {
borderBottom: "1px solid #874F41",
},
},
},
MuiAlert: {
styleOverrides: {
outlinedError: {
borderColor: "#7a0f20",
},
outlinedSuccess: {
borderColor: "#008000",
},
},
},
},
});

export interface HeatmapRectStyle {
fill: string;
stroke: string;
Expand Down Expand Up @@ -219,10 +287,11 @@ declare module "@mui/material/styles" {
}
}

export type ThemeMode = "light" | "dark" | "hidden";
export type ThemeMode = "light" | "dark" | "kak" | "retro";

export const themeModes: Record<ThemeMode, ThemeOptions> = {
light: lightTheme,
dark: darkTheme,
hidden: hiddenTheme,
kak: kakTheme,
retro: retroTheme,
};
Loading