Class: Keystone::Ui::AlertComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/keystone/ui/alert_component.rb

Constant Summary collapse

BASE_CLASSES =
"rounded-md p-4"
TYPE_CLASSES =
{
  success: "bg-green-50 text-green-800 dark:bg-green-900/30 dark:text-green-300",
  warning: "bg-yellow-50 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300",
  error: "bg-red-50 text-red-800 dark:bg-red-900/30 dark:text-red-300"
}.freeze
OUTER_CLASSES =
"flex"
INNER_CLASSES =
"flex-1"
TITLE_CLASSES =
"font-semibold"
MESSAGE_CLASSES =
"text-sm"
MESSAGE_WITH_TITLE_CLASSES =
"text-sm mt-1"
DISMISS_CLASSES =
"ml-auto -mr-1.5 -mt-1.5 inline-flex rounded-md p-1.5 focus:outline-none focus:ring-2 focus:ring-offset-2 cursor-pointer"

Instance Method Summary collapse

Constructor Details

#initialize(message:, type: :info, title: nil, dismissible: false) ⇒ AlertComponent

Returns a new instance of AlertComponent.



21
22
23
24
25
26
# File 'app/components/keystone/ui/alert_component.rb', line 21

def initialize(message:, type: :info, title: nil, dismissible: false)
  @message = message
  @type = type
  @title = title
  @dismissible = dismissible
end

Instance Method Details

#classesObject



28
29
30
31
32
33
34
35
# File 'app/components/keystone/ui/alert_component.rb', line 28

def classes
  type_css = if @type == :info
    "bg-accent-50 text-accent-800 dark:bg-accent-900/30 dark:text-accent-300"
  else
    TYPE_CLASSES.fetch(@type)
  end
  "#{BASE_CLASSES} #{type_css}"
end

#dismissible?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/components/keystone/ui/alert_component.rb', line 49

def dismissible?
  @dismissible
end

#message_textObject



37
38
39
# File 'app/components/keystone/ui/alert_component.rb', line 37

def message_text
  @message
end

#title?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/components/keystone/ui/alert_component.rb', line 41

def title?
  !@title.nil?
end

#title_textObject



45
46
47
# File 'app/components/keystone/ui/alert_component.rb', line 45

def title_text
  @title
end

#wrapper_dataObject



53
54
55
# File 'app/components/keystone/ui/alert_component.rb', line 53

def wrapper_data
  dismissible? ? { controller: "dismiss" } : {}
end