mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 04:46:05 +00:00
updated nextjs example with app router
This commit is contained in:
@@ -2,7 +2,7 @@ import type { AppTheme } from "modules/server/AppServer";
|
||||
import { useBkndWindowContext } from "ui/client/ClientProvider";
|
||||
import { useBknd } from "ui/client/bknd";
|
||||
|
||||
export function useTheme(fallback: AppTheme = "system"): { theme: AppTheme } {
|
||||
export function useTheme(fallback: AppTheme = "system") {
|
||||
const b = useBknd();
|
||||
const winCtx = useBkndWindowContext();
|
||||
|
||||
@@ -14,13 +14,16 @@ export function useTheme(fallback: AppTheme = "system"): { theme: AppTheme } {
|
||||
const override = b?.adminOverride?.color_scheme;
|
||||
const config = b?.config.server.admin.color_scheme;
|
||||
const win = winCtx.color_scheme;
|
||||
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
const prefersDark =
|
||||
typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
|
||||
const theme = override ?? config ?? win ?? fallback;
|
||||
|
||||
if (theme === "system") {
|
||||
return { theme: prefersDark ? "dark" : "light" };
|
||||
}
|
||||
|
||||
return { theme };
|
||||
return {
|
||||
theme: (theme === "system" ? (prefersDark ? "dark" : "light") : theme) as AppTheme,
|
||||
prefersDark,
|
||||
override,
|
||||
config,
|
||||
win,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user