Class: Essence::LinkComponent

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

Constant Summary collapse

DEFAULT_DISPLAY_AS =
:link
DEFAULT_VARIANT =
:primary
{
  DEFAULT_DISPLAY_AS => {
    DEFAULT_VARIANT => 'link-primary',
    secondary: 'link-secondary',
    danger: 'link-danger'
  }
}.freeze
VARIANT_MAPPINGS =
LINK_MAPPINGS.merge(ButtonComponent::BUTTON_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) ⇒ LinkComponent

Returns a new instance of LinkComponent.



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

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/link_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/link_component.rb', line 5

def name
  @name
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

#variantObject (readonly)

Returns the value of attribute variant.



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

def variant
  @variant
end