Class: Shadcn::BadgeComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/shadcn/badge_component.rb

Overview

Badge component for labels and status indicators Matches shadcn/ui Badge component

Examples:

Basic badge

<%= render Shadcn::BadgeComponent.new { "New" } %>

Variant badges

<%= render Shadcn::BadgeComponent.new(variant: :secondary) { "Draft" } %>
<%= render Shadcn::BadgeComponent.new(variant: :destructive) { "Error" } %>
<%= render Shadcn::BadgeComponent.new(variant: :outline) { "v1.0.0" } %>

Constant Summary collapse

VARIANTS =

Available badge variants

{
  default: "border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",
  secondary: "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
  destructive: "border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
  outline: "text-foreground"
}.freeze
BASE_CLASSES =
"inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2"

Instance Attribute Summary

Attributes inherited from BaseComponent

#class_name, #data, #html_options

Instance Method Summary collapse

Methods inherited from BaseComponent

#content

Methods included from Rails::Helpers::ClassNameHelper

#cn

Constructor Details

#initialize(variant: :default, **options) ⇒ BadgeComponent

Returns a new instance of BadgeComponent.

Parameters:

  • variant (Symbol) (defaults to: :default)

    Badge style variant (:default, :secondary, :destructive, :outline)



27
28
29
30
# File 'app/components/shadcn/badge_component.rb', line 27

def initialize(variant: :default, **options)
  super(**options)
  @variant = variant.to_sym
end