Class: Daisy::Actions::SwapComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::Actions::SwapComponent
- Includes:
- LocoMotion::Concerns::TippableComponent
- Defined in:
- app/components/daisy/actions/swap_component.rb
Overview
The Swap component allows toggling between two states, “on” and “off”, with an optional indeterminate state. It provides a flexible way to create animated toggles, switches, or any other element that needs to alternate between different visual states. The component supports both simple text/emoji swaps and complex HTML content swaps.
It also includes built-in animations that can be enabled through CSS classes like ‘swap-rotate` or `swap-flip`.
Includes the LocoMotion::Concerns::TippableComponent module to enable easy tooltip addition.
Defined Under Namespace
Classes: SwapIndeterminate, SwapOff, SwapOn
Constant Summary
Constants inherited from LocoMotion::BaseComponent
LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS
Instance Attribute Summary collapse
-
#simple_off ⇒ String
readonly
The value of the ‘off` option.
-
#simple_on ⇒ String
readonly
The value of the ‘on` option.
Attributes inherited from LocoMotion::BaseComponent
Instance Method Summary collapse
-
#before_render ⇒ Object
Sets up the component with various CSS classes and HTML attributes.
-
#initialize(on = nil, off = nil, checked = nil, **kws, &block) ⇒ SwapComponent
constructor
Creates a new instance of the SwapComponent.
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(on = nil, off = nil, checked = nil, **kws, &block) ⇒ SwapComponent
Creates a new instance of the SwapComponent.
127 128 129 130 131 132 133 |
# File 'app/components/daisy/actions/swap_component.rb', line 127 def initialize(on = nil, off = nil, checked = nil, **kws, &block) super @checked = config_option(:checked, checked || false) @simple_on = config_option(:on, on) @simple_off = config_option(:off, off) end |
Instance Attribute Details
#simple_off ⇒ String (readonly)
Returns The value of the ‘off` option. Usually text or emoji.
96 97 98 |
# File 'app/components/daisy/actions/swap_component.rb', line 96 def simple_off @simple_off end |
#simple_on ⇒ String (readonly)
Returns The value of the ‘on` option. Usually text or emoji.
93 94 95 |
# File 'app/components/daisy/actions/swap_component.rb', line 93 def simple_on @simple_on end |
Instance Method Details
#before_render ⇒ Object
Sets up the component with various CSS classes and HTML attributes.
138 139 140 141 142 143 |
# File 'app/components/daisy/actions/swap_component.rb', line 138 def before_render setup_component # Set tag, base CSS setup_checkbox # Setup the hidden checkbox part setup_on_off # Setup the on/off part CSS super # Run TippableComponent hook end |