@opensig/opendesign
Version:
23 lines (22 loc) • 533 B
JavaScript
import { isClient } from "../_utils/is.mjs";
import { ref, watch } from "vue";
const THEME_KEY = "__theme__";
const rootTheme = ref("");
watch(rootTheme, (newTheme) => {
document.documentElement.dataset.oTheme = newTheme;
localStorage.setItem(THEME_KEY, newTheme);
});
function useTheme(defaultTheme = "light") {
if (!isClient) {
return {
theme: rootTheme
};
}
rootTheme.value = rootTheme.value || localStorage.getItem(THEME_KEY) || defaultTheme;
return {
theme: rootTheme
};
}
export {
useTheme
};