Class: IgnitionKit::Button

Inherits:
Component show all
Defined in:
app/lib/ignition_kit/button.rb

Constant Summary collapse

BASE =
[
  [
    "inline-flex items-center justify-center rounded-md border",
    "focus:outline-none focus:ring-[3px] focus:ring-ring"
  ]
].flatten.freeze
VARIANTS =
{
  default: ["bg-background text-foreground border-border border-b-zinc-300"],
  primary: ["bg-primary text-white border-primary"],
  destructive: ["bg-destructive text-white border-destructive"],
  ghost: ["bg-transparent text-foreground border-transparent"]
}.freeze
SIZES =
{
  base: "px-4 py-1.5 font-medium"
}

Instance Method Summary collapse

Methods inherited from Component

#tw

Constructor Details

#initialize(text = nil, variant: :default, size: :base, href: nil, **options) ⇒ Button

Returns a new instance of Button.



21
22
23
24
25
26
# File 'app/lib/ignition_kit/button.rb', line 21

def initialize(text = nil, variant: :default, size: :base, href: nil, **options)
  super(**options)
  @text = text || yield
  @href = href
  @classes = tw.merge([BASE, VARIANTS[variant], SIZES[size], options[:class]])
end

Instance Method Details

#renderObject



28
29
30
31
32
33
34
35
36
37
38
# File 'app/lib/ignition_kit/button.rb', line 28

def render
  if @href
    tag.a(href: @href, class: @classes) do
      tag.span(@text)
    end
  else
    tag.button(type: "button", class: @classes) do
      tag.span(@text)
    end
  end
end