first commit
This commit is contained in:
commit
b47f825d54
83 changed files with 10016 additions and 0 deletions
30
frontend/src/composables/useDarkMode.ts
Normal file
30
frontend/src/composables/useDarkMode.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import { ref, watch } from "vue";
|
||||
|
||||
const isDark = ref(false);
|
||||
|
||||
// Initialize from localStorage or system preference
|
||||
const stored = localStorage.getItem("dark_mode");
|
||||
if (stored !== null) {
|
||||
isDark.value = stored === "true";
|
||||
} else {
|
||||
isDark.value = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
}
|
||||
|
||||
// Apply class to <html>
|
||||
function applyClass() {
|
||||
document.documentElement.classList.toggle("dark", isDark.value);
|
||||
}
|
||||
applyClass();
|
||||
|
||||
watch(isDark, () => {
|
||||
applyClass();
|
||||
localStorage.setItem("dark_mode", String(isDark.value));
|
||||
});
|
||||
|
||||
export function useDarkMode() {
|
||||
function toggle() {
|
||||
isDark.value = !isDark.value;
|
||||
}
|
||||
|
||||
return { isDark, toggle };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue