Module: Klods::Components::Nav
- Included in:
- Builders
- Defined in:
- lib/klods/components/nav.rb
Instance Method Summary collapse
- #nav(a = nil, b = nil, &block) ⇒ Object
- #nav_link(a = nil, b = nil, &block) ⇒ Object
- #nav_list(a = nil, b = nil, &block) ⇒ Object
- #nav_toggle(a = nil, b = nil, &block) ⇒ Object
- #toc(a = nil, b = nil, &block) ⇒ Object
- #toc_item(a = nil, b = nil, &block) ⇒ Object
- #toc_link(a = nil, b = nil, &block) ⇒ Object
Instance Method Details
#nav(a = nil, b = nil, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/klods/components/nav.rb', line 12 def nav(a = nil, b = nil, &block) props, children = Core.normalize_args(a, b) children = klods_capture(&block) if block Core.build( tag: "nav", base: "klods-nav", modifiers: {collapse: "klods-nav--collapse"}, props: props, children: children ) end |
#nav_link(a = nil, b = nil, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/klods/components/nav.rb', line 28 def nav_link(a = nil, b = nil, &block) props, children = Core.normalize_args(a, b) children = klods_capture(&block) if block link = Core.build( tag: "a", base: "klods-nav__link", modifiers: {active: "klods-nav__link--active"}, props: props, children: children ) Core.el("li", {}, link) end |
#nav_list(a = nil, b = nil, &block) ⇒ Object
22 23 24 25 26 |
# File 'lib/klods/components/nav.rb', line 22 def nav_list(a = nil, b = nil, &block) props, children = Core.normalize_args(a, b) children = klods_capture(&block) if block Core.build(tag: "ul", base: "klods-nav__list", props: props, children: children) end |
#nav_toggle(a = nil, b = nil, &block) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/klods/components/nav.rb', line 39 def nav_toggle(a = nil, b = nil, &block) props, children = Core.normalize_args(a, b) children = klods_capture(&block) if block 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, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/klods/components/nav.rb', line 48 def toc(a = nil, b = nil, &block) props, children = Core.normalize_args(a, b) children = klods_capture(&block) if block Core.build( tag: "ul", base: "klods-toc", modifiers: {sub: "klods-toc--sub"}, props: props, children: children ) end |
#toc_item(a = nil, b = nil, &block) ⇒ Object
58 59 60 61 62 |
# File 'lib/klods/components/nav.rb', line 58 def toc_item(a = nil, b = nil, &block) props, children = Core.normalize_args(a, b) children = klods_capture(&block) if block Core.el("li", props, children) end |
#toc_link(a = nil, b = nil, &block) ⇒ Object
64 65 66 67 68 |
# File 'lib/klods/components/nav.rb', line 64 def toc_link(a = nil, b = nil, &block) props, children = Core.normalize_args(a, b) children = klods_capture(&block) if block Core.el("a", props, children) end |