Class: Pajamas::BadgeComponent

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

Constant Summary collapse

SIZE_OPTIONS =
[:sm, :md, :lg].freeze
VARIANT_OPTIONS =
[:muted, :neutral, :info, :success, :warning, :danger, :tier].freeze

Instance Method Summary collapse

Constructor Details

#initialize(text = nil, icon: nil, icon_classes: [], icon_only: false, href: nil, size: :md, variant: :muted, **html_options) ⇒ BadgeComponent

Returns a new instance of BadgeComponent.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/components/pajamas/badge_component.rb', line 5

def initialize(
  text = nil,
  icon: nil,
  icon_classes: [],
  icon_only: false,
  href: nil,
  size: :md,
  variant: :muted,
  **html_options
)
  @text = text.presence
  @icon = icon.to_s.presence
  @icon_classes = Array.wrap(icon_classes)
  @icon_only = @icon && icon_only
  @href = href.presence
  @size = filter_attribute(size.to_sym, SIZE_OPTIONS, default: :md)
  @variant = filter_attribute(variant.to_sym, VARIANT_OPTIONS, default: :muted)
  @html_options = html_options
end