Class: UiBibz::Ui::Core::Navigations::Navbar

Inherits:
Component show all
Includes:
UiBibz::Ui::Concerns::HtmlConcern, UiBibz::Ui::Concerns::NavigationConcern
Defined in:
lib/ui_bibz/ui/core/navigations/navbar.rb

Overview

Create a Navbar

This element is an extend of UiBibz::Ui::Core::Component.

Attributes

  • content - Content of element

  • options - Options of element

  • html_options - Html Options of element

Options

You can add HTML attributes using the html_options. You can pass arguments in options attribute:

  • type - Symbol (:light, :dark)

  • glyph

  • status (:secondary, :primary, :info, :warning, :danger, inverse)

  • position - Symbol (:top, :bottom)

  • position_type - Symbol (:fixed, :sticky)

  • title - String

  • container - Hash container options

  • container_html - Hash container html options

  • expand_size - Symbol size

(:sm, :md, :lg, :xl, :xxl)

Signatures

UiBibz::Ui::Core::Navbar.new(options = nil, html_options = nil).tap do |nb|
  ...
  nb.nav(options = nil, html_options = nil) do |n|
    n.link content options = nil, html_options = nil, &block
    n.link content options = nil, html_options = nil, &block
  end
  ...
end

Examples

UiBibz::Ui::Core::Navbar.new().tap do |nb|
  nb.nav(position: :right) do |n|
    n.link 'Link 1', "#"
    n.link 'Link 2', "#"
  end
  nb.form(url: 'search/', type: :form_tag) do
    text_field_tag 'search', nil, { class: 'form-control', placeholder: 'Search' }
    button 'Submit', type: :submit
  end
  nb.text 'My text'
end.render

Helper

ui_navbar(options = {}, html_options = {}) do |nb|
  nb.nav(options = {}, html_options = {}) do |n|
    n.link(content, options = {}, html_options = {})
    n.link(options = {}, html_options = {}) do
      content
    end
  end
  nb.brand content
  nb.link 'toto', "#"
end

Constant Summary

Constants inherited from Component

Component::BREAKPOINTS, Component::SIZES, Component::STATUSES

Instance Attribute Summary

Attributes inherited from Component

#content, #html_options, #options

Attributes inherited from Base

#output_buffer

Instance Method Summary collapse

Methods inherited from Component

#render

Methods included from GlyphExtension

#glyph_and_content_html

Methods included from KlassExtension

#exclude_classes, #exclude_classes_in_html_options, #join_classes

Methods inherited from Base

#generate_id, #i18n_set?, #inject_url

Constructor Details

#initializeNavbar

See UiBibz::Ui::Core::Component.initialize



81
82
83
84
# File 'lib/ui_bibz/ui/core/navigations/navbar.rb', line 81

def initialize(...)
  super
  @items = []
end

Instance Method Details

#brand(content = nil, options = nil, html_options = nil) ⇒ Object



126
127
128
# File 'lib/ui_bibz/ui/core/navigations/navbar.rb', line 126

def brand(content = nil, options = nil, html_options = nil, &)
  @brand = UiBibz::Ui::Core::Navigations::NavbarBrand.new(content, options, html_options, &).render
end

#form(model_or_url, options = {}) ⇒ Object

Add navbar form items See UiBibz::Ui::Core::NavbarForm



115
116
117
# File 'lib/ui_bibz/ui/core/navigations/navbar.rb', line 115

def form(model_or_url, options = {}, &)
  @items << UiBibz::Ui::Core::Navigations::NavbarForm.new(model_or_url, options, &)
end

#idObject



130
131
132
# File 'lib/ui_bibz/ui/core/navigations/navbar.rb', line 130

def id
  @id ||= generate_id('navbar-id')
end

Add navbar nav items See UiBibz::Ui::Core::NavbarNav



108
109
110
111
# File 'lib/ui_bibz/ui/core/navigations/navbar.rb', line 108

def nav(content = nil, options = nil, html_options = nil, &)
  options ||= {}
  @items << UiBibz::Ui::Core::Navigations::NavbarNav.new(content, options, html_options).tap(&)
end


134
135
136
137
138
139
140
141
# File 'lib/ui_bibz/ui/core/navigations/navbar.rb', line 134

def navbar_toggle_html(content = nil, &block)
  @navbar_toggle_html = if block.nil?
                          content
                        else
                          context = eval('self', block.binding) # rubocop:disable Style/EvalWithLocation
                          context.capture(&block)
                        end
end

#pre_renderObject

Render html tag



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/ui_bibz/ui/core/navigations/navbar.rb', line 87

def pre_render
   :nav, html_options do
    UiBibz::Ui::Core::Layouts::Container.new(options[:container], options[:container_html]) do
      capture do
        if brand_position == :left
          concat title
          concat @navbar_toggle_html
        end
        concat navbar_toggle_button_html
        if brand_position == :right
          concat title
          concat @navbar_toggle_html
        end
        concat body_html
      end
    end.render
  end
end

#text(content = nil, options = nil, html_options = nil) ⇒ Object

Not use !!!!! Add navbar text items See UiBibz::Ui::Core::NavbarText



122
123
124
# File 'lib/ui_bibz/ui/core/navigations/navbar.rb', line 122

def text(content = nil, options = nil, html_options = nil, &)
  @items << UiBibz::Ui::Core::Navigations::NavbarText.new(content, options, html_options, &)
end