Class: Daisy::Navigation::LinkComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::Navigation::LinkComponent
- Includes:
- LocoMotion::Concerns::IconableComponent, LocoMotion::Concerns::LinkableComponent, LocoMotion::Concerns::TippableComponent
- Defined in:
- app/components/daisy/navigation/link_component.rb
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
Adds the relevant Daisy classes and applies the href and target attributes if provided.
-
#call ⇒ Object
Renders the link component.
-
#initialize(*args, **kws) ⇒ LinkComponent
constructor
Create a new instance of the LinkComponent.
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(*args, **kws) ⇒ LinkComponent
Create a new instance of the LinkComponent.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/components/daisy/navigation/link_component.rb', line 88 def initialize(*args, **kws) super if args.size == 1 # If given one arg, assume it's the href and / or the title (if no block is given) @title = args[0] @href = args[0] elsif args.size == 2 # If given two args, assume the first is the title and the second is the href @title = args[0] @href = args[1] else # Otherwise, assume they pass everything as keyword arguments @title = config_option(:title) @href = config_option(:href) end @target = config_option(:target) end |
Instance Method Details
#before_render ⇒ Object
Adds the relevant Daisy classes and applies the href and target attributes if provided.
112 113 114 115 116 |
# File 'app/components/daisy/navigation/link_component.rb', line 112 def before_render super setup_component end |
#call ⇒ Object
Renders the link component.
Because this is an inline component which might be utlized alongside text, we utilize the ‘call` method instead of a template to ensure that no additional whitespace gets added to the output.
125 126 127 128 129 130 131 132 133 134 135 |
# File 'app/components/daisy/navigation/link_component.rb', line 125 def call if content? part(:component) { content } else part(:component) do concat(render_left_icon) concat(@title) concat(render_right_icon) end end end |