diff --git a/src/components/ThemeSwitcher.astro b/src/components/ThemeSwitcher.astro index 25b1796..d748a91 100644 --- a/src/components/ThemeSwitcher.astro +++ b/src/components/ThemeSwitcher.astro @@ -11,7 +11,7 @@ interface Props extends HTMLAttributes<"div"> { darkBgClass?: string[]; lightBgClass?: string[]; rootExtraClass?: string; - onChange?: (mode: "light" | "dark" | "system") => void; + onChange?: string; } const { @@ -23,7 +23,7 @@ const { lightBgClass = [], rootExtraClass = "", class: className, - onChange, + onChange = "onThemeChange", ...rest }: Props = Astro.props; @@ -140,7 +140,8 @@ const checkBase = "wr:size-4 wr:opacity-0 wr:scale-90 wr:transition"; localStorage.setItem(storageKey, mode); reflectUI(mode); - onChange?.(mode); + const fn = window[onChange]; + if (typeof fn === "function") fn(mode); } // Init