class UiBibz::Ui::Core::Lists::Components::List

Create a list

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

Attributes

Options

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

Signatures

UiBibz::Ui::Core::Lists::Components::List.new do |l|
  l.header content =  nil, options = nil, html_options = nil, &block
  l.body content =  nil, options = nil, html_options = nil, &block
end

UiBibz::Ui::Core::Lists::Components::List.new content, options = nil, html_options = nil

UiBibz::Ui::Core::Lists::Components::List.new options = nil, html_options = nil do
  content
end

Examples

UiBibz::Ui::Core::Lists::Components::List.new('Test', status: :success, url: '#test').render

UiBibz::Ui::Core::Lists::Components::List.new(status: :primary) do
    'Test 2'
end.render

UiBibz::Ui::Core::List.new(state: :active) do |l|
  l.header 'My title', nil, class: 'my-title'
  l.body do
    'My content'
  end
end.render

Public Instance Methods

body(content = nil, options = nil, html_options = nil, &block) click to toggle source

Add body which is a component

# File lib/ui_bibz/ui/core/lists/components/list.rb, line 79
def body(content = nil, options = nil, html_options = nil, &block)
  @body = UiBibz::Ui::Core::Lists::Components::ListBody.new content, options, html_options, &block
end
header(content = nil, options = nil, html_options = nil, &block) click to toggle source

Add header which is a component

# File lib/ui_bibz/ui/core/lists/components/list.rb, line 74
def header(content = nil, options = nil, html_options = nil, &block)
  @header = UiBibz::Ui::Core::Lists::Components::ListHeader.new content, options, html_options, &block
end
pre_render() click to toggle source

Render html tag

# File lib/ui_bibz/ui/core/lists/components/list.rb, line 64
def pre_render
  content_tag tag_type, html_options do
    concat glyph_and_content_html if @content
    concat header_html if @header
    concat body_html   if @body
    concat badge_html  if @options[:badge]
  end
end

Private Instance Methods

badge_classes() click to toggle source
# File lib/ui_bibz/ui/core/lists/components/list.rb, line 97
def badge_classes
  'd-flex justify-content-between align-items-center' unless options[:badge].nil?
end
badge_html() click to toggle source
# File lib/ui_bibz/ui/core/lists/components/list.rb, line 132
def badge_html
  if options[:badge].is_a? Hash
    options[:badge][:status] = options[:status] || :secondary
    UiBibz::Ui::Core::Notifications::Badge.new(options[:badge].delete(:content), options[:badge]).render

  else
    UiBibz::Ui::Core::Notifications::Badge.new(options[:badge], type: :pill, status: (options[:status] || :secondary)).render
  end
end
body_html() click to toggle source
# File lib/ui_bibz/ui/core/lists/components/list.rb, line 93
def body_html
  @body.render
end
button_type?() click to toggle source
# File lib/ui_bibz/ui/core/lists/components/list.rb, line 118
def button_type?
  @options[:tag_type] == :button || @html_options.delete(:tag_type) == :button
end
component_html_classes() click to toggle source
# File lib/ui_bibz/ui/core/lists/components/list.rb, line 85
def component_html_classes
  super << ['list-group-item', tag_type_class, badge_classes, header_classes]
end
header_classes() click to toggle source
# File lib/ui_bibz/ui/core/lists/components/list.rb, line 105
def header_classes
  'flex-column align-items-start' if @options[:tap]
end
header_html() click to toggle source
# File lib/ui_bibz/ui/core/lists/components/list.rb, line 89
def header_html
  @header.render
end
status() click to toggle source
# File lib/ui_bibz/ui/core/lists/components/list.rb, line 101
def status
  "list-group-item-#{@options[:status]}" unless @options[:status].nil?
end
tag_type() click to toggle source
# File lib/ui_bibz/ui/core/lists/components/list.rb, line 122
def tag_type
  if link_type?
    :a
  elsif button_type?
    :button
  else
    :li
  end
end
tag_type_class() click to toggle source
# File lib/ui_bibz/ui/core/lists/components/list.rb, line 109
def tag_type_class
  'list-group-item-action' if button_type? || link_type?
end