Class: ElementComponent::Components::Badge
- Defined in:
- lib/element_component/components/badge.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
-
#initialize(variant: :primary, pill: false, **attributes, &block) ⇒ Badge
constructor
A new instance of Badge.
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(variant: :primary, pill: false, **attributes, &block) ⇒ Badge
Returns a new instance of Badge.
8 9 10 11 12 13 14 15 |
# File 'lib/element_component/components/badge.rb', line 8 def initialize(variant: :primary, pill: false, **attributes, &block) super("span", &block) add_attribute(class: "badge") add_attribute(class: "bg-#{variant}") add_attribute(class: "rounded-pill") if pill add_attribute(attributes) unless attributes.empty? end |