class UiBibz::Ui::Core::Notifications::Components::Bar

Create a bar

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::Notifications::Components::Bar.new(percentage, options = nil, html_options = nil)

UiBibz::Ui::Core::Notifications::Components::Bar.new(options = nil, html_options = nil) do
  percentage
end

Examples

UiBibz::Ui::Core::Notifications::Components::Bar.new(50%, { value: 50})
# or
UiBibz::Ui::Core::Notifications::Components::Bar.new(10%, { value: 10, status: :success },{ class: 'test' }).render
# or
UiBibz::Ui::Core::Notifications::Components::Bar.new({ value: 10, status: :success},{ class: 'test' }) do
  10%
end.render

Public Instance Methods

pre_render() click to toggle source

Render html tag

# File lib/ui_bibz/ui/core/notifications/components/bar.rb, line 48
def pre_render
  content_tag :div, text, html_options
end

Private Instance Methods

animated() click to toggle source
# File lib/ui_bibz/ui/core/notifications/components/bar.rb, line 66
def animated
  'progress-bar-animated' unless options[:animated].nil?
end
component_html_classes() click to toggle source
# File lib/ui_bibz/ui/core/notifications/components/bar.rb, line 54
def component_html_classes
  ['progress-bar', striped, animated, status]
end
component_html_options() click to toggle source
# File lib/ui_bibz/ui/core/notifications/components/bar.rb, line 58
def component_html_options
  { 'aria-valuenow': value, 'aria-valuemin': min, 'aria-valuemax': max, style: "width: #{value}%", role: 'progressbar' }
end
max() click to toggle source
# File lib/ui_bibz/ui/core/notifications/components/bar.rb, line 74
def max
  options[:max] || 100
end
min() click to toggle source
# File lib/ui_bibz/ui/core/notifications/components/bar.rb, line 70
def min
  options[:min] || 0
end
status() click to toggle source
# File lib/ui_bibz/ui/core/notifications/components/bar.rb, line 82
def status
  if options[:statuses]
    "bg-#{statuses.fetch(statuses.size * value / 100, statuses.last)}"
  else
    "bg-#{options[:status]}" unless options[:status].nil?
  end
end
statuses() click to toggle source
# File lib/ui_bibz/ui/core/notifications/components/bar.rb, line 100
def statuses
  options[:statuses] == true ? %i[success primary info warning danger] : options[:statuses]
end
striped() click to toggle source
# File lib/ui_bibz/ui/core/notifications/components/bar.rb, line 62
def striped
  'progress-bar-striped' unless options[:striped].nil?
end
text() click to toggle source
# File lib/ui_bibz/ui/core/notifications/components/bar.rb, line 90
def text
  if options[:label].nil?
    "#{value}%"
  elsif options[:label] == false
    ''
  else
    options[:label]
  end
end
value() click to toggle source
# File lib/ui_bibz/ui/core/notifications/components/bar.rb, line 78
def value
  options[:value] || content.to_f
end