Class: Panda::Core::UI::Badge

Inherits:
Base
  • Object
show all
Defined in:
app/components/panda/core/UI/badge.rb

Overview

Badge component for status indicators, labels, and counts.

Badges are small, inline elements that highlight an item's status or provide additional metadata at a glance.

Examples:

Basic badge

render Panda::Core::UI::Badge.new(text: "New")

Status badges

render Panda::Core::UI::Badge.new(text: "Active", variant: :success)
render Panda::Core::UI::Badge.new(text: "Pending", variant: :warning)
render Panda::Core::UI::Badge.new(text: "Error", variant: :danger)

With count

render Panda::Core::UI::Badge.new(text: "99+", variant: :primary, size: :small)

Removable badge

render Panda::Core::UI::Badge.new(
  text: "Tag",
  removable: true,
  data: { action: "click->tags#remove" }
)

Constant Summary

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, variant: :default, size: :medium, removable: false, rounded: false, **attrs) ⇒ Badge

Returns a new instance of Badge.



30
31
32
33
34
35
36
37
# File 'app/components/panda/core/UI/badge.rb', line 30

def initialize(text:, variant: :default, size: :medium, removable: false, rounded: false, **attrs)
  @text = text
  @variant = variant
  @size = size
  @removable = removable
  @rounded = rounded
  super(**attrs)
end

Instance Attribute Details

#removableObject (readonly)

Returns the value of attribute removable.



39
40
41
# File 'app/components/panda/core/UI/badge.rb', line 39

def removable
  @removable
end

#roundedObject (readonly)

Returns the value of attribute rounded.



39
40
41
# File 'app/components/panda/core/UI/badge.rb', line 39

def rounded
  @rounded
end

#sizeObject (readonly)

Returns the value of attribute size.



39
40
41
# File 'app/components/panda/core/UI/badge.rb', line 39

def size
  @size
end

#textObject (readonly)

Returns the value of attribute text.



39
40
41
# File 'app/components/panda/core/UI/badge.rb', line 39

def text
  @text
end

#variantObject (readonly)

Returns the value of attribute variant.



39
40
41
# File 'app/components/panda/core/UI/badge.rb', line 39

def variant
  @variant
end

Instance Method Details

#removable?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/components/panda/core/UI/badge.rb', line 41

def removable?
  removable
end