Class: EasyAdmin::NotificationComponent

Inherits:
Phlex::HTML
  • Object
show all
Defined in:
app/components/easy_admin/notification_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(type:, message:, title: nil, duration: 4000) ⇒ NotificationComponent

Returns a new instance of NotificationComponent.



3
4
5
6
7
8
# File 'app/components/easy_admin/notification_component.rb', line 3

def initialize(type:, message:, title: nil, duration: 4000)
  @type = type
  @message = message
  @title = title
  @duration = duration
end

Instance Method Details

#view_templateObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/components/easy_admin/notification_component.rb', line 10

def view_template
  unsafe_raw("<turbo-frame id=\"notifications\">")
  div(
    class: "fixed top-4 right-4 max-w-sm w-full bg-white shadow-lg rounded-lg pointer-events-auto ring-1 ring-black ring-opacity-5 transform translate-x-full opacity-0 transition-all duration-300 ease-in-out z-50",
    data: {
      controller: "notification",
      notification_type_value: @type,
      notification_message_value: @message,
      notification_duration_value: @duration
    }
  ) do
    div(class: "p-4") do
      div(class: "flex items-start") do
        div(class: "flex-shrink-0") do
          render_icon
        end
        
        div(class: "ml-3 w-0 flex-1") do
          if @title
            p(class: "text-sm font-medium text-gray-900") { @title }
          end
          
          p(class: notification_text_classes) { @message }
        end
        
        div(class: "ml-4 flex-shrink-0 flex") do
          button(
            type: "button",
            class: "bg-white rounded-md inline-flex text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500",
            data: { action: "click->notification#close" }
          ) do
            span(class: "sr-only") { "Close" }
            unsafe_raw('<svg class="h-5 w-5" fill="currentColor" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"/></svg>')
          end
        end
      end
    end
  end
  unsafe_raw("</turbo-frame>")
end