Class: NitroKit::Badge

Inherits:
Component
  • Object
show all
Defined in:
app/components/nitro_kit/badge.rb

Constant Summary collapse

BADGE =
"inline-flex items-center gap-x-1.5 rounded-md font-medium"
VARIANTS =
{
  default: "border border-transparent bg-zinc-200 text-zinc-700 dark:bg-zinc-800 dark:text-zinc-300",
  outline: "border"
}
SIZES =
{
  sm: "text-xs px-1.5 py-0.5",
  md: "text-sm px-2 py-0.5"
}

Instance Attribute Summary collapse

Attributes inherited from Component

#attrs

Instance Method Summary collapse

Methods inherited from Component

#data_merge, merge, #merge

Constructor Details

#initialize(variant: :default, size: :md, **attrs) ⇒ Badge

Returns a new instance of Badge.



15
16
17
18
19
20
# File 'app/components/nitro_kit/badge.rb', line 15

def initialize(variant: :default, size: :md, **attrs)
  super(**attrs)

  @variant = variant
  @size = size
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



22
23
24
# File 'app/components/nitro_kit/badge.rb', line 22

def size
  @size
end

#variantObject (readonly)

Returns the value of attribute variant.



22
23
24
# File 'app/components/nitro_kit/badge.rb', line 22

def variant
  @variant
end

Instance Method Details

#view_templateObject



24
25
26
27
28
29
# File 'app/components/nitro_kit/badge.rb', line 24

def view_template
  span(
    **attrs,
    class: merge(BADGE, VARIANTS[variant], SIZES[size], attrs[:class])
  ) { yield }
end