Class: Keystone::Ui::AlertComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Keystone::Ui::AlertComponent
- 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
- #classes ⇒ Object
- #dismissible? ⇒ Boolean
-
#initialize(message:, type: :info, title: nil, dismissible: false) ⇒ AlertComponent
constructor
A new instance of AlertComponent.
- #message_text ⇒ Object
- #title? ⇒ Boolean
- #title_text ⇒ Object
- #wrapper_data ⇒ Object
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 = @type = type @title = title @dismissible = dismissible end |
Instance Method Details
#classes ⇒ Object
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
49 50 51 |
# File 'app/components/keystone/ui/alert_component.rb', line 49 def dismissible? @dismissible end |
#message_text ⇒ Object
37 38 39 |
# File 'app/components/keystone/ui/alert_component.rb', line 37 def @message end |
#title? ⇒ Boolean
41 42 43 |
# File 'app/components/keystone/ui/alert_component.rb', line 41 def title? !@title.nil? end |
#title_text ⇒ Object
45 46 47 |
# File 'app/components/keystone/ui/alert_component.rb', line 45 def title_text @title end |
#wrapper_data ⇒ Object
53 54 55 |
# File 'app/components/keystone/ui/alert_component.rb', line 53 def wrapper_data dismissible? ? { controller: "dismiss" } : {} end |