Class: Bulmacomp::NavbarComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Bulmacomp::NavbarComponent
- Defined in:
- app/components/bulmacomp/navbar_component.rb
Overview
Make an html structure for a bulma navbar
Instance Method Summary collapse
-
#call ⇒ String
Html_safe navbar.
-
#initialize(brand: nil, navbar_start: nil, navbar_end: nil, **opts) {|optional| ... } ⇒ NavbarComponent
constructor
A new instance of NavbarComponent.
-
#navbar_brand ⇒ String
Html_safe navbar-brand tag.
-
#navbar_burger ⇒ String
Html_safe navbar-burger link.
-
#navbar_menu ⇒ String
Html_safe navbar-menu tag.
Constructor Details
#initialize(brand: nil, navbar_start: nil, navbar_end: nil, **opts) {|optional| ... } ⇒ NavbarComponent
Returns a new instance of NavbarComponent.
51 52 53 54 55 56 57 |
# File 'app/components/bulmacomp/navbar_component.rb', line 51 def initialize(brand: nil, navbar_start: nil, navbar_end: nil, **opts) super @brand = brand @navbar_start = tag.div , class: 'navbar-start' if .present? @navbar_end = tag.div , class: 'navbar-end' if .present? @opts = { class: 'navbar', aria: { role: 'navigation', label: 'main navigation' } }.merge(opts) end |
Instance Method Details
#call ⇒ String
Returns html_safe navbar.
60 61 62 |
# File 'app/components/bulmacomp/navbar_component.rb', line 60 def call tag.nav safe_join([, ]), **@opts end |
#navbar_brand ⇒ String
Returns html_safe navbar-brand tag.
65 66 67 68 69 70 |
# File 'app/components/bulmacomp/navbar_component.rb', line 65 def return if @brand.blank? tag.div safe_join([link_to(@brand, root_path, data_turbo_frame: 'yield', class: 'navbar-item'), ]), class: 'navbar-brand' end |
#navbar_burger ⇒ String
Returns html_safe navbar-burger link.
78 79 80 81 82 83 |
# File 'app/components/bulmacomp/navbar_component.rb', line 78 def aria = {expanded: 'false', label: 'menu'} data = {action: 'click->page#toggleMenu'} role = 'button' tag.a tag.span(aria_hidden: true) * 3, class: 'navbar-burger', aria:, data:, role: end |
#navbar_menu ⇒ String
Returns html_safe navbar-menu tag.
73 74 75 |
# File 'app/components/bulmacomp/navbar_component.rb', line 73 def tag.div(safe_join([@navbar_start, content, @navbar_end]), class: 'navbar-menu', data: { page_target: 'menu' }) end |