Class: Daisy::Navigation::LinkComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::Navigation::LinkComponent
- Defined in:
- app/components/daisy/navigation/link_component.rb
Overview
Creates a styled link component that can be used for navigation or inline text links. This component is designed to work similarly to Rails’ ‘link_to` helper.
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 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(*args, **kws) ⇒ LinkComponent
Create a new instance of the LinkComponent.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/components/daisy/navigation/link_component.rb', line 50 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.
74 75 76 77 78 |
# File 'app/components/daisy/navigation/link_component.rb', line 74 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.
87 88 89 |
# File 'app/components/daisy/navigation/link_component.rb', line 87 def call part(:component) { content || @title } end |