Class: IronAdmin::Ui::AlertComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- IronAdmin::Ui::AlertComponent
- Defined in:
- app/components/iron_admin/ui/alert_component.rb
Overview
Renders a styled alert/notification message.
Constant Summary collapse
- TYPES =
Type configurations with colors and icons.
{ success: { bg: "bg-green-50", border: "border-green-200", text: "text-green-800", icon: "check-circle", }, error: { bg: "bg-red-50", border: "border-red-200", text: "text-red-800", icon: "x-circle", }, warning: { bg: "bg-yellow-50", border: "border-yellow-200", text: "text-yellow-800", icon: "exclamation-triangle", }, info: { bg: "bg-blue-50", border: "border-blue-200", text: "text-blue-800", icon: "information-circle", }, }.freeze
Instance Attribute Summary collapse
-
#dismissible ⇒ Boolean
readonly
Whether alert can be dismissed.
-
#message ⇒ String?
readonly
The alert message.
-
#type ⇒ Symbol
readonly
Alert type (:success, :error, :warning, :info).
Instance Method Summary collapse
-
#alert_classes ⇒ String
private
CSS classes for alert container.
-
#icon_name ⇒ String
private
Heroicon name for alert type.
-
#initialize(message: nil, type: :info, dismissible: true) ⇒ AlertComponent
constructor
A new instance of AlertComponent.
-
#render? ⇒ Boolean
private
Whether to render the component.
-
#type_config ⇒ Hash
private
Configuration for the current alert type.
Constructor Details
#initialize(message: nil, type: :info, dismissible: true) ⇒ AlertComponent
Returns a new instance of AlertComponent.
60 61 62 63 64 |
# File 'app/components/iron_admin/ui/alert_component.rb', line 60 def initialize(message: nil, type: :info, dismissible: true) @message = @type = type.to_sym @dismissible = dismissible end |
Instance Attribute Details
#dismissible ⇒ Boolean (readonly)
Returns Whether alert can be dismissed.
26 27 28 |
# File 'app/components/iron_admin/ui/alert_component.rb', line 26 def dismissible @dismissible end |
#message ⇒ String? (readonly)
Returns The alert message.
20 21 22 |
# File 'app/components/iron_admin/ui/alert_component.rb', line 20 def @message end |
#type ⇒ Symbol (readonly)
Returns Alert type (:success, :error, :warning, :info).
23 24 25 |
# File 'app/components/iron_admin/ui/alert_component.rb', line 23 def type @type end |
Instance Method Details
#alert_classes ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns CSS classes for alert container.
74 75 76 |
# File 'app/components/iron_admin/ui/alert_component.rb', line 74 def alert_classes "#{type_config[:bg]} #{type_config[:border]} #{type_config[:text]} border rounded-lg p-4" end |
#icon_name ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Heroicon name for alert type.
80 81 82 |
# File 'app/components/iron_admin/ui/alert_component.rb', line 80 def icon_name type_config[:icon] end |
#render? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Whether to render the component.
86 87 88 |
# File 'app/components/iron_admin/ui/alert_component.rb', line 86 def render? .present? || content.present? end |
#type_config ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Configuration for the current alert type.
68 69 70 |
# File 'app/components/iron_admin/ui/alert_component.rb', line 68 def type_config TYPES[@type] || TYPES[:info] end |