Skip to content

Commit 6e3cf58

Browse files
committed
fix: dark-mode load icon from server
1 parent e573354 commit 6e3cf58

File tree

4 files changed

+7
-17
lines changed

4 files changed

+7
-17
lines changed

explorer/assets/vendor/dark_mode.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const setupThemeToggle = () => {
3636
setThemeCookie("light");
3737
}
3838
};
39+
toggleVisibility(isDark());
3940
document
4041
.getElementById("theme-toggle")
4142
.addEventListener("click", function () {
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
defmodule DarkMode do
22
use Phoenix.Component
33

4+
attr(:theme, :string, required: true)
5+
46
def button(assigns) do
57
~H"""
68
<button
@@ -13,7 +15,7 @@ defmodule DarkMode do
1315
>
1416
<svg
1517
id="theme-toggle-dark-icon"
16-
class="w-5 h-5 text-transparent hidden"
18+
class={["w-5 h-5 ", @theme == "light" && "hidden text-transparent"]}
1719
fill="currentColor"
1820
viewBox="0 0 20 20"
1921
xmlns="http://www.w3.org/2000/svg"
@@ -24,7 +26,7 @@ defmodule DarkMode do
2426
2527
<svg
2628
id="theme-toggle-light-icon"
27-
class="w-5 h-5 text-transparent"
29+
class={["w-5 h-5", @theme == "dark" && "hidden text-transparent"]}
2830
fill="currentColor"
2931
viewBox="0 0 20 20"
3032
xmlns="http://www.w3.org/2000/svg"
@@ -38,19 +40,6 @@ defmodule DarkMode do
3840
</path>
3941
</svg>
4042
</button>
41-
42-
<script>
43-
// Toggle early based on <html class="dark">
44-
const themeToggleDarkIcon = document.getElementById('theme-toggle-dark-icon');
45-
const themeToggleLightIcon = document.getElementById('theme-toggle-light-icon');
46-
if (themeToggleDarkIcon != null && themeToggleLightIcon != null) {
47-
let dark = document.documentElement.classList.contains('dark');
48-
const show = dark ? themeToggleDarkIcon : themeToggleLightIcon
49-
const hide = dark ? themeToggleLightIcon : themeToggleDarkIcon
50-
show.classList.remove('hidden', 'text-transparent');
51-
hide.classList.add('hidden', 'text-transparent');
52-
}
53-
</script>
5443
"""
5544
end
5645
end

explorer/lib/explorer_web/components/layouts/app.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<.live_component module={NavComponent} id="navbar" host={@host} />
1+
<.live_component module={NavComponent} id="navbar" host={@host} theme={@theme} />
22
<.root_background>
33
<.flash_group flash={@flash} />
44
<%= @inner_content %>

explorer/lib/explorer_web/components/nav.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ defmodule NavComponent do
103103
>
104104
GitHub
105105
</.link>
106-
<DarkMode.button />
106+
<DarkMode.button theme={@theme} />
107107
<.hover_dropdown_selector
108108
current_value={get_current_network(@host)}
109109
variant="accent"

0 commit comments

Comments
 (0)