Class: Charming::Components::Badge

Inherits:
Charming::Component show all
Defined in:
lib/charming/presentation/components/badge.rb

Overview

Badge is a small inline label rendered as a styled pill — useful for versions, counts, and statuses inside status bars, lists, and headers.

Badge.new("v1.2").render            # themed default
Badge.new("3 errors", style: theme.warn).render

Instance Method Summary collapse

Methods inherited from Charming::Component

#captures_text?

Methods inherited from View

#focused?, #layout_assigns

Constructor Details

#initialize(label, style: nil, theme: nil) ⇒ Badge

label is the badge text. style overrides the default themed style.



12
13
14
15
16
# File 'lib/charming/presentation/components/badge.rb', line 12

def initialize(label, style: nil, theme: nil)
  super(theme: theme)
  @label = label.to_s
  @badge_style = style
end

Instance Method Details

#renderObject

Renders the pill: a space-padded label with the badge style applied.



19
20
21
# File 'lib/charming/presentation/components/badge.rb', line 19

def render
  resolved_style.render(" #{@label} ")
end