Class: Crm::StickyHeaderComponent::NavItem

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

Instance Method Summary collapse

Methods inherited from ApplicationComponent

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

Constructor Details

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

Returns a new instance of NavItem.



67
68
69
70
71
72
73
74
75
# File 'app/components/crm/sticky_header_component.rb', line 67

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

Instance Method Details

#callObject



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

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

  (:li, class: "nav-item") do
    (:a, class: css.join(" "), href: @href) do
      parts = []
      parts << (:i, nil, class: "#{@icon} 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