Class: Railsboot::BadgeComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/railsboot/badge_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(pill: false, color: DEFAULT_COLOR, **html_attributes) ⇒ BadgeComponent

Returns a new instance of BadgeComponent.



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/components/railsboot/badge_component.rb', line 2

def initialize(pill: false, color: DEFAULT_COLOR, **html_attributes)
  @pill = pill
  @color = fetch_or_raise(color, COLORS)
  @html_attributes = html_attributes

  @html_attributes[:tag] = :span
  @html_attributes[:class] = class_names(
    "badge",
    "bg-#{@color}",
    {"rounded-pill" => @pill},
    html_attributes.delete(:class)
  )
end

Instance Method Details

#callObject



16
17
18
19
20
# File 'app/components/railsboot/badge_component.rb', line 16

def call
  render Railsboot::BaseComponent.new(**@html_attributes) do
    content
  end
end