Skip to content

Commit 25c5182

Browse files
authored
Merge pull request #26 from substancelab/dark_mode
Add dark mode to the demo site
2 parents f17c49b + fe5efbc commit 25c5182

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

demo/app/assets/tailwind/application.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
/* Include CSS classes used by the components in the final CSS */
88
@import "../builds/tailwind/flowbite_components";
99

10+
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
11+
1012
footer a {
1113
@apply font-medium text-blue-600 dark:text-blue-500 hover:underline;
1214
}

demo/app/views/layouts/application.html.erb

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<%= stylesheet_link_tag :app %>
2222
</head>
2323

24-
<body>
24+
<body class="bg-white text-gray-800 dark:bg-gray-900 dark:text-gray-400">
2525
<header>
2626
<nav class="bg-white border-gray-200 dark:bg-gray-900">
2727
<div class="max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-4">
@@ -44,6 +44,18 @@
4444
<li>
4545
<%= link_to("GitHub", "https://github.com/substancelab/flowbite-components", class: "block py-2 px-3 text-gray-900 rounded-sm hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent") %>
4646
</li>
47+
<li>
48+
<button data-theme-toggle="dark" class="dark:hidden">
49+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-6">
50+
<path fill-rule="evenodd" d="M9.528 1.718a.75.75 0 0 1 .162.819A8.97 8.97 0 0 0 9 6a9 9 0 0 0 9 9 8.97 8.97 0 0 0 3.463-.69.75.75 0 0 1 .981.98 10.503 10.503 0 0 1-9.694 6.46c-5.799 0-10.5-4.7-10.5-10.5 0-4.368 2.667-8.112 6.46-9.694a.75.75 0 0 1 .818.162Z" clip-rule="evenodd" />
51+
</svg>
52+
</button>
53+
<button data-theme-toggle="light" class="hidden dark:block">
54+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
55+
<path stroke-linecap="round" stroke-linejoin="round" d="M12 18v-5.25m0 0a6.01 6.01 0 0 0 1.5-.189m-1.5.189a6.01 6.01 0 0 1-1.5-.189m3.75 7.478a12.06 12.06 0 0 1-4.5 0m3.75 2.383a14.406 14.406 0 0 1-3 0M14.25 18v-.192c0-.983.658-1.823 1.508-2.316a7.5 7.5 0 1 0-7.517 0c.85.493 1.509 1.333 1.509 2.316V18" />
56+
</svg>
57+
</button>
58+
</li>
4759
</ul>
4860
</div>
4961
</div>
@@ -56,7 +68,7 @@
5668
</article>
5769
</main>
5870

59-
<footer class="mt-28 px-5 py-5 flex border-t-2 border-gray-200 dark:border-gray-70">
71+
<footer class="mt-28 px-5 py-5 flex border-t-2 border-gray-200 dark:border-gray-700">
6072
<div class="space-y-5">
6173
<div class="flex space-x-5">
6274
<%= link_to("GitHub", "https://github.com/substancelab/flowbite-components") %>
@@ -74,5 +86,22 @@
7486
</div>
7587
</div>
7688
</footer>
89+
90+
<script>
91+
function setTheme(theme) {
92+
document.documentElement.setAttribute('data-theme', theme);
93+
localStorage.setItem("theme", theme);
94+
}
95+
setTheme(localStorage.getItem('theme') || 'light');
96+
97+
document.querySelectorAll("[data-theme-toggle]").forEach((element) => {
98+
element.addEventListener("click", () => {
99+
const theme = element.getAttribute("data-theme-toggle");
100+
if (theme) {
101+
setTheme(theme);
102+
}
103+
});
104+
});
105+
</script>
77106
</body>
78107
</html>

0 commit comments

Comments
 (0)