Class: ElementComponent::Components::NavbarToggler

Inherits:
Element
  • Object
show all
Defined in:
lib/element_component/components/navbar/toggler.rb

Instance Attribute Summary

Attributes inherited from Element

#attributes, #contents, #element, #html

Instance Method Summary collapse

Methods inherited from Element

#add_attribute, #add_attribute!, #add_content, #add_content!, #new_element, #remove_attribute, #remove_attribute_value, #render, #reset_attributes!, #reset_contents!

Constructor Details

#initialize(target: nil, **attributes) ⇒ NavbarToggler

Returns a new instance of NavbarToggler.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/element_component/components/navbar/toggler.rb', line 6

def initialize(target: nil, **attributes)
  super("button", closing_tag: false)

  add_attribute(class: "navbar-toggler")
  add_attribute(type: "button")
  add_attribute("data-bs-toggle": "collapse")
  add_attribute("data-bs-target": "##{target}") if target
  add_attribute("aria-controls": target) if target
  add_attribute("aria-expanded": "false")
  add_attribute("aria-label": "Toggle navigation")
  add_attribute(attributes) unless attributes.empty?

  add_content(Element.new("span", class: "navbar-toggler-icon"))
end