Class: NitroKit::Badge

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

Constant Summary collapse

VARIANTS =
%i[default outline]

Instance Attribute Summary collapse

Attributes inherited from Component

#attrs

Instance Method Summary collapse

Methods inherited from Component

#builder, from_template

Constructor Details

#initialize(text = nil, variant: :default, size: :md, color: :gray, **attrs) ⇒ Badge

Returns a new instance of Badge.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/components/nitro_kit/badge.rb', line 7

def initialize(text = nil, variant: :default, size: :md, color: :gray, **attrs)
  @text = text
  @variant = variant
  @size = size
  @color = color

  super(
    attrs,
    class: [
      base_class,
      variant_class,
      size_class
    ]
  )
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



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

def color
  @color
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

#variantObject (readonly)

Returns the value of attribute variant.



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

def variant
  @variant
end

Instance Method Details

#view_template(&block) ⇒ Object



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

def view_template(&block)
  span(**attrs) do
    text_or_block(text, &block)
  end
end