Class: Essence::LinkComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Essence::LinkComponent
- Defined in:
- app/components/essence/link_component.rb
Constant Summary collapse
- DEFAULT_DISPLAY_AS =
:link
- DEFAULT_VARIANT =
:primary
- LINK_MAPPINGS =
{ 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
-
#html_options ⇒ Object
readonly
Returns the value of attribute html_options.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Instance Method Summary collapse
-
#initialize(name:, url: nil, variant: DEFAULT_VARIANT, display_as: DEFAULT_DISPLAY_AS, **html_options) ⇒ LinkComponent
constructor
A new instance of LinkComponent.
Methods inherited from ApplicationComponent
#assets_path, assets_path, images_directory
Methods included from Utils
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, **) @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 = end |
Instance Attribute Details
#html_options ⇒ Object (readonly)
Returns the value of attribute html_options.
5 6 7 |
# File 'app/components/essence/link_component.rb', line 5 def @html_options end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'app/components/essence/link_component.rb', line 5 def name @name end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'app/components/essence/link_component.rb', line 5 def url @url end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
5 6 7 |
# File 'app/components/essence/link_component.rb', line 5 def variant @variant end |