-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathuse-theme.ts
103 lines (88 loc) · 1.98 KB
/
use-theme.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import type { ComputedRef } from "vue";
import type { DaisyTheme } from "~~/lib/data/themes";
export interface UseTheme {
theme: ComputedRef<DaisyTheme>;
setTheme: (theme: DaisyTheme) => void;
}
const themeRef = ref<DaisyTheme>("garden");
export function useTheme(): UseTheme {
const preferences = useViewPreferences();
themeRef.value = preferences.value.theme;
const setTheme = (newTheme: DaisyTheme) => {
preferences.value.theme = newTheme;
if (htmlEl) {
htmlEl.value?.setAttribute("data-theme", newTheme);
// FIXME: this is a hack to remove the theme class from the html element
htmlEl.value?.classList.remove(...themes);
htmlEl.value?.classList.add("theme-" + newTheme);
}
themeRef.value = newTheme;
};
const htmlEl = ref<HTMLElement | null>();
onMounted(() => {
if (htmlEl.value) {
return;
}
htmlEl.value = document.querySelector("html");
});
const theme = computed(() => {
return themeRef.value;
});
return { theme, setTheme };
}
export function useIsDark() {
const theme = useTheme();
const darkthemes = [
"synthwave",
"retro",
"cyberpunk",
"valentine",
"halloween",
"forest",
"aqua",
"black",
"luxury",
"dracula",
"business",
"night",
"coffee",
];
return computed(() => {
return darkthemes.includes(theme.theme.value);
});
}
export const themes = [
"dark",
"theme-aqua",
"theme-black",
"theme-bumblebee",
"theme-cmyk",
"theme-corporate",
"theme-cupcake",
"theme-cyberpunk",
"theme-dark",
"theme-dracula",
"theme-emerald",
"theme-fantasy",
"theme-forest",
"theme-garden",
"theme-halloween",
"theme-light",
"theme-lofi",
"theme-luxury",
"theme-pastel",
"theme-retro",
"theme-synthwave",
"theme-valentine",
"theme-wireframe",
"theme-autumn",
"theme-business",
"theme-acid",
"theme-lemonade",
"theme-night",
"theme-coffee",
"theme-winter",
"theme-dim",
"theme-nord",
"theme-sunset",
];