Class: Kanso::NotificationComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/kanso/notification_component.rb

Defined Under Namespace

Classes: Theme

Constant Summary collapse

THEMES =
{
  success: Theme.new(
    icon_name: "check-circle",
    icon_bg_classes: "bg-green-100",
    icon_color_classes: "text-green-600",
    title_text_classes: "text-green-800",
    body_text_classes: "text-green-700",
    aria_role: "status"
  ),
  error: Theme.new(
    icon_name: "x-circle",
    icon_bg_classes: "bg-red-100",
    icon_color_classes: "text-red-600",
    title_text_classes: "text-red-800",
    body_text_classes: "text-red-700",
    aria_role: "alert"
  ),
  warning: Theme.new(
    icon_name: "exclamation-triangle",
    icon_bg_classes: "bg-yellow-100",
    icon_color_classes: "text-yellow-600",
    title_text_classes: "text-yellow-800",
    body_text_classes: "text-yellow-700",
    aria_role: "alert"
  ),
  info: Theme.new(
    icon_name: "information-circle",
    icon_bg_classes: "bg-blue-100",
    icon_color_classes: "text-blue-600",
    title_text_classes: "text-blue-800",
    body_text_classes: "text-blue-700",
    aria_role: "status"
  )
}.freeze
RAILS_FLASH_ALIASES =
{
  notice: :success,
  alert: :error
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message:, title: nil, theme: :info) ⇒ NotificationComponent

Returns a new instance of NotificationComponent.



57
58
59
60
61
62
63
64
# File 'app/components/kanso/notification_component.rb', line 57

def initialize(message:, title: nil, theme: :info)
  @title = title
  @message = message

  theme_sym = theme.to_sym
  mapped_theme = RAILS_FLASH_ALIASES[theme_sym] || theme_sym
  @theme_data = THEMES[mapped_theme] || THEMES[:info]
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



55
56
57
# File 'app/components/kanso/notification_component.rb', line 55

def message
  @message
end

#theme_dataObject (readonly)

Returns the value of attribute theme_data.



55
56
57
# File 'app/components/kanso/notification_component.rb', line 55

def theme_data
  @theme_data
end

#titleObject (readonly)

Returns the value of attribute title.



55
56
57
# File 'app/components/kanso/notification_component.rb', line 55

def title
  @title
end