Class: NitroKit::Button

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

Constant Summary collapse

VARIANTS =
%i[default primary destructive ghost]

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, href: nil, variant: :default, size: :md, icon: nil, icon_right: nil, **attrs) ⇒ Button

Returns a new instance of Button.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/components/nitro_kit/button.rb', line 7

def initialize(
  text = nil,
  href: nil,
  variant: :default,
  size: :md,
  icon: nil,
  icon_right: nil,
  **attrs
)
  @text = text
  @href = href
  @icon = icon
  @icon_right = icon_right
  @size = size
  @variant = variant

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

Instance Attribute Details

#hrefObject (readonly)

Returns the value of attribute href.



33
34
35
# File 'app/components/nitro_kit/button.rb', line 33

def href
  @href
end

#iconObject (readonly)

Returns the value of attribute icon.



33
34
35
# File 'app/components/nitro_kit/button.rb', line 33

def icon
  @icon
end

#icon_rightObject (readonly)

Returns the value of attribute icon_right.



33
34
35
# File 'app/components/nitro_kit/button.rb', line 33

def icon_right
  @icon_right
end

#sizeObject (readonly)

Returns the value of attribute size.



33
34
35
# File 'app/components/nitro_kit/button.rb', line 33

def size
  @size
end

#textObject (readonly)

Returns the value of attribute text.



33
34
35
# File 'app/components/nitro_kit/button.rb', line 33

def text
  @text
end

#variantObject (readonly)

Returns the value of attribute variant.



33
34
35
# File 'app/components/nitro_kit/button.rb', line 33

def variant
  @variant
end

Instance Method Details

#view_template(&block) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'app/components/nitro_kit/button.rb', line 42

def view_template(&block)
  if href
    a(href:, **attrs) do
      contents(&block)
    end
  else
    button(type: :button, **attrs) do
      contents(&block)
    end
  end
end