-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
81 lines (73 loc) · 3.6 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Month calendar Vue component with Tailwind</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">
<button id="theme-toggle" type="button" class="text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 focus:outline-none focus:ring-0 rounded-none rounded-tl-lg text-sm p-2.5 transition-colors fixed bottom-0 right-0" aria-label="Switch color theme to Dark or White">
<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>
<div id="app" class="flex w-full h-full justify-center 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>