Class: UiBibz::Ui::Core::Forms::Buttons::ButtonGroup

Inherits:
Component
  • Object
show all
Includes:
UiBibz::Ui::Concerns::HtmlConcern
Defined in:
lib/ui_bibz/ui/core/forms/buttons/button_group.rb

Overview

Create a button group

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:

  • state (:active, :disabled)

  • 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::Forms::Buttons::ButtonGroup.new(options = nil, html_options = nil) do |bg|
  ...
end

Examples

UiBibz::Ui::Core::Forms::Buttons::ButtonGroup.new(position: :vertical, size: :xs) do |bg|
  bg.ui_button 'test'
  bg.ui_button 'test2'
end.render

Helper

ui_button_group(options = {}, html_options = {}) do |bg|
  bg.ui_button 'content'
  bg.ui_button_link 'Link', url: '#'
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) ⇒ ButtonGroup

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



53
54
55
56
# File 'lib/ui_bibz/ui/core/forms/buttons/button_group.rb', line 53

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

Instance Method Details

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



63
64
65
66
67
68
69
70
71
# File 'lib/ui_bibz/ui/core/forms/buttons/button_group.rb', line 63

def button(content = nil, options = nil, html_options = nil, &block)
  if block.nil?
    options = @options.merge(options || {})
  else
    content = @options.merge(content || {})
  end

  @items << Button.new(content, options, html_options, &block)
end


73
74
75
76
77
78
79
80
81
# File 'lib/ui_bibz/ui/core/forms/buttons/button_group.rb', line 73

def button_link(content = nil, options = nil, html_options = nil, &block)
  if block.nil?
    options = @options.merge(options || {})
  else
    content = @options.merge(content || {})
  end

  @items << ButtonLink.new(content, options, html_options, &block)
end

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



103
104
105
# File 'lib/ui_bibz/ui/core/forms/buttons/button_group.rb', line 103

def choice_group(content = nil, options = nil, html_options = nil, &block)
  @items << UiBibz::Ui::Core::Forms::Choices::ChoiceGroup.new(content, options, html_options).tap(&block)
end


83
84
85
86
# File 'lib/ui_bibz/ui/core/forms/buttons/button_group.rb', line 83

def dropdown(content, options = {}, html_options = nil, &block)
  options = @options.merge(options)
  @items << ButtonGroupDropdown.new(content, options, html_options).tap(&block)
end

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



99
100
101
# File 'lib/ui_bibz/ui/core/forms/buttons/button_group.rb', line 99

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

#input(attribute_name, options = {}, &block) ⇒ Object



93
94
95
96
97
# File 'lib/ui_bibz/ui/core/forms/buttons/button_group.rb', line 93

def input(attribute_name, options = {}, &block)
  options = @options.merge(options)

  @items << @options[:form].input(attribute_name, options.merge({ label: false, wrapper: false }), &block)
end

#pre_renderObject

Render html tag



59
60
61
# File 'lib/ui_bibz/ui/core/forms/buttons/button_group.rb', line 59

def pre_render
   :div, @items.map { |item| item.respond_to?(:render) ? item.try(:render) : item }.join.html_safe, html_options
end

#split_dropdown(content, options = {}, html_options = nil, &block) ⇒ Object



88
89
90
91
# File 'lib/ui_bibz/ui/core/forms/buttons/button_group.rb', line 88

def split_dropdown(content, options = {}, html_options = nil, &block)
  options = @options.merge(options)
  @items << ButtonGroupSplitDropdown.new(content, options, html_options).tap(&block)
end