Class: BetterUi::Breadcrumb::ItemComponent

Inherits:
ApplicationComponent show all
Defined in:
app/components/better_ui/breadcrumb/item_component.rb

Overview

A breadcrumb item component that renders as a link or current page indicator.

When an href is provided, the item renders as a link. When href is nil, it renders as a span with aria-current="page" to indicate the current page.

Examples:

Link item

<%= render BetterUi::Breadcrumb::ItemComponent.new(label: "Home", href: "/") %>

Current page item (no href)

<%= render BetterUi::Breadcrumb::ItemComponent.new(label: "Settings") %>

With icon

<%= render BetterUi::Breadcrumb::ItemComponent.new(label: "Home", href: "/") do |item| %>
  <% item.with_icon_before do %>
    <svg>...</svg>
  <% end %>
<% end %>

Constant Summary

Constants inherited from ApplicationComponent

ApplicationComponent::SHADOWS, ApplicationComponent::VARIANTS, ApplicationComponent::VARIANT_BODY_DIVIDE, ApplicationComponent::VARIANT_DIVIDE, ApplicationComponent::VARIANT_HEADER_BG, ApplicationComponent::VARIANT_HEADER_TEXT, ApplicationComponent::VARIANT_HIGHLIGHTED, ApplicationComponent::VARIANT_HOVERABLE, ApplicationComponent::VARIANT_RING, ApplicationComponent::VARIANT_SORT_ICON, ApplicationComponent::VARIANT_STRIPED

Instance Method Summary collapse

Constructor Details

#initialize(label:, href: nil, **options) ⇒ ItemComponent

Initializes a new breadcrumb item component.

Parameters:

  • label (String) —

    the text to display (required)

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

    the link URL (nil renders as current page)

  • options (Hash) —

    additional HTML attributes passed to the element



33
34
35
36
37
# File 'app/components/better_ui/breadcrumb/item_component.rb', line 33

def initialize(label:, href: nil, **options)
  @label = label
  @href = href
  @options = options
end

Instance Method Details

#current? ⇒ Boolean

Whether this item represents the current page.

Returns:

  • (Boolean) —

    true if no href is provided



42
43
44
# File 'app/components/better_ui/breadcrumb/item_component.rb', line 42

def current?
  @href.nil?
end

#with_icon_before ⇒ Object

Slot for rendering an icon before the label.

Yield Returns:

  • (String) —

    the SVG or icon HTML content



26
# File 'app/components/better_ui/breadcrumb/item_component.rb', line 26

renders_one :icon_before