Class: Railsboot::ButtonComponent
- Defined in:
- app/components/railsboot/button_component.rb
Direct Known Subclasses
Railsboot::Button::ButtonComponent, Railsboot::Button::InputComponent, Railsboot::Button::LinkComponent
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
- #button? ⇒ Boolean
-
#initialize(text: "", href: "", tag: DEFAULT_TAG, variant: DEFAULT_VARIANT, size: DEFAULT_SIZE, outline: false, form: nil, **html_attributes) ⇒ ButtonComponent
constructor
A new instance of ButtonComponent.
- #input? ⇒ Boolean
- #link? ⇒ Boolean
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
29 30 31 |
# File 'app/components/railsboot/button_component.rb', line 29 def @tag == "button" end |
#input? ⇒ Boolean
37 38 39 |
# File 'app/components/railsboot/button_component.rb', line 37 def input? @tag == "input" end |
#link? ⇒ Boolean
33 34 35 |
# File 'app/components/railsboot/button_component.rb', line 33 def link? @tag == "a" end |