Class: Crm::StickyHeaderComponent::NavItem

Inherits:
ApplicationComponent show all
Defined in:
app/components/crm/sticky_header_component.rb

Overview

A single nav pill rendered as <li class="nav-item"> wrapping an anchor,
with optional icon, badge, and trailing raw HTML.

Delegated Instance Attributes collapse

Methods inherited from ApplicationComponent

#cms_link, #image_asset_tag, #image_tag, #number_to_currency, #number_with_delimiter, #post_path, #post_url, #strip_tags

Instance Method Summary collapse

Methods inherited from ApplicationComponent

#fetch_or_fallback

Constructor Details

#initialize(href:, label:, icon: nil, icon_family: nil, active: false, badge: nil, suffix_html: nil) ⇒ NavItem

Returns a new instance of NavItem.

Parameters:

  • href (String)

    anchor target, typically a #section-id fragment for scrollspy

  • label (String)

    visible text of the nav pill

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

    canonical FA6+ icon name (e.g. 'circle-info')

  • icon_family (Symbol, nil) (defaults to: nil)

    icon family override (:solid, :brands, :custom); defaults to sharp-regular

  • active (Boolean) (defaults to: false)

    whether the pill renders with the active class

  • badge (String, Integer, nil) (defaults to: nil)

    optional count/text rendered as a secondary badge after the label

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

    optional raw HTML appended after the badge (marked html_safe)



96
97
98
99
100
101
102
103
104
105
# File 'app/components/crm/sticky_header_component.rb', line 96

def initialize(href:, label:, icon: nil, icon_family: nil, active: false, badge: nil, suffix_html: nil)
  super()
  @href = href
  @label = label
  @icon = icon
  @icon_family = icon_family
  @active = active
  @badge = badge
  @suffix_html = suffix_html
end

Instance Method Details

#callActiveSupport::SafeBuffer

Renders the nav pill as <li class="nav-item"><a ...>…</a></li>.

Returns:

  • (ActiveSupport::SafeBuffer)

    the nav item markup



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/components/crm/sticky_header_component.rb', line 109

def call
  css = %w[nav-link text-nowrap]
  css << "active" if @active

  (:li, class: "nav-item") do
    (:a, class: css.join(" "), href: @href) do
      parts = []
      parts << fa_icon(@icon, family: @icon_family, class: 'me-1') if @icon.present?
      parts << @label
      parts << (:span, @badge, class: "badge bg-secondary ms-1") if @badge.present?
      parts << @suffix_html.html_safe if @suffix_html.present?
      safe_join(parts)
    end
  end
end

#fa_iconObject

Alias for Helpers#fa_icon

Returns:

  • (Object)

    Helpers#fa_icon

See Also:



87
# File 'app/components/crm/sticky_header_component.rb', line 87

delegate :fa_icon, to: :helpers