Class: Kanso::ButtonComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ClassCombinable
Defined in:
app/components/kanso/button_component.rb

Constant Summary collapse

THEME_CLASSES =
{
  primary: "bg-indigo-500 text-white hover:bg-indigo-600 active:bg-indigo-700",
  danger:  "bg-red-600 text-white hover:bg-red-700 active:bg-red-800",
  default: "bg-white text-indigo-600 border border-indigo-600 focus:ring-indigo-500/50 hover:bg-indigo-50 hover:border-indigo-700 active:bg-indigo-700 active:text-white"
}.freeze

Instance Method Summary collapse

Methods included from ClassCombinable

#combine_classes

Constructor Details

#initialize(theme: :default, tag: :button, url: nil, method: nil, **options) ⇒ ButtonComponent

Returns a new instance of ButtonComponent.



13
14
15
16
17
18
19
# File 'app/components/kanso/button_component.rb', line 13

def initialize(theme: :default, tag: :button, url: nil, method: nil, **options)
  @theme = theme
  @tag = tag
  @url = url
  @method = method
  @options = options
end

Instance Method Details

#callObject



21
22
23
24
25
26
27
28
29
# File 'app/components/kanso/button_component.rb', line 21

def call
  if @url
    button_to(@url, method: @method, **html_options) do
      content
    end
  else
    (@tag, content, html_options)
  end
end