fix: mantine dark mode

This commit is contained in:
DIYgod
2023-09-21 22:06:00 +08:00
parent cca99139d2
commit 316814adb7
4 changed files with 22 additions and 4 deletions
+5 -2
View File
@@ -22,7 +22,7 @@ import {
import { getColorScheme } from "~/lib/get-color-scheme"
import { ColorSchemeInjector } from "./ColorSchemeInjector"
import Providers, { mantineTheme } from "./providers"
import Providers, { mantineDefaultColorScheme, mantineTheme } from "./providers"
export const metadata: Metadata = {
title: `${APP_NAME} - ${APP_SLOGAN}`,
@@ -118,7 +118,10 @@ export default function RootLayout({
<ColorSchemeScript />
</head>
<body>
<MantineProvider theme={mantineTheme}>
<MantineProvider
theme={mantineTheme}
defaultColorScheme={mantineDefaultColorScheme}
>
<Providers lang={lang}>
{modal}
{children}
+11
View File
@@ -41,6 +41,17 @@ export const mantineTheme = createTheme({
fontFamily: "var(--font-fans)",
})
let mantineDefaultColorSchemeT = "auto"
if (localStorage.getItem(DARK_MODE_STORAGE_KEY) === "light") {
mantineDefaultColorSchemeT = "light"
} else if (localStorage.getItem(DARK_MODE_STORAGE_KEY) === "dark") {
mantineDefaultColorSchemeT = "dark"
}
export const mantineDefaultColorScheme = mantineDefaultColorSchemeT as
| "auto"
| "light"
| "dark"
const createQueryClient = () => new QueryClient()
export default function Providers({
children,
+4
View File
@@ -3,6 +3,8 @@
import { useTheme } from "next-themes"
import { MouseEvent } from "react"
import { useMantineColorScheme } from "@mantine/core"
import { useIsClient } from "~/hooks/useClient"
import { cn } from "~/lib/utils"
@@ -33,11 +35,13 @@ const ThemeIndicator = () => {
const ThemeSwitcher = () => {
const { setTheme } = useTheme()
const { setColorScheme } = useMantineColorScheme()
const buildThemeTransition = (
e: MouseEvent,
theme: "light" | "dark" | "system",
) => {
setColorScheme(theme === "system" ? "auto" : theme)
return setTheme(theme)
// disable in https://github.com/Crossbell-Box/xLog/commit/06713c901e90b57de6f5f5a0252d2c9dd874335f
if (
+2 -2
View File
@@ -4,8 +4,8 @@
@layer base {
body {
@apply text-zinc-800;
@apply fill-zinc-800;
@apply !text-zinc-800;
@apply !fill-zinc-800;
font-family: var(--font-fans);
}