Class: Crm::StickyHeaderComponent::NavItem
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Crm::StickyHeaderComponent::NavItem
- 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
-
#fa_icon ⇒ Object
Alias for Helpers#fa_icon.
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
-
#call ⇒ ActiveSupport::SafeBuffer
Renders the nav pill as
<li class="nav-item"><a ...>…</a></li>. -
#initialize(href:, label:, icon: nil, icon_family: nil, active: false, badge: nil, suffix_html: nil) ⇒ NavItem
constructor
A new instance of NavItem.
Methods inherited from ApplicationComponent
Constructor Details
#initialize(href:, label:, icon: nil, icon_family: nil, active: false, badge: nil, suffix_html: nil) ⇒ NavItem
Returns a new instance of NavItem.
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
#call ⇒ ActiveSupport::SafeBuffer
Renders the nav pill as <li class="nav-item"><a ...>…</a></li>.
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 content_tag(:li, class: "nav-item") do content_tag(:a, class: css.join(" "), href: @href) do parts = [] parts << fa_icon(@icon, family: @icon_family, class: 'me-1') if @icon.present? parts << @label parts << content_tag(: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_icon ⇒ Object
Alias for Helpers#fa_icon
87 |
# File 'app/components/crm/sticky_header_component.rb', line 87 delegate :fa_icon, to: :helpers |