web_lib

Common web application libraries
git clone https://radroots.dev/git/web_lib.git
Log | Files | Refs | LICENSE

theme.ts (593B)


      1 import { get_store } from "$lib/utils/app";
      2 import type { ThemeKey, ThemeMode } from "@radroots/themes";
      3 import { type CallbackPromiseGeneric } from "@radroots/utils";
      4 import { writable } from "svelte/store";
      5 
      6 export const theme_mode = writable<ThemeMode>("light");
      7 export const theme_key = writable<ThemeKey>();
      8 export const theme_reset = writable<boolean>(false);
      9 
     10 export const theme_toggle = async (callback: CallbackPromiseGeneric<ThemeMode>): Promise<void> => {
     11     const mode = get_store(theme_mode) === `light` ? `dark` : `light`;
     12     theme_mode.set(mode);
     13     await callback(mode);
     14 };