diff --git a/assets/js/app.ts b/assets/js/app.ts index 2f462efb..63a883ab 100644 --- a/assets/js/app.ts +++ b/assets/js/app.ts @@ -1375,10 +1375,30 @@ const StatusTitle = { } } +const ThemeSelector = { + mounted() { + this.updateActive() + window.addEventListener("phx:set-theme", () => this.updateActive()) + }, + updateActive() { + const current = localStorage.getItem("phx:theme") || "system" + this.el.querySelectorAll("[data-phx-theme]").forEach((btn) => { + const isActive = btn.dataset.phxTheme === current + btn.setAttribute("aria-pressed", isActive ? "true" : "false") + btn.classList.toggle("ring-2", isActive) + btn.classList.toggle("ring-indigo-500", isActive) + btn.classList.toggle("bg-indigo-50", isActive) + btn.classList.toggle("dark:bg-indigo-900/20", isActive) + btn.classList.toggle("text-indigo-700", isActive) + btn.classList.toggle("dark:text-indigo-300", isActive) + }) + }, +} + const liveSocket = new LiveSocket("/live", Socket, { longPollFallbackMs: 5000, params: { _csrf_token: csrfToken, timezone: userTimezone }, - hooks: { ...colocatedHooks, SensorChart, CopyToClipboard, ScrollToTop, AutoDismissFlash, BetaBannerDismiss, NetworkMap, SitesMap, LeafletMap, DeviceListReorder, MikrotikPortSync, GlobalSearch, GlobalSearchTrigger, DynamicFavicon, StatusTitle }, + hooks: { ...colocatedHooks, SensorChart, CopyToClipboard, ScrollToTop, AutoDismissFlash, BetaBannerDismiss, NetworkMap, SitesMap, LeafletMap, DeviceListReorder, MikrotikPortSync, GlobalSearch, GlobalSearchTrigger, DynamicFavicon, StatusTitle, ThemeSelector }, }) // Show progress bar on live navigation and form submits diff --git a/lib/towerops_web/components/layouts.ex b/lib/towerops_web/components/layouts.ex index 29f90c6e..0eeb605b 100644 --- a/lib/towerops_web/components/layouts.ex +++ b/lib/towerops_web/components/layouts.ex @@ -443,8 +443,6 @@ defmodule ToweropsWeb.Layouts do > <.icon name="hero-question-mark-circle" class="h-5 w-5" /> - - <.theme_toggle /> + + + + + + <% end %> <%= if @active_tab == "account" do %>