Class: PhlexKit::ThemeToggle

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/theme_toggle/theme_toggle.rb

Overview

Light/dark theme switch built on Toggle. Ported from ruby_ui's RubyUI

ThemeToggle. The sibling phlex-kit--theme-toggle controller listens for the toggle's change event and flips :root (matching the token system).

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(**attrs) ⇒ ThemeToggle

Returns a new instance of ThemeToggle.



6
# File 'app/components/phlex_kit/theme_toggle/theme_toggle.rb', line 6

def initialize(**attrs) = (@attrs = attrs)

Instance Method Details

#view_template(&block) ⇒ Object



7
8
9
10
11
12
13
# File 'app/components/phlex_kit/theme_toggle/theme_toggle.rb', line 7

def view_template(&block)
  render PhlexKit::Toggle.new(
    aria: { label: "Toggle theme" },
    wrapper: { data: { controller: "phlex-kit--theme-toggle", action: "phlex-kit--toggle:change->phlex-kit--theme-toggle#apply" } },
    **@attrs, &block
  )
end