Class: Daisy::Navigation::BreadcrumbItemComponent

Inherits:
LocoMotion::BaseComponent show all
Includes:
LocoMotion::Concerns::IconableComponent, LocoMotion::Concerns::TippableComponent
Defined in:
app/components/daisy/navigation/breadcrumbs_component.rb

Overview

Component for a single breadcrumb item in a breadcrumbs trail.

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

#config, #loco_parent

Instance Method Summary collapse

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

Constructor Details

#initialize(title = nil, href = nil, *args, **kws) ⇒ BreadcrumbItemComponent

Initialize a breadcrumb item component.

Parameters:

  • title (String, nil) (defaults to: nil)

    The display text for the breadcrumb.

  • href (String, nil) (defaults to: nil)

    The URL for the breadcrumb link.

  • args (Array)

    Additional positional arguments passed to the component.

  • kws (Hash)

    Additional keyword options.

Options Hash (**kws):

  • icon (Symbol)

    Icon name to display before the title.

  • tip (String)

    Tooltip text shown on hover.



63
64
65
66
67
68
# File 'app/components/daisy/navigation/breadcrumbs_component.rb', line 63

def initialize(title = nil, href = nil, *args, **kws)
  super

  @simple_title = config_option(:title, title)
  @href = config_option(:href, href)
end

Instance Method Details

#before_renderObject

Configure the component before rendering.

Sets the component tag to be a list item and configures the link part with the href value.



74
75
76
77
78
79
# File 'app/components/daisy/navigation/breadcrumbs_component.rb', line 74

def before_render
  set_tag_name(:component, :li)

  set_tag_name(:link, "a")
  add_html(:link, { href: @href })
end

#callObject



81
82
83
84
85
86
87
88
89
90
91
# File 'app/components/daisy/navigation/breadcrumbs_component.rb', line 81

def call
  part(:component) do
    if @href
      part(:link) do
        render_icon_and_content
      end
    else
      render_icon_and_content
    end
  end
end

#render_icon_and_contentString

Render the icon (if provided) and content.

Returns:

  • (String)

    The rendered HTML for the icon and content.



96
97
98
99
# File 'app/components/daisy/navigation/breadcrumbs_component.rb', line 96

def render_icon_and_content
  concat(render_icon)
  concat(content || @simple_title)
end