Class: UiBibz::Ui::Core::Forms::Dropdowns::Dropdown

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

Overview

Create a dropdown

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

  • open - Boolean (:xs, :sm, :lg)

  • glyph - Add glyph with name or hash options

    • name - String

    • size - Integer

    • type - Symbol

  • html_button - Hash

  • theme - Symbol, defaut: :dark

  • position - Symbol (:up, :right, :down, :left)

  • alignment - Symbol/Hash - eq. { direction: :start, size: :lg } (:left, :right, :start, :end)

Signatures

UiBibz::Ui::Core::Forms::Dropdowns::Dropdown.new(options = nil, html_options = nil).tap do |d|
  ...
  d.header content = nil, options = nil, html_options = nil, &block
  d.divider
  d.link content = nil, options = nil, html_options = nil, &block
  ...
end

Examples

UiBibz::Ui::Core::Forms::Dropdowns::Dropdown.new(name, status: :success).tap do |d|
  d.link 'test', { url: '#' }
  d.divider
  d.header 'Header 1'
  d.link 'test2', { url: '#' }
end.render

Helper

dropdown(name, options = {}, html_options = {}) do |d|
  d.link(content, options = {}, html_options = {})
  d.link(options = {}, html_options = {}) do
    content
  end
  d.divider
  d.header(content, options = {}, html_options = {})
  d.header(options = {}, html_options = {}) do
    content
  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, options = nil, html_options = nil, &block) ⇒ Dropdown

Returns a new instance of Dropdown.



73
74
75
76
77
# File 'lib/ui_bibz/ui/core/forms/dropdowns/dropdown.rb', line 73

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

Instance Method Details

#dividerObject

Add dropdown Separator See UiBibz::Ui::Core::Forms::Dropdowns::Components::DropdownDivider



95
96
97
# File 'lib/ui_bibz/ui/core/forms/dropdowns/dropdown.rb', line 95

def divider
  @items << UiBibz::Ui::Core::Forms::Dropdowns::Components::DropdownDivider.new.render
end

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

Add dropdown header See UiBibz::Ui::Core::Forms::Dropdowns::Components::DropdownHeader



89
90
91
# File 'lib/ui_bibz/ui/core/forms/dropdowns/dropdown.rb', line 89

def header(content = nil, options = nil, html_options = nil, &block)
  @items << UiBibz::Ui::Core::Forms::Dropdowns::Components::DropdownHeader.new(content, options, html_options, &block).render
end

#idObject



105
106
107
# File 'lib/ui_bibz/ui/core/forms/dropdowns/dropdown.rb', line 105

def id
  @id ||= html_options[:id] || generate_id('dropdown')
end

Add dropdown link in list See UiBibz::Ui::Core::Forms::Dropdowns::Components::DropdownLink



101
102
103
# File 'lib/ui_bibz/ui/core/forms/dropdowns/dropdown.rb', line 101

def link(content = nil, options = nil, html_options = nil, &block)
  @items << UiBibz::Ui::Core::Forms::Dropdowns::Components::DropdownLink.new(content, options, html_options, &block).render
end

#pre_renderObject

Render html tag



80
81
82
83
84
85
# File 'lib/ui_bibz/ui/core/forms/dropdowns/dropdown.rb', line 80

def pre_render
   :div, html_options do
    concat button_html
    concat ul_html
  end
end