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, #tapped?

Methods included from PopoverExtension

#popover_data_html, #tooltip_data_html

Methods included from GlyphExtension

#generate_glyph, #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

#initialize(content = nil, options = nil, html_options = nil, &block) ⇒ Navbar

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



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

def initialize(content = nil, options = nil, html_options = nil, &block)
  super
  @items = []
end

Instance Method Details

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



124
125
126
# File 'lib/ui_bibz/ui/core/navigations/navbar.rb', line 124

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

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

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



113
114
115
# File 'lib/ui_bibz/ui/core/navigations/navbar.rb', line 113

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

#idObject



128
129
130
# File 'lib/ui_bibz/ui/core/navigations/navbar.rb', line 128

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

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



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

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


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

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
# 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
      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.render
  end
end

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

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



120
121
122
# File 'lib/ui_bibz/ui/core/navigations/navbar.rb', line 120

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