Class: Anchor::ButtonComponent
- Defined in:
- app/components/anchor/button_component.rb
Constant Summary collapse
- TAG_DEFAULT =
:button- TAG_OPTIONS =
[TAG_DEFAULT, :a].freeze
- 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
Instance Method Summary collapse
-
#initialize(tag: TAG_DEFAULT, type: TYPE_DEFAULT, href: nil, size: SIZE_DEFAULT, variant: VARIANT_DEFAULT, data: {}, form: nil, popovertarget: nil, popovertargetaction: nil, **kwargs) ⇒ ButtonComponent
constructor
A new instance of ButtonComponent.
Methods inherited from Component
Methods included from ViewHelper
Methods included from FetchOrFallbackHelper
Constructor Details
#initialize(tag: TAG_DEFAULT, type: TYPE_DEFAULT, href: nil, size: SIZE_DEFAULT, variant: VARIANT_DEFAULT, data: {}, form: nil, popovertarget: nil, popovertargetaction: nil, **kwargs) ⇒ ButtonComponent
Returns a new instance of ButtonComponent.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/components/anchor/button_component.rb', line 39 def initialize( tag: TAG_DEFAULT, type: TYPE_DEFAULT, href: nil, size: SIZE_DEFAULT, variant: VARIANT_DEFAULT, data: {}, form: nil, popovertarget: nil, popovertargetaction: nil, **kwargs ) @tag = fetch_or_fallback(TAG_OPTIONS, tag, TAG_DEFAULT) if @tag == :button @type = fetch_or_fallback( TYPE_OPTIONS, type, TYPE_DEFAULT ) end @data = data @href = href if @tag == :a @size = SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)] @variant = VARIANT_MAPPINGS[ fetch_or_fallback(VARIANT_OPTIONS, variant, VARIANT_DEFAULT) ] @form = form @popovertarget = popovertarget @popovertargetaction = popovertargetaction super end |