Class: DsfrComponent::BadgeComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/dsfr_component/badge_component.rb

Constant Summary collapse

STATUSES =
%i[success error info warning new].freeze

Constants inherited from Base

DsfrComponent::Base::HEADING_LEVELS

Instance Attribute Summary

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Constructor Details

#initialize(status:, classes: [], html_attributes: {}) ⇒ BadgeComponent

Returns a new instance of BadgeComponent.

Parameters:

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
# File 'app/components/dsfr_component/badge_component.rb', line 6

def initialize(status:, classes: [], html_attributes: {})
  raise(ArgumentError, "`status` should be one of #{STATUSES}") unless STATUSES.include?(status)

  @status = status

  classes.push("fr-badge--#{@status}")

  super(classes: classes, html_attributes: html_attributes)
end

Instance Method Details

#callObject



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

def call
  tag.div(**html_attributes) do
    content
  end
end