Class: UiBibz::Ui::Core::Navigations::Toolbar

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

Overview

Create a toolbar

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:

  • status - status of element with symbol value: (:primary, :secondary, :info, :warning, :danger)

  • size - Size of element with symbol value: (:xs, :sm, :lg)

  • position - Position vertical or horizontal with symbol value: (:vertical, :horizontal)

Signatures

UiBibz::Ui::Core::Navigations::Toolbar.new(options = nil, html_options = nil) do |bt|
  ...
end

Examples

UiBibz::Ui::Core::Navigations::Toolbar.new(status: :primary, size: :xs) do |bt|
  bt.button_group do |bg|
    bg.ui_button 'test 1'
    bg.ui_button 'test 2'
  end
  bt.button_group do |bg|
    bg.ui_button 'test 3'
    bg.ui_button 'test 4'
  end
end.render

Helper

ui_toolbar(options = {}, html_options = {}) do |bt|
  bt.button_group do |bg|
    bg.ui_button 'content'
    bg.ui_button_link 'Link', url: '#'
  end
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, #status

Methods inherited from Base

#generate_id, #i18n_set?, #inject_url

Constructor Details

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

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



58
59
60
61
# File 'lib/ui_bibz/ui/core/navigations/toolbar.rb', line 58

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

Instance Method Details

#button_group(cont = nil, opt = nil, hopt = nil, &block) ⇒ Object



68
69
70
71
72
# File 'lib/ui_bibz/ui/core/navigations/toolbar.rb', line 68

def button_group(cont = nil, opt = nil, hopt = nil, &block)
  cont = @options.merge(cont || {})
  (cont || {}).delete(:class)
  @items << UiBibz::Ui::Core::Forms::Buttons::ButtonGroup.new(cont, opt, hopt).tap(&block)
end

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

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



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

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

#pre_renderObject

Render html tag



64
65
66
# File 'lib/ui_bibz/ui/core/navigations/toolbar.rb', line 64

def pre_render
   :div, @items.map(&:render).join.html_safe, html_options
end

#spacer(num = 'auto') ⇒ Object



74
75
76
77
# File 'lib/ui_bibz/ui/core/navigations/toolbar.rb', line 74

def spacer(num = 'auto')
  kls = "me-#{num}"
  @items.last.html_options['class'] = join_classes(@items.last.html_options.delete(:class), @items.last.html_options[:class], kls)
end