Class: Essence::ButtonComponent

Inherits:
ApplicationComponent show all
Defined in:
app/components/essence/button_component.rb

Constant Summary collapse

DEFAULT_DISPLAY_AS =
:button
DEFAULT_VARIANT =
:primary
BUTTON_MAPPINGS =
{
  DEFAULT_DISPLAY_AS => {
    DEFAULT_VARIANT => 'button-primary',
    secondary: 'button-secondary',
    danger: 'button-danger',
    outline: 'button-outline'
  }
}.freeze
VARIANT_MAPPINGS =
BUTTON_MAPPINGS.merge(LinkComponent::LINK_MAPPINGS).freeze
DISPLAY_AS_OPTIONS =
VARIANT_MAPPINGS.keys.freeze

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationComponent

#assets_path, assets_path, images_directory

Methods included from Utils

#get_directory_file_names

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #integer_or_fallback

Constructor Details

#initialize(name:, url: nil, variant: DEFAULT_VARIANT, display_as: DEFAULT_DISPLAY_AS, **html_options) ⇒ ButtonComponent

Returns a new instance of ButtonComponent.



30
31
32
33
34
35
36
37
38
39
40
# File 'app/components/essence/button_component.rb', line 30

def initialize(name:,
               url: nil,
               variant: DEFAULT_VARIANT,
               display_as: DEFAULT_DISPLAY_AS,
               **html_options)
  @name         = name
  @url          = url
  @variant      = fetch_or_fallback(VARIANT_MAPPINGS[display_as.to_sym].keys, variant.to_sym, DEFAULT_VARIANT)
  @display_as   = fetch_or_fallback(DISPLAY_AS_OPTIONS, display_as.to_sym, DEFAULT_DISPLAY_AS)
  @html_options = html_options
end

Instance Attribute Details

#html_optionsObject (readonly)

Returns the value of attribute html_options.



5
6
7
# File 'app/components/essence/button_component.rb', line 5

def html_options
  @html_options
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'app/components/essence/button_component.rb', line 5

def name
  @name
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'app/components/essence/button_component.rb', line 5

def url
  @url
end