Class: Crm::StickyHeaderComponent::NavItem
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Crm::StickyHeaderComponent::NavItem
- Defined in:
- app/components/crm/sticky_header_component.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(href:, label:, icon: nil, active: false, badge: nil, suffix_html: nil) ⇒ NavItem
constructor
A new instance of NavItem.
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
#call ⇒ Object
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 content_tag(:li, class: "nav-item") do content_tag(:a, class: css.join(" "), href: @href) do parts = [] parts << content_tag(:i, nil, class: "#{@icon} 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 |