Class: DaisyUI::ThemeController
- Defined in:
- lib/daisy_ui/theme_controller.rb
Overview
Theme controller changes the theme when checkbox/radio is checked Supports common patterns: swap, toggle, dropdown, radio buttons
Constant Summary
Constants inherited from Base
Base::BOOLS, Base::COLOR_MODIFIERS
Instance Method Summary collapse
-
#initialize(theme_value: nil, checked: false, as: :input) ⇒ ThemeController
constructor
A new instance of ThemeController.
- #view_template(&block) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(theme_value: nil, checked: false, as: :input) ⇒ ThemeController
Returns a new instance of ThemeController.
41 42 43 44 45 |
# File 'lib/daisy_ui/theme_controller.rb', line 41 def initialize(*, theme_value: nil, checked: false, as: :input, **) super(*, as:, **) @theme_value = theme_value @checked = checked end |
Instance Method Details
#view_template(&block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/daisy_ui/theme_controller.rb', line 47 def view_template(&block) # Input always has just the theme-controller class input_classes = apply_prefix(self.class.component_class.to_s) attrs = { type: :checkbox, class: input_classes } attrs[:value] = theme_value if theme_value attrs[:checked] = true if checked attrs.merge!() if block # If block given, wrap in label with modifier classes (swap, toggle, etc.) wrapper_classes = merge_classes(*modifier_classes, *responsive_classes) label(class: wrapper_classes) do public_send(as, **attrs) whitespace yield whitespace end else # Just render the input public_send(as, **attrs) end end |