Class: Anchor::ToastComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/anchor/toast_component.rb

Constant Summary collapse

VARIANT_DEFAULT =
:notice
VARIANT_MAPPINGS =
{
  VARIANT_DEFAULT => "bg-gray-900 text-white",
  :success => "bg-green-700 text-white",
  :error => "bg-red-700 text-white",
  # TODO: Figma doesn’t provide a yellow ‘alert’ style
  :alert => "bg-yellow-600 text-white",
}.freeze
VARIANT_OPTIONS =
VARIANT_MAPPINGS.keys

Instance Method Summary collapse

Methods inherited from Component

generate_id

Methods included from ViewHelper

#text_prose

Methods included from FetchOrFallbackHelper

#fetch_or_fallback

Constructor Details

#initialize(variant: VARIANT_DEFAULT) ⇒ ToastComponent

Returns a new instance of ToastComponent.



17
18
19
20
21
22
23
24
# File 'app/components/anchor/toast_component.rb', line 17

def initialize(variant: VARIANT_DEFAULT)
  @variant = VARIANT_MAPPINGS[
    fetch_or_fallback(VARIANT_OPTIONS, variant, VARIANT_DEFAULT)
  ]
  @id = self.class.generate_id

  super
end