Class: Railsboot::ButtonComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/railsboot/button_component.rb

Constant Summary collapse

TAGS =
["button", "a", "input"].freeze
DEFAULT_TAG =
"button".freeze
VARIANTS =
(COLORS + ["link"]).freeze
DEFAULT_VARIANT =
DEFAULT_COLOR
SIZES =
["", "lg", "sm"].freeze
DEFAULT_SIZE =
"".freeze

Constants inherited from Component

Component::COLORS, Component::DEFAULT_COLOR

Instance Method Summary collapse

Constructor Details

#initialize(text: "", href: "", tag: DEFAULT_TAG, variant: DEFAULT_VARIANT, size: DEFAULT_SIZE, outline: false, form: nil, **html_attributes) ⇒ ButtonComponent

Returns a new instance of ButtonComponent.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/components/railsboot/button_component.rb', line 11

def initialize(text: "", href: "", tag: DEFAULT_TAG, variant: DEFAULT_VARIANT, size: DEFAULT_SIZE, outline: false, form: nil, **html_attributes)
  @tag = fetch_or_raise(tag, TAGS)
  @text = text
  @href = href
  @variant = fetch_or_raise(variant, VARIANTS)
  @outline = outline
  @size = fetch_or_fallback(size, SIZES, DEFAULT_SIZE)
  @form = form
  @html_attributes = html_attributes

  @html_attributes[:class] = class_names(
    "btn",
    ["btn", ("outline" if @outline), @variant].compact_blank.join("-"),
    {"btn-#{@size}" => @size.present?},
    html_attributes.delete(:class)
  )
end

Instance Method Details

#button?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/components/railsboot/button_component.rb', line 29

def button?
  @tag == "button"
end

#input?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/components/railsboot/button_component.rb', line 37

def input?
  @tag == "input"
end

#link?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/components/railsboot/button_component.rb', line 33

def link?
  @tag == "a"
end