Class: Daisy::Actions::ThemeControllerComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::Actions::ThemeControllerComponent
- Defined in:
- app/components/daisy/actions/theme_controller_component.rb
Overview
The ThemeComponent serves as a foundation for building a full Theme Switcher. It provides the building blocks that you will use such as the Theme Preview, Theme Radio, and Stimulus ThemeController.
Constant Summary collapse
- SOME_THEMES =
Default list of themes to display in the controller
["light", "dark", "synthwave", "retro", "cyberpunk", "wireframe"].freeze
Constants inherited from LocoMotion::BaseComponent
LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS
Instance Attribute Summary collapse
-
#themes ⇒ Object
readonly
Returns the value of attribute themes.
Attributes inherited from LocoMotion::BaseComponent
Instance Method Summary collapse
-
#before_render ⇒ Object
Sets up the component with theme Stimulus controller.
-
#build_radio_input(theme, **options) ⇒ Daisy::DataInput::RadioButtonComponent
Builder method to create a radio input for use in selecting themes.
-
#build_theme_preview(theme, **options) ⇒ Daisy::Actions::ThemePreviewComponent
Builder method to create a theme preview showing the theme’s colors in a 2x2 grid.
-
#call ⇒ Object
Renders the component and its content.
-
#initialize(**kws, &block) ⇒ ThemeControllerComponent
constructor
Creates a new instance of the ThemeControllerComponent.
Methods inherited from LocoMotion::BaseComponent
build, #component_ref, #config_option, #cssify, define_modifier, define_modifiers, define_part, define_parts, define_size, define_sizes, #empty_part_content, #inspect, #part, register_component_initializer, register_component_setup, #rendered_css, #rendered_data, #rendered_html, #rendered_stimulus_controllers, #rendered_tag_name, renders_many, renders_one, set_component_name, #set_loco_parent, #strip_spaces
Constructor Details
#initialize(**kws, &block) ⇒ ThemeControllerComponent
Creates a new instance of the ThemeControllerComponent.
26 27 28 29 30 |
# File 'app/components/daisy/actions/theme_controller_component.rb', line 26 def initialize(**kws, &block) super @themes = config_option(:themes, SOME_THEMES) end |
Instance Attribute Details
#themes ⇒ Object (readonly)
Returns the value of attribute themes.
16 17 18 |
# File 'app/components/daisy/actions/theme_controller_component.rb', line 16 def themes @themes end |
Instance Method Details
#before_render ⇒ Object
Sets up the component with theme Stimulus controller.
35 36 37 |
# File 'app/components/daisy/actions/theme_controller_component.rb', line 35 def before_render add_stimulus_controller(:component, "loco-theme") end |
#build_radio_input(theme, **options) ⇒ Daisy::DataInput::RadioButtonComponent
Builder method to create a radio input for use in selecting themes.
55 56 57 58 59 60 |
# File 'app/components/daisy/actions/theme_controller_component.rb', line 55 def build_radio_input(theme, **) [:css] = ([:css] || "").concat(" theme-controller") = { name: "theme", id: "theme-#{theme}", value: theme } render Daisy::DataInput::RadioButtonComponent.new(**.deep_merge()) end |
#build_theme_preview(theme, **options) ⇒ Daisy::Actions::ThemePreviewComponent
Builder method to create a theme preview showing the theme’s colors in a 2x2 grid.
78 79 80 81 82 83 |
# File 'app/components/daisy/actions/theme_controller_component.rb', line 78 def build_theme_preview(theme, **) render Daisy::Actions::ThemePreviewComponent.new( theme: theme, ** ) end |
#call ⇒ Object
Renders the component and its content.
42 43 44 |
# File 'app/components/daisy/actions/theme_controller_component.rb', line 42 def call part(:component) { content } end |