Class: Railsboot::BadgeComponent

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

Overview

ViewComponent: renders the badge block.

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of BadgeComponent.



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

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



18
19
20
21
22
# File 'app/components/railsboot/badge_component.rb', line 18

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