Class: Daisy::Actions::ButtonComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::Actions::ButtonComponent
- Includes:
- LocoMotion::Concerns::IconableComponent, LocoMotion::Concerns::LinkableComponent, LocoMotion::Concerns::TippableComponent
- Defined in:
- app/components/daisy/actions/button_component.rb
Overview
We do not use component parts for the icons since we're
calling loco_icon within the component. But we do provide
custom CSS & HTML options to allow overriding / customization.
Includes the LocoMotion::Concerns::TippableComponent module to enable easy tooltip addition.
The Button component can be used to render HTML <button> or <a> elements
that are styled to look like a clickable element.
Constant Summary
Constants inherited from LocoMotion::BaseComponent
LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS
Instance Attribute Summary
Attributes inherited from LocoMotion::BaseComponent
Instance Method Summary collapse
-
#before_render ⇒ Object
Calls the #setup_component method before rendering the component.
-
#initialize(title = nil, action = nil, **kws, &block) ⇒ ButtonComponent
constructor
Instantiate a new Button component.
-
#setup_component ⇒ Object
Performs button-specific setup.
Methods included from LocoMotion::Concerns::IconableComponent
#has_icons?, #left_icon_html, #render_left_icon, #render_right_icon, #right_icon_html
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(title = nil, action = nil, **kws, &block) ⇒ ButtonComponent
Instantiate a new Button component.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'app/components/daisy/actions/button_component.rb', line 198 def initialize(title = nil, action = nil, **kws, &block) super # If both a title and a block are provided, assume the title is the action action = title if title && block_given? # Force the title to be nil if a block is given so we don't accidentally # render two titles title = nil if block_given? # ActionableComponent (via LinkableComponent) already read the `action:` # keyword into @action and emits the `data-action` attribute. Re-read it # here with the positional `action` arg as the fallback so the # button-only `daisy_button("Say Hello", "greeter#greet")` sugar keeps # working; the keyword still wins when both are given. @action = config_option(:action, action) # Initialize concerns -- handled by BaseComponent hook default_title = @left_icon || @right_icon ? nil : "Submit" @simple_title = config_option(:title, title || default_title) end |
Instance Method Details
#before_render ⇒ Object
Calls the #setup_component method before rendering the component.
223 224 225 226 227 228 |
# File 'app/components/daisy/actions/button_component.rb', line 223 def before_render # Run before the super so LinkableComponent can override our tag name setup_component super end |
#setup_component ⇒ Object
Performs button-specific setup. Adds the btn CSS class to the component.
Tag name setup (<a> vs <button>) and tooltip setup are handled by
LinkableComponent and TippableComponent concerns via BaseComponent hooks.
235 236 237 238 239 240 241 242 243 244 245 |
# File 'app/components/daisy/actions/button_component.rb', line 235 def setup_component # Ensure tag is button if LinkableComponent didn't set it to <a> set_tag_name(:component, :button) # Add the btn class add_css(:component, "btn") unless @skip_styling # `data-action` is emitted by ActionableComponent (pulled in via # LinkableComponent); see @action handling in initialize for the # positional-arg sugar. end |