Class: Crm::StickyHeaderComponent::NavItem

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

Overview

Namespace for NavItem ViewComponents.

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.



77
78
79
80
81
82
83
84
85
86
# File 'app/components/crm/sticky_header_component.rb', line 77

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

#callObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/components/crm/sticky_header_component.rb', line 88

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:



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

delegate :fa_icon, to: :helpers