Class: IronAdmin::Ui::AlertComponent

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

Overview

Renders a styled alert/notification message.

Examples:

Success alert

render IronAdmin::Ui::AlertComponent.new(
  message: "Record saved successfully",
  type: :success
)

Error alert

render IronAdmin::Ui::AlertComponent.new(
  message: "Something went wrong",
  type: :error
)

Constant Summary collapse

TYPES =

Type configurations with colors and icons.

Returns:

  • (Hash{Symbol => Hash})
{
  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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of AlertComponent.

Parameters:

  • message (String, nil) (defaults to: nil)

    Alert message

  • type (Symbol) (defaults to: :info)

    Alert type (default: :info)

  • dismissible (Boolean) (defaults to: true)

    Can be dismissed (default: true)



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 = message
  @type = type.to_sym
  @dismissible = dismissible
end

Instance Attribute Details

#dismissibleBoolean (readonly)

Returns Whether alert can be dismissed.

Returns:

  • (Boolean)

    Whether alert can be dismissed



26
27
28
# File 'app/components/iron_admin/ui/alert_component.rb', line 26

def dismissible
  @dismissible
end

#messageString? (readonly)

Returns The alert message.

Returns:

  • (String, nil)

    The alert message



20
21
22
# File 'app/components/iron_admin/ui/alert_component.rb', line 20

def message
  @message
end

#typeSymbol (readonly)

Returns Alert type (:success, :error, :warning, :info).

Returns:

  • (Symbol)

    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_classesString

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.

Returns:

  • (String)

    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_nameString

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.

Returns:

  • (String)

    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.

Returns:

  • (Boolean)

    Whether to render the component



86
87
88
# File 'app/components/iron_admin/ui/alert_component.rb', line 86

def render?
  message.present? || content.present?
end

#type_configHash

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.

Returns:

  • (Hash)

    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