feat: color scheme toggle

This commit is contained in:
2025-08-09 17:41:37 +04:00
parent 067094c78a
commit 45dc8901fd
3 changed files with 64 additions and 22 deletions

View File

@ -0,0 +1,26 @@
.container {
@mixin dark {
background-color: var(--mantine-color-dark-7);
}
}
.icon {
width: rem(18px);
height: rem(18px);
}
.light {
display: block;
}
.dark {
display: none;
}
:global([data-mantine-color-scheme='dark']) .light {
display: none;
}
:global([data-mantine-color-scheme='dark']) .dark {
display: block;
}

View File

@ -1,28 +1,40 @@
"use client";
import { Button, Group, useMantineColorScheme } from "@mantine/core";
import { modals } from "@mantine/modals";
import { IconMoon, IconSun } from "@tabler/icons-react";
import classNames from "classnames";
import {
ActionIcon,
useComputedColorScheme,
useMantineColorScheme,
} from "@mantine/core";
import style from "./ColorSchemeToggle.module.css";
export function ColorSchemeToggle() {
const { setColorScheme } = useMantineColorScheme();
const computedColorScheme = useComputedColorScheme(undefined, {
getInitialValueInEffect: true,
});
const openTestModal = () => {
modals.openContextModal({
modal: "testModal",
title: "Тест",
withCloseButton: false,
innerProps: {},
});
const toggleColorScheme = () => {
setColorScheme(computedColorScheme === "light" ? "dark" : "light");
};
return (
<Group
justify="center"
mt="xl">
<Button onClick={() => setColorScheme("light")}>Light</Button>
<Button onClick={() => setColorScheme("dark")}>Dark</Button>
<Button onClick={() => setColorScheme("auto")}>Auto</Button>
<Button onClick={() => openTestModal()}>Modal</Button>
</Group>
<ActionIcon
onClick={toggleColorScheme}
variant="default"
size="xl"
radius="lg"
aria-label="Toggle color scheme"
className={style.container}>
<IconSun
className={classNames(style.icon, style.light)}
stroke={1.5}
/>
<IconMoon
className={classNames(style.icon, style.dark)}
stroke={1.5}
/>
</ActionIcon>
);
}