From e5a4858774c03d2513f00d45aa7da30b8b374e86 Mon Sep 17 00:00:00 2001 From: Ryan Kulp Date: Thu, 28 Dec 2023 14:56:42 -0500 Subject: [PATCH] DRY flash to 1 element and load svg/classes dynamically --- app/helpers/application_helper.rb | 12 ++++++ app/views/shared/_flash.html.erb | 64 ++++++++++--------------------- 2 files changed, 32 insertions(+), 44 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6bb5d777..11430b7c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -28,4 +28,16 @@ def nav_link_classes(path = nil) defaults.gsub!('gray', 'black').gsub!('-medium', '-bold') if request.path == "/#{path}" defaults end + + def flash_classes + defaults = 'text-green-500 bg-green-100' + defaults.gsub!('green', 'red') if flash[:alert].present? + defaults + end + + def flash_icon + gpath = 'M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z' + gpath = 'M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z' if flash[:alert].present? + "" + end end diff --git a/app/views/shared/_flash.html.erb b/app/views/shared/_flash.html.erb index 0655a7d0..9b9beae0 100644 --- a/app/views/shared/_flash.html.erb +++ b/app/views/shared/_flash.html.erb @@ -1,51 +1,27 @@ -<% visibility = 'hidden' unless (flash[:alert].present? || flash[:notice].present?) %> +<% if notice || alert %> +
+
+
-
-
-
- <% if flash[:alert].present? %> - -
- - + +<% end %> \ No newline at end of file