Class: Nav::ToggleComponent

Inherits:
SparkComponents::Component
  • Object
show all
Defined in:
app/components/spark/nav/toggle_component.rb

Instance Method Summary collapse

Instance Method Details

#renderObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/components/spark/nav/toggle_component.rb', line 7

def render
  root_attr type: "button", id: @id || unique_id
  aria_attr hidden: true

  # When toggled on, adds an active class to itself and `nav-active` to `target` selector.
  data_attr nav_toggle: "#{target}"

  (:button, tag_attrs) do
    concat (:span, text, class: join_class("text")) if text
    if icon == 'nav-menu'
      concat (:span, class: join_class("icon-wrapper")) {
        (:span, nil, class: join_class("menu-icon"))
      }
    else
      concat (:span, class: join_class("icon")) {
        @view.use_svg(icon, width: '12px', class: join_class("svg")) if icon
      }
    end
  end
end