feat: use system color theme

This commit is contained in:
Elias Schneider
2022-10-10 22:30:04 +02:00
parent db7edc4cd6
commit d902aae03f
5 changed files with 51 additions and 108 deletions

View File

@@ -1,41 +0,0 @@
import {
ColorScheme,
ColorSchemeProvider,
MantineProvider,
} from "@mantine/core";
import { ModalsProvider } from "@mantine/modals";
import { setCookies } from "cookies-next";
import { Dispatch, ReactNode, SetStateAction } from "react";
import mantineTheme from "../../styles/mantine.style";
const ThemeProvider = ({
children,
colorScheme,
setColorScheme,
}: {
children: ReactNode;
colorScheme: ColorScheme;
setColorScheme: Dispatch<SetStateAction<ColorScheme>>;
}) => {
const toggleColorScheme = (value?: ColorScheme) => {
const nextColorScheme =
value || (colorScheme === "dark" ? "light" : "dark");
setColorScheme(nextColorScheme);
setCookies("mantine-color-scheme", nextColorScheme, {
maxAge: 60 * 60 * 24 * 30,
});
};
return (
<MantineProvider theme={{ colorScheme, ...mantineTheme }} withGlobalStyles>
<ColorSchemeProvider
colorScheme={colorScheme}
toggleColorScheme={toggleColorScheme}
>
<ModalsProvider>{children}</ModalsProvider>
</ColorSchemeProvider>
</MantineProvider>
);
};
export default ThemeProvider;

View File

@@ -1,8 +1,7 @@
import { ActionIcon, Avatar, Menu } from "@mantine/core";
import { NextLink } from "@mantine/next";
import { DoorExit, Link, Moon } from "tabler-icons-react";
import { DoorExit, Link } from "tabler-icons-react";
import authService from "../../services/auth.service";
import ToggleThemeButton from "./ToggleThemeButton";
const ActionAvatar = () => {
return (
@@ -13,13 +12,12 @@ const ActionAvatar = () => {
</ActionIcon>
</Menu.Target>
<Menu.Dropdown>
<Menu.Label>My account</Menu.Label>
<Menu.Item
component={NextLink}
href="/account/shares"
icon={<Link size={14} />}
>
Shares
My shares
</Menu.Item>
<Menu.Item
onClick={async () => {
@@ -29,10 +27,6 @@ const ActionAvatar = () => {
>
Sign out
</Menu.Item>
<Menu.Label>Settings</Menu.Label>
<Menu.Item icon={<Moon size={14} />}>
<ToggleThemeButton />
</Menu.Item>
</Menu.Dropdown>
</Menu>
);

View File

@@ -1,4 +1,5 @@
import {
Box,
Burger,
Container,
createStyles,
@@ -111,7 +112,7 @@ const NavBar = () => {
const user = useUser();
const [opened, toggleOpened] = useDisclosure(false);
const [authenticatedLinks, setAuthenticatedLinks] = useState<Link[]>([
const authenticatedLinks = [
{
link: "/upload",
label: "Upload",
@@ -119,7 +120,7 @@ const NavBar = () => {
{
component: <ActionAvatar />,
},
]);
];
const [unauthenticatedLinks, setUnauthenticatedLinks] = useState<Link[]>([
{
@@ -149,16 +150,15 @@ const NavBar = () => {
}, []);
const { classes, cx } = useStyles();
console.log(user);
const items = (
<>
{(user ? authenticatedLinks : unauthenticatedLinks).map((link) => {
if (link.component) {
return (
<>
<Container pl={5} py={15}>
<Box pl={5} py={15}>
{link.component}
</Container>
</Box>
</>
);
}
@@ -185,8 +185,8 @@ const NavBar = () => {
<Image
src="/img/logo.svg"
alt="Pinvgin Share Logo"
height={40}
width={40}
height={35}
width={35}
/>
<Text weight={600}>Pingvin Share</Text>
</Group>

View File

@@ -1,19 +0,0 @@
import { Switch, useMantineColorScheme } from "@mantine/core";
const ToggleThemeButton = () => {
const { colorScheme, toggleColorScheme } = useMantineColorScheme();
return (
<Switch
size="sm"
checked={colorScheme == "dark"}
onClick={(v) =>
toggleColorScheme(v.currentTarget.checked ? "dark" : "light")
}
onLabel="ON"
offLabel="OFF"
/>
);
};
export default ToggleThemeButton;