Class: ButtonComponent

Inherits:
Component show all
Includes:
Attachable, Sizeable
Defined in:
app/components/button_component.rb

Overview

Button — buttons in many styles.

Usage:

Button(color: :green, icon: "checkmark") { text "Approve" }
Button(variant: :primary, size: :large, fluid: true) { text "Submit" }
Button(href: "/path", variant: :primary) { text "Go" }

Constant Summary

Constants inherited from Component

Component::HTML_OPTIONS

Instance Method Summary collapse

Methods inherited from Component

default, #initialize, #render_in, slot

Constructor Details

This class inherits a constructor from Component

Instance Method Details

#to_sObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/components/button_component.rb', line 26

def to_s
  classes = class_names(
    "ui",
    color,
    size,
    variant,
    animated && "animated #{animated unless animated == 'true'}".strip,
    { "fluid" => fluid, "disabled" => disabled, "loading" => loading,
      "inverted" => inverted, "attached" => attached,
      "labeled icon" => labeled && icon,
      "icon" => icon && !labeled && !@content },
    "button"
  )

  icon_el = icon ? tag.i(class: "#{icon} icon") : nil
  content = safe_join([ icon_el, @content ])

  opts = merge_html_options(class: classes)

  if href
    tag.a(**opts, href: href) { content }
  else
    tag.button(**opts, type: type) { content }
  end
end