Class: Essence::StatusComponent

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

Constant Summary collapse

DEFAULT_VARIANT =
:outline
VARIANT_MAPPINGS =
{
  DEFAULT_VARIANT => 'status-outline',
  :todo => 'status-todo',
  :active => 'status-active',
  :danger => 'status-danger'
}.freeze
VARIANT_OPTIONS =
VARIANT_MAPPINGS.keys.freeze
DEFAULT_BUBBLE =
nil
BUBBLE_MAPPINGS =
{
  DEFAULT_BUBBLE => '',
  :dotted => 'status-bubble-dotted',
  :outline => 'status-bubble-outline',
  :solid => 'status-bubble-solid'
}.freeze
BUBBLE_OPTIONS =
BUBBLE_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(text:, variant: DEFAULT_VARIANT, bubble: DEFAULT_BUBBLE, **html_options) ⇒ StatusComponent

Returns a new instance of StatusComponent.



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

def initialize(text:,
               variant: DEFAULT_VARIANT,
               bubble: DEFAULT_BUBBLE,
               **html_options)
  @text         = text&.to_s&.strip&.presence&.downcase
  @variant      = fetch_or_fallback(VARIANT_OPTIONS, variant.to_sym, DEFAULT_VARIANT)
  @bubble       = fetch_or_fallback(BUBBLE_OPTIONS, bubble&.to_sym, DEFAULT_BUBBLE)
  @html_options = html_options
end

Instance Attribute Details

#bubbleObject (readonly)

Returns the value of attribute bubble.



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

def bubble
  @bubble
end

#html_optionsObject (readonly)

Returns the value of attribute html_options.



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

def html_options
  @html_options
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end