feat: add theme selector to unauthenticated pages
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
99a8d64344
commit
104faf7006
6 changed files with 98 additions and 69 deletions
|
|
@ -1295,6 +1295,41 @@ defmodule MvWeb.CoreComponents do
|
|||
"""
|
||||
end
|
||||
|
||||
@doc """
|
||||
Renders a theme toggle using DaisyUI swap (sun/moon with rotate effect).
|
||||
|
||||
Wired to the theme script in root layout: checkbox uses `data-theme-toggle`,
|
||||
root script syncs checked state (checked = dark) and listens for `phx:set-theme`.
|
||||
Use in public header or sidebar. Optional `class` is applied to the wrapper.
|
||||
"""
|
||||
attr :class, :string, default: nil, doc: "Optional extra classes for the swap wrapper"
|
||||
|
||||
def theme_swap(assigns) do
|
||||
assigns = assign(assigns, :wrapper_class, assigns[:class])
|
||||
|
||||
~H"""
|
||||
<div class={[@wrapper_class]}>
|
||||
<label
|
||||
class="swap swap-rotate cursor-pointer focus-within:outline-none focus-within:focus-visible:ring-2 focus-within:focus-visible:ring-primary focus-within:focus-visible:ring-offset-2 rounded"
|
||||
aria-label={gettext("Toggle dark mode")}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
data-theme-toggle
|
||||
aria-label={gettext("Toggle dark mode")}
|
||||
onchange="window.dispatchEvent(new CustomEvent('phx:set-theme',{detail:{theme:this.checked?'dark':'light'}}))"
|
||||
/>
|
||||
<span class="swap-on size-6 flex items-center justify-center" aria-hidden="true">
|
||||
<.icon name="hero-moon" class="size-5" />
|
||||
</span>
|
||||
<span class="swap-off size-6 flex items-center justify-center" aria-hidden="true">
|
||||
<.icon name="hero-sun" class="size-5" />
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
@doc """
|
||||
Renders a [Heroicon](https://heroicons.com).
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue