mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 12:56:05 +00:00
removed admin config from server, theme is now client side, fixed module manager migrations
This commit is contained in:
@@ -1,29 +1,49 @@
|
||||
import type { AppTheme } from "modules/server/AppServer";
|
||||
import { useBkndWindowContext } from "ui/client/ClientProvider";
|
||||
import { useBknd } from "ui/client/bknd";
|
||||
import { create } from "zustand";
|
||||
import { combine, persist } from "zustand/middleware";
|
||||
|
||||
const themes = ["dark", "light", "system"] as const;
|
||||
export type AppTheme = (typeof themes)[number];
|
||||
|
||||
const themeStore = create(
|
||||
persist(
|
||||
combine({ theme: null as AppTheme | null }, (set) => ({
|
||||
setTheme: (theme: AppTheme | any) => {
|
||||
if (themes.includes(theme)) {
|
||||
document.startViewTransition(() => {
|
||||
set({ theme });
|
||||
});
|
||||
}
|
||||
},
|
||||
})),
|
||||
{
|
||||
name: "bknd-admin-theme",
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
export function useTheme(fallback: AppTheme = "system") {
|
||||
const b = useBknd();
|
||||
const winCtx = useBkndWindowContext();
|
||||
const theme_state = themeStore((state) => state.theme);
|
||||
const theme_set = themeStore((state) => state.setTheme);
|
||||
|
||||
// 1. override
|
||||
// 2. config
|
||||
// 3. winCtx
|
||||
// 4. fallback
|
||||
// 5. default
|
||||
const override = b?.adminOverride?.color_scheme;
|
||||
const config = b?.config.server.admin.color_scheme;
|
||||
const win = winCtx.color_scheme;
|
||||
// 2. local storage
|
||||
// 3. fallback
|
||||
// 4. default
|
||||
const override = b?.options?.theme;
|
||||
const prefersDark =
|
||||
typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
|
||||
const theme = override ?? config ?? win ?? fallback;
|
||||
const theme = override ?? theme_state ?? fallback;
|
||||
|
||||
return {
|
||||
theme: (theme === "system" ? (prefersDark ? "dark" : "light") : theme) as AppTheme,
|
||||
value: theme,
|
||||
themes,
|
||||
setTheme: theme_set,
|
||||
state: theme_state,
|
||||
prefersDark,
|
||||
override,
|
||||
config,
|
||||
win,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user