Class: IronAdmin::Ui::BadgeComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- IronAdmin::Ui::BadgeComponent
- Defined in:
- app/components/iron_admin/ui/badge_component.rb
Overview
Displays a colored badge/tag for status indicators and labels.
Constant Summary collapse
- COLORS =
Available color themes mapped to Tailwind classes.
{ green: "bg-green-100 text-green-800", red: "bg-red-100 text-red-800", yellow: "bg-yellow-100 text-yellow-800", blue: "bg-blue-100 text-blue-800", indigo: "bg-indigo-100 text-indigo-800", purple: "bg-purple-100 text-purple-800", pink: "bg-pink-100 text-pink-800", orange: "bg-orange-100 text-orange-800", teal: "bg-teal-100 text-teal-800", gray: "bg-gray-100 text-gray-800", }.freeze
- SIZES =
Available sizes mapped to Tailwind classes.
{ sm: "px-2 py-0.5 text-xs", md: "px-2.5 py-0.5 text-sm", lg: "px-3 py-1 text-sm", }.freeze
Instance Attribute Summary collapse
-
#color ⇒ Symbol
readonly
The color theme (:green, :red, :yellow, :blue, etc.).
-
#size ⇒ Symbol
readonly
The size (:sm, :md, :lg).
-
#text ⇒ String
readonly
The text displayed in the badge.
Instance Method Summary collapse
-
#call ⇒ String
Renders the badge span.
-
#color_classes ⇒ String
private
CSS color classes for badge.
-
#initialize(text:, color: :gray, size: :md) ⇒ BadgeComponent
constructor
A new instance of BadgeComponent.
-
#size_classes ⇒ String
private
CSS size classes for badge.
Constructor Details
#initialize(text:, color: :gray, size: :md) ⇒ BadgeComponent
Returns a new instance of BadgeComponent.
48 49 50 51 52 |
# File 'app/components/iron_admin/ui/badge_component.rb', line 48 def initialize(text:, color: :gray, size: :md) @text = text @color = color.to_sym @size = size.to_sym end |
Instance Attribute Details
#color ⇒ Symbol (readonly)
Returns The color theme (:green, :red, :yellow, :blue, etc.).
17 18 19 |
# File 'app/components/iron_admin/ui/badge_component.rb', line 17 def color @color end |
#size ⇒ Symbol (readonly)
Returns The size (:sm, :md, :lg).
20 21 22 |
# File 'app/components/iron_admin/ui/badge_component.rb', line 20 def size @size end |
#text ⇒ String (readonly)
Returns The text displayed in the badge.
14 15 16 |
# File 'app/components/iron_admin/ui/badge_component.rb', line 14 def text @text end |
Instance Method Details
#call ⇒ String
Renders the badge span.
68 69 70 |
# File 'app/components/iron_admin/ui/badge_component.rb', line 68 def call tag.span(text, class: "inline-flex items-center font-medium rounded-full #{color_classes} #{size_classes}") end |
#color_classes ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns CSS color classes for badge.
56 57 58 |
# File 'app/components/iron_admin/ui/badge_component.rb', line 56 def color_classes IronAdmin.configuration.badge_colors[@color] || COLORS[@color] || COLORS[:gray] end |
#size_classes ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns CSS size classes for badge.
62 63 64 |
# File 'app/components/iron_admin/ui/badge_component.rb', line 62 def size_classes SIZES[@size] || SIZES[:md] end |