Class: Anchor::ButtonComponent

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

Constant Summary collapse

TYPE_DEFAULT =
:button
TYPE_OPTIONS =
[TYPE_DEFAULT, :reset, :submit].freeze
VARIANT_DEFAULT =
:basic
VARIANT_MAPPINGS =
{
  VARIANT_DEFAULT => "btn",
  :primary => "btn btn-primary",
  :critical => "btn btn-critical",
  :text => "btn btn-text",
}.freeze
VARIANT_OPTIONS =
VARIANT_MAPPINGS.keys
SIZE_DEFAULT =
nil
SIZE_MAPPINGS =
{
  small: "btn-small",
}.freeze
SIZE_OPTIONS =
SIZE_MAPPINGS.keys << SIZE_DEFAULT

Constants included from ViewHelper

ViewHelper::ANCHOR_HELPERS

Instance Method Summary collapse

Methods inherited from Component

generate_id

Methods included from ViewHelper

#anchor_form_with, #anchor_svg, #deep_blank?, #merge_options, #popover_trigger_attributes

Methods included from FetchOrFallbackHelper

#fetch_or_fallback

Constructor Details

#initialize(type: TYPE_DEFAULT, size: SIZE_DEFAULT, href: nil, disabled: false, full_width: false, **kwargs) ⇒ ButtonComponent

Returns a new instance of ButtonComponent.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/components/anchor/button_component.rb', line 37

def initialize(
  type: TYPE_DEFAULT,
  size: SIZE_DEFAULT,
  href: nil,
  disabled: false,
  full_width: false,
  **kwargs
)
  @type = fetch_or_fallback(TYPE_OPTIONS, type, TYPE_DEFAULT)
  @size = SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size,
    SIZE_DEFAULT)]
  @href = href
  @disabled = disabled
  @full_width = full_width

  super(**kwargs)
end