Class: ElementComponent::Components::ProgressBar

Inherits:
Element
  • Object
show all
Defined in:
lib/element_component/components/progress/bar.rb

Constant Summary collapse

VALID_VARIANTS =
%i[primary secondary success danger warning info light dark].freeze

Instance Attribute Summary

Attributes inherited from Element

#attributes, #contents, #element, #html

Instance Method Summary collapse

Methods inherited from Element

#add_attribute, #add_attribute!, #add_content, #add_content!, #new_element, #remove_attribute, #remove_attribute_value, #render, #reset_attributes!, #reset_contents!

Constructor Details

#initialize(value: 0, variant: nil, striped: false, animated: false, **attributes, &block) ⇒ ProgressBar

Returns a new instance of ProgressBar.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/element_component/components/progress/bar.rb', line 8

def initialize(value: 0, variant: nil, striped: false, animated: false, **attributes, &block)
  super("div", &block)

  add_attribute(class: "progress-bar")
  add_attribute(class: "bg-#{variant}") if variant
  add_attribute(class: "progress-bar-striped") if striped
  add_attribute(class: "progress-bar-animated") if animated
  add_attribute(role: "progressbar")
  add_attribute("aria-valuenow": value.to_s)
  add_attribute("aria-valuemin": "0")
  add_attribute("aria-valuemax": "100")
  add_attribute(style: "width: #{value}%")
  add_attribute(attributes) unless attributes.empty?
end