Class: Bs5::BadgeComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/components/bs5/badge_component.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, color: :secondary, pill: false) ⇒ BadgeComponent

Returns a new instance of BadgeComponent.



12
13
14
15
16
# File 'app/components/bs5/badge_component.rb', line 12

def initialize(text:, color: :secondary, pill: false)
  @text = text
  @color = color.to_sym
  @pill = pill
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



7
8
9
# File 'app/components/bs5/badge_component.rb', line 7

def color
  @color
end

#textObject (readonly)

Returns the value of attribute text.



7
8
9
# File 'app/components/bs5/badge_component.rb', line 7

def text
  @text
end

Instance Method Details

#before_renderObject



18
19
20
# File 'app/components/bs5/badge_component.rb', line 18

def before_render
  raise errors.full_messages.to_sentence if invalid?
end