Skip to content

Commit 3d35345

Browse files
committed
refactor: update to v4 of the squonk theme
1 parent aac170d commit 3d35345

File tree

9 files changed

+92
-124
lines changed

9 files changed

+92
-124
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@sentry/nextjs": "8.50.0",
5555
"@squonk/account-server-client": "4.0.0",
5656
"@squonk/data-manager-client": "3.2.0",
57-
"@squonk/mui-theme": "3.0.2",
57+
"@squonk/mui-theme": "4.0.0",
5858
"@squonk/sdf-parser": "1.3.0",
5959
"@tanstack/match-sorter-utils": "8.19.4",
6060
"@tanstack/react-query": "5.64.1",

pnpm-lock.yaml

Lines changed: 40 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Box, FormControl, FormControlLabel, FormLabel, Radio, RadioGroup } from "@mui/material";
2+
import { useColorScheme } from "@mui/material/styles";
3+
4+
/**
5+
* Displays a button which controls the theme of the application.
6+
*/
7+
export const ColourSchemeSelection = () => {
8+
const { mode, setMode } = useColorScheme();
9+
if (!mode) {
10+
return null;
11+
}
12+
13+
return (
14+
<Box
15+
sx={{
16+
display: "flex",
17+
width: "100%",
18+
alignItems: "center",
19+
justifyContent: "center",
20+
bgcolor: "background.default",
21+
color: "text.primary",
22+
borderRadius: 1,
23+
p: 3,
24+
minHeight: "56px",
25+
}}
26+
>
27+
<FormControl>
28+
<FormLabel id="demo-theme-toggle">Theme</FormLabel>
29+
<RadioGroup
30+
row
31+
aria-labelledby="demo-theme-toggle"
32+
name="theme-toggle"
33+
value={mode}
34+
onChange={(event) => setMode(event.target.value as "dark" | "light" | "system")}
35+
>
36+
<FormControlLabel control={<Radio />} label="System" value="system" />
37+
<FormControlLabel control={<Radio />} label="Light" value="light" />
38+
<FormControlLabel control={<Radio />} label="Dark" value="dark" />
39+
</RadioGroup>
40+
</FormControl>
41+
</Box>
42+
);
43+
};

src/components/DarkModeSwitch.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/components/app/ThemeProviders.tsx

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import { type FC, type ReactNode, useEffect, useState } from "react";
1+
import { type FC, type ReactNode } from "react";
22

3-
import { generateThemes } from "@squonk/mui-theme";
3+
import theme from "@squonk/mui-theme";
44

55
import { CssBaseline } from "@mui/material";
66
import { ThemeProvider as MuiThemeProvider } from "@mui/material/styles";
77

8-
import { useColorScheme } from "../../state/colorScheme";
9-
10-
const { darkTheme, lightTheme } = generateThemes();
11-
128
export interface ThemeProvidersProps {
139
children: ReactNode;
1410
}
@@ -17,22 +13,8 @@ export interface ThemeProvidersProps {
1713
* Provides the theme for Mui and emotion
1814
*/
1915
export const ThemeProviders: FC<ThemeProvidersProps> = ({ children }) => {
20-
// Color Scheme
21-
const [scheme] = useColorScheme();
22-
const [theme, setTheme] = useState(lightTheme);
23-
24-
// Set the theme client-side since we don't know whether the user has dark mode enabled in their
25-
// localStorage
26-
useEffect(() => {
27-
if (scheme === "dark") {
28-
setTheme(darkTheme);
29-
} else {
30-
setTheme(lightTheme);
31-
}
32-
}, [scheme]);
33-
3416
return (
35-
<MuiThemeProvider theme={theme}>
17+
<MuiThemeProvider defaultMode="light" theme={theme}>
3618
<CssBaseline />
3719
{children}
3820
</MuiThemeProvider>

src/components/logo/LogoImage.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { useColorScheme } from "@mui/material";
12
import Image from "next/image";
23

34
import logo from "../../../assets/graphics/app-logos/data-manager.svg";
45
import logoWhite from "../../../assets/graphics/app-logos/data-manager-white-tear-variant.svg";
5-
import { useColorScheme } from "../../state/colorScheme";
66

77
export interface LogoImageProps {
88
variant?: "dark" | "light";
@@ -11,13 +11,9 @@ export interface LogoImageProps {
1111
const alt = "Squonk (animal) logo with title text 'Squonk' and subtitle 'Data Manager'";
1212

1313
export const LogoImage = ({ variant }: LogoImageProps) => {
14-
const [scheme] = useColorScheme();
14+
const { mode } = useColorScheme();
1515

16-
if (variant === undefined) {
17-
variant = scheme;
18-
}
19-
20-
return variant === "dark" ? (
16+
return (variant ?? mode) === "dark" ? (
2117
<Image priority alt={alt} height="60" src={logoWhite} width="206" />
2218
) : (
2319
<Image priority alt={alt} height="60" src={logo} width="206" />

src/layouts/navigation/UserMenuContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Alert, Box, Chip, Typography, useMediaQuery, useTheme } from "@mui/mate
44
import { AuthButton } from "../../components/auth/AuthButton";
55
import { CenterLoader } from "../../components/CenterLoader";
66
import { Chips } from "../../components/Chips";
7-
import { DarkModeSwitch } from "../../components/DarkModeSwitch";
7+
import { ColourSchemeSelection } from "../../components/ColourSchemeSelection";
88
import { useASAuthorizationStatus, useDMAuthorizationStatus } from "../../hooks/useIsAuthorized";
99
import { useKeycloakUser } from "../../hooks/useKeycloakUser";
1010

@@ -21,7 +21,7 @@ export const UserMenuContent = () => {
2121
Account
2222
</Typography>
2323
<UserMenuContentInner />
24-
<DarkModeSwitch />
24+
<ColourSchemeSelection />
2525
</Box>
2626
);
2727
};

0 commit comments

Comments
 (0)