Class: Essence::ButtonComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Essence::ButtonComponent
- 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
-
#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.
Instance Method Summary collapse
-
#initialize(name:, url: nil, variant: DEFAULT_VARIANT, display_as: DEFAULT_DISPLAY_AS, **html_options) ⇒ ButtonComponent
constructor
A new instance of ButtonComponent.
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) ⇒ 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, **) @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/button_component.rb', line 5 def @html_options end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'app/components/essence/button_component.rb', line 5 def name @name end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'app/components/essence/button_component.rb', line 5 def url @url end |