Class: BulmaPhlex::NavigationBarDropdown

Inherits:
Base
  • Object
show all
Defined in:
lib/bulma_phlex/navigation_bar_dropdown.rb

Overview

Renders a dropdown menu for the [Bulma navbar](bulma.io/documentation/components/navbar/#dropdown-menu).

Provides structured content for a navbar dropdown, including headers, links, and dividers. Intended to be used inside a NavigationBar block.

## Example

render BulmaPhlex::NavigationBar.new do |navbar|
  navbar.brand_item "My App", "/"

  navbar.right do |menu|
    menu.dropdown "Account" do |dropdown|
      dropdown.header "User"
      dropdown.item "Profile", "/profile"
      dropdown.item "Settings", "/settings"
      dropdown.divider
      dropdown.item "Sign Out", "/logout"
    end
  end
end

Instance Method Summary collapse

Instance Method Details

#dividerObject



40
41
42
# File 'lib/bulma_phlex/navigation_bar_dropdown.rb', line 40

def divider
  hr(class: "navbar-divider")
end

#header(label, divider: false) ⇒ Object

Adds a non-clickable header item to the dropdown menu. Optionally add a divider before the header with the ‘divder: true` parameter.



31
32
33
34
# File 'lib/bulma_phlex/navigation_bar_dropdown.rb', line 31

def header(label, divider: false)
  self.divider if divider
  div(class: "navbar-item has-text-weight-semibold") { label }
end

#item(label, path) ⇒ Object



36
37
38
# File 'lib/bulma_phlex/navigation_bar_dropdown.rb', line 36

def item(label, path)
  a(class: "navbar-item", href: path) { label }
end

#view_templateObject



25
26
27
# File 'lib/bulma_phlex/navigation_bar_dropdown.rb', line 25

def view_template(&)
  div(class: "navbar-dropdown is-right", &)
end