mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-17 04:12:45 +00:00
Chungus 2.0
This commit is contained in:
46
src/providers/ThemeDataProvider.tsx
Normal file
46
src/providers/ThemeDataProvider.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import setGlobalColorTheme from "@app/lib/themeColors";
|
||||
import { useTheme } from "next-themes";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
type ThemeColorStateProps = {
|
||||
children: React.ReactNode;
|
||||
colors: any;
|
||||
};
|
||||
|
||||
export default function ThemeDataProvider({
|
||||
children,
|
||||
colors
|
||||
}: ThemeColorStateProps) {
|
||||
const [isMounted, setIsMounted] = useState(false);
|
||||
const { theme } = useTheme();
|
||||
|
||||
useEffect(() => {
|
||||
if (!colors) {
|
||||
setIsMounted(true);
|
||||
return;
|
||||
}
|
||||
|
||||
let lightOrDark = theme;
|
||||
|
||||
if (theme === "system" || !theme) {
|
||||
lightOrDark = window.matchMedia("(prefers-color-scheme: dark)")
|
||||
.matches
|
||||
? "dark"
|
||||
: "light";
|
||||
}
|
||||
|
||||
setGlobalColorTheme(lightOrDark as "light" | "dark", colors);
|
||||
|
||||
if (!isMounted) {
|
||||
setIsMounted(true);
|
||||
}
|
||||
}, [theme]);
|
||||
|
||||
if (!isMounted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
Reference in New Issue
Block a user