Class: Flowbite::Sidebar::Navigation

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/flowbite/sidebar/navigation.rb

Overview

Renders the navigation list for a sidebar.

This component renders a <ul> with navigation items. It can be used inside a Flowbite::Sidebar for a fixed-position sidebar, or standalone in any layout that needs sidebar-style navigation.

Examples:

Inside a Sidebar

<%= render(Flowbite::Sidebar.new) do %>
  <%= render(Flowbite::Sidebar::Navigation.new) do |nav| %>
    <% nav.with_item do %>
      <%= render(Flowbite::Sidebar::Item.new(href: "/")) { "Home" } %>
    <% end %>
  <% end %>
<% end %>

Standalone

<%= render(Flowbite::Sidebar::Navigation.new) do |nav| %>
  <% nav.with_item do %>
    <%= render(Flowbite::Sidebar::Item.new(href: "/")) { "Home" } %>
  <% end %>
<% end %>

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class: nil, **options) ⇒ Navigation

Returns a new instance of Navigation.

Parameters:

  • class (Array<String>) (defaults to: nil)

    Additional CSS classes for the list element.

  • options (Hash)

    Additional HTML options for the list element.



37
38
39
40
41
# File 'app/components/flowbite/sidebar/navigation.rb', line 37

def initialize(class: nil, **options)
  super()
  @class = Array.wrap(binding.local_variable_get(:class))
  @options = options
end

Class Method Details

.classesObject



30
31
32
# File 'app/components/flowbite/sidebar/navigation.rb', line 30

def classes
  ["space-y-2", "font-medium"]
end

Instance Method Details

#callObject



43
44
45
46
47
48
49
# File 'app/components/flowbite/sidebar/navigation.rb', line 43

def call
  (:ul, list_options) do
    items.each do |item|
      concat(item)
    end
  end
end