Class: Panda::Core::Admin::FlashMessageComponent
- Defined in:
- app/components/panda/core/admin/flash_message_component.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#subtitle ⇒ Object
readonly
Returns the value of attribute subtitle.
-
#temporary ⇒ Object
readonly
Returns the value of attribute temporary.
Instance Method Summary collapse
- #icon_colour_css ⇒ Object
- #icon_css ⇒ Object
-
#initialize(message: "", kind: :default, temporary: true, subtitle: nil, **attrs) ⇒ FlashMessageComponent
constructor
A new instance of FlashMessageComponent.
- #notification_attrs ⇒ Object
- #render_close_button ⇒ Object
- #render_content ⇒ Object
- #render_icon ⇒ Object
- #tone_classes ⇒ Object
Constructor Details
#initialize(message: "", kind: :default, temporary: true, subtitle: nil, **attrs) ⇒ FlashMessageComponent
Returns a new instance of FlashMessageComponent.
7 8 9 10 11 12 13 |
# File 'app/components/panda/core/admin/flash_message_component.rb', line 7 def initialize(message: "", kind: :default, temporary: true, subtitle: nil, **attrs) @message = @kind = kind @temporary = temporary @subtitle = subtitle super(**attrs) end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
15 16 17 |
# File 'app/components/panda/core/admin/flash_message_component.rb', line 15 def kind @kind end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
15 16 17 |
# File 'app/components/panda/core/admin/flash_message_component.rb', line 15 def @message end |
#subtitle ⇒ Object (readonly)
Returns the value of attribute subtitle.
15 16 17 |
# File 'app/components/panda/core/admin/flash_message_component.rb', line 15 def subtitle @subtitle end |
#temporary ⇒ Object (readonly)
Returns the value of attribute temporary.
15 16 17 |
# File 'app/components/panda/core/admin/flash_message_component.rb', line 15 def temporary @temporary end |
Instance Method Details
#icon_colour_css ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/components/panda/core/admin/flash_message_component.rb', line 56 def icon_colour_css case @kind when :success "text-emerald-600" when :alert, :error "text-rose-600" when :warning "text-amber-600" when :info, :notice "text-sky-600" else "text-gray-500" end end |
#icon_css ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/components/panda/core/admin/flash_message_component.rb', line 86 def icon_css case @kind when :success "fa-circle-check" when :alert, :error "fa-circle-xmark" when :warning "fa-triangle-exclamation" when :info, :notice "fa-circle-info" else "fa-circle-info" end end |
#notification_attrs ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'app/components/panda/core/admin/flash_message_component.rb', line 17 def notification_attrs { class: "pointer-events-auto w-full max-w-md translate-y-0 transform rounded-2xl border px-4 py-3 shadow-lg transition duration-300 ease-out sm:translate-x-0 starting:translate-y-2 starting:opacity-0 starting:sm:translate-x-2 starting:sm:translate-y-0 #{tone_classes}", data: { controller: "alert", alert_dismiss_after_value: (@temporary ? "5000" : nil) }.compact } end |
#render_close_button ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'app/components/panda/core/admin/flash_message_component.rb', line 45 def content_tag(:div, class: "ml-4 flex shrink-0") do content_tag(:button, type: "button", class: "inline-flex items-center cursor-pointer opacity-60 hover:opacity-100", data: {action: "alert#close"}) do content_tag(:i, "", class: "fa-solid fa-xmark") end end end |
#render_content ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/components/panda/core/admin/flash_message_component.rb', line 33 def render_content content_tag(:div, class: "ml-2 w-0 flex-1") do = content_tag(:p, @message, class: "text-sm font-medium flash-message-title") subtitle_html = if @subtitle content_tag(:p, @subtitle, class: "mt-1 text-xs opacity-80 flash-message-subtitle") else "".html_safe end ( + subtitle_html).html_safe end end |
#render_icon ⇒ Object
27 28 29 30 31 |
# File 'app/components/panda/core/admin/flash_message_component.rb', line 27 def render_icon content_tag(:div, class: "shrink-0") do content_tag(:i, "", class: "fa-solid size-5 #{icon_css} #{icon_colour_css}") end end |
#tone_classes ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/components/panda/core/admin/flash_message_component.rb', line 71 def tone_classes case @kind when :success "bg-emerald-50 text-emerald-700 border-emerald-200" when :alert, :error "bg-rose-50 text-rose-700 border-rose-200" when :warning "bg-amber-50 text-amber-700 border-amber-200" when :info, :notice "bg-sky-50 text-sky-700 border-sky-200" else "bg-white text-gray-700 border-gray-200" end end |