-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
88 lines (80 loc) · 4.69 KB
/
index.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Dark Theme Switcher with Vue 3 and Tailwindcss</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="/favicon.ico">
<style>
html,
body {
width: 100%;
height: 100%;
display: block
}
</style>
</head>
<body class="bg-[#efecea] dark:bg-[#3c3c3c] relative">
<aside class="fixed bottom-3 right-3 grid grid-cols-2">
<button id="theme-toggle" type="button" class="text-gray-500 dark:text-gray-400 hover:bg-white dark:hover:bg-gray-800 focus:outline-none focus:ring-0 rounded-lg text-sm p-2.5 transition-colors">
<svg id="dark-icon" class="hidden w-5 h-5" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
<path d="M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z"></path>
</svg>
<svg id="light-icon" class="hidden w-5 h-5" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
<path d="M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z" fill-rule="evenodd" clip-rule="evenodd"></path>
</svg>
</button>
<a href="https://github.com/howbizarre/vue-tailwindcss-dark-theme-switcher" class="text-gray-500 dark:text-gray-400 hover:bg-white dark:hover:bg-gray-800 focus:outline-none focus:ring-0 rounded-lg text-sm p-2.5 transition-colors">
<svg width="20" height="20" viewBox="0 0 32 32">
<path fill="currentColor" fill-rule="evenodd" d="M16 2a14 14 0 0 0-4.43 27.28c.7.13 1-.3 1-.67v-2.38c-3.89.84-4.71-1.88-4.71-1.88a3.71 3.71 0 0 0-1.62-2.05c-1.27-.86.1-.85.1-.85a2.94 2.94 0 0 1 2.14 1.45a3 3 0 0 0 4.08 1.16a2.93 2.93 0 0 1 .88-1.87c-3.1-.36-6.37-1.56-6.37-6.92a5.4 5.4 0 0 1 1.44-3.76a5 5 0 0 1 .14-3.7s1.17-.38 3.85 1.43a13.3 13.3 0 0 1 7 0c2.67-1.81 3.84-1.43 3.84-1.43a5 5 0 0 1 .14 3.7a5.4 5.4 0 0 1 1.44 3.76c0 5.38-3.27 6.56-6.39 6.91a3.33 3.33 0 0 1 .95 2.59v3.84c0 .46.25.81 1 .67A14 14 0 0 0 16 2Z" />
</svg>
</a>
</aside>
<div id="app" class="flex w-full h-full justify-center items-start sm:items-center"></div>
<script>
const docElm = document.documentElement;
const themeToggleBtn = docElm.querySelector("#theme-toggle");
const darkIcon = themeToggleBtn.querySelector("#dark-icon");
const lightIcon = themeToggleBtn.querySelector("#light-icon");
if (localStorage.getItem("color-theme") === "dark") {
darkIcon.classList.remove("hidden");
docElm.classList.remove("light");
docElm.classList.add("dark");
} else {
if ((!('color-theme' in localStorage)) && (window.matchMedia('(prefers-color-scheme: dark)').matches)) {
darkIcon.classList.remove("hidden");
docElm.classList.remove("light");
docElm.classList.add("dark");
localStorage.setItem("color-theme", "dark");
} else {
lightIcon.classList.remove("hidden");
docElm.classList.remove("dark");
docElm.classList.add("light");
localStorage.setItem("color-theme", "light");
}
}
themeToggleBtn.addEventListener("click", function () {
darkIcon.classList.toggle("hidden");
lightIcon.classList.toggle("hidden");
if (localStorage.getItem("color-theme")) {
if (localStorage.getItem("color-theme") === "light") {
docElm.classList.add("dark");
localStorage.setItem("color-theme", "dark");
} else {
docElm.classList.remove("dark");
localStorage.setItem("color-theme", "light");
}
} else {
if (docElm.classList.contains("dark")) {
docElm.classList.remove("dark");
localStorage.setItem("color-theme", "light");
} else {
docElm.classList.add("dark");
localStorage.setItem("color-theme", "dark");
}
}
});
</script>
<script type="module" src="/src/main.ts"></script>
</body>
</html>