New Chnages to Switch Theme
This commit is contained in:
@@ -11,6 +11,7 @@ interface Props extends HTMLAttributes<"div"> {
|
|||||||
darkBgClass?: string[];
|
darkBgClass?: string[];
|
||||||
lightBgClass?: string[];
|
lightBgClass?: string[];
|
||||||
rootExtraClass?: string;
|
rootExtraClass?: string;
|
||||||
|
onChange?: (mode: "light" | "dark" | "system") => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -22,6 +23,7 @@ const {
|
|||||||
lightBgClass = [],
|
lightBgClass = [],
|
||||||
rootExtraClass = "",
|
rootExtraClass = "",
|
||||||
class: className,
|
class: className,
|
||||||
|
onChange,
|
||||||
...rest
|
...rest
|
||||||
}: Props = Astro.props;
|
}: Props = Astro.props;
|
||||||
|
|
||||||
@@ -91,7 +93,7 @@ const checkBase = "wr:size-4 wr:opacity-0 wr:scale-90 wr:transition";
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script is:inline define:vars={{ containerId, storageKey, rootSelector, darkBgClass, lightBgClass, rootExtraClass }}>
|
<script is:inline define:vars={{ containerId, storageKey, rootSelector, darkBgClass, lightBgClass, rootExtraClass, onChange }}>
|
||||||
(() => {
|
(() => {
|
||||||
const host = document.getElementById(containerId);
|
const host = document.getElementById(containerId);
|
||||||
if (!host) return;
|
if (!host) return;
|
||||||
@@ -137,6 +139,8 @@ const checkBase = "wr:size-4 wr:opacity-0 wr:scale-90 wr:transition";
|
|||||||
|
|
||||||
localStorage.setItem(storageKey, mode);
|
localStorage.setItem(storageKey, mode);
|
||||||
reflectUI(mode);
|
reflectUI(mode);
|
||||||
|
|
||||||
|
onChange?.(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
|
|||||||
Reference in New Issue
Block a user