Module: Klods::Components::Nav

Included in:
Builders
Defined in:
lib/klods/components/nav.rb

Instance Method Summary collapse

Instance Method Details



12
13
14
15
16
17
18
19
# File 'lib/klods/components/nav.rb', line 12

def nav(a = nil, b = nil)
  props, children = Core.normalize_args(a, b)
  Core.build(
    tag: "nav", base: "klods-nav",
    modifiers: {collapse: "klods-nav--collapse"},
    props: props, children: children
  )
end


26
27
28
29
30
31
32
33
34
# File 'lib/klods/components/nav.rb', line 26

def nav_link(a = nil, b = nil)
  props, children = Core.normalize_args(a, b)
  link = Core.build(
    tag: "a", base: "klods-nav__link",
    modifiers: {active: "klods-nav__link--active"},
    props: props, children: children
  )
  Core.el("li", {}, link)
end


21
22
23
24
# File 'lib/klods/components/nav.rb', line 21

def nav_list(a = nil, b = nil)
  props, children = Core.normalize_args(a, b)
  Core.build(tag: "ul", base: "klods-nav__list", props: props, children: children)
end


36
37
38
39
40
41
42
# File 'lib/klods/components/nav.rb', line 36

def nav_toggle(a = nil, b = nil)
  props, children = Core.normalize_args(a, b)
  props = {"type" => "button", "aria-label" => "Toggle navigation", "class" => "klods-nav__toggle"}
    .merge(props.transform_keys(&:to_s))
  default_icon = Core.el("span", {"aria-hidden" => "true", "class" => "klods-icon"}, Core.raw(MENU_SVG))
  Core.el("button", props, children || default_icon)
end

#toc(a = nil, b = nil) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/klods/components/nav.rb', line 44

def toc(a = nil, b = nil)
  props, children = Core.normalize_args(a, b)
  Core.build(
    tag: "ul", base: "klods-toc",
    modifiers: {sub: "klods-toc--sub"},
    props: props, children: children
  )
end

#toc_item(a = nil, b = nil) ⇒ Object



53
54
55
56
# File 'lib/klods/components/nav.rb', line 53

def toc_item(a = nil, b = nil)
  props, children = Core.normalize_args(a, b)
  Core.el("li", props, children)
end


58
59
60
61
# File 'lib/klods/components/nav.rb', line 58

def toc_link(a = nil, b = nil)
  props, children = Core.normalize_args(a, b)
  Core.el("a", props, children)
end