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
Includes the LocoMotion::Concerns::TippableComponent module to enable easy tooltip addition.
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.
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
offoption. -
#simple_on ⇒ String
readonly
The value of the
onoption.
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
Methods included from LocoMotion::Concerns::InspectableComponent
Constructor Details
#initialize(on = nil, off = nil, checked = nil, **kws, &block) ⇒ SwapComponent
Creates a new instance of the SwapComponent.
125 126 127 128 129 130 131 |
# File 'app/components/daisy/actions/swap_component.rb', line 125 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.
97 98 99 |
# File 'app/components/daisy/actions/swap_component.rb', line 97 def simple_off @simple_off end |
#simple_on ⇒ String (readonly)
Returns The value of the on option. Usually text or emoji.
94 95 96 |
# File 'app/components/daisy/actions/swap_component.rb', line 94 def simple_on @simple_on end |
Instance Method Details
#before_render ⇒ Object
Sets up the component with various CSS classes and HTML attributes.
136 137 138 139 140 141 |
# File 'app/components/daisy/actions/swap_component.rb', line 136 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 |