From d26d3f02ea68a9fedd2a0fe7cd3f248620019cbc Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Thu, 16 May 2024 01:09:47 +0000 Subject: [PATCH] Refactor --- .../tailwind/alert_component.html.erb | 19 +++---------------- app/components/tailwind/alert_component.rb | 6 ++++++ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/app/components/tailwind/alert_component.html.erb b/app/components/tailwind/alert_component.html.erb index 771524b59..979b35aca 100644 --- a/app/components/tailwind/alert_component.html.erb +++ b/app/components/tailwind/alert_component.html.erb @@ -1,19 +1,6 @@
- <% case @type %> - <% when :success %> -
- <%= render Tailwind::Icon.new(name: :tick) %> -
- <% when :congratulations %> -
- <%= render Tailwind::Icon.new(name: :clapping) %> -
- <% when :warning %> -
- <%= render Tailwind::Icon.new(name: :warning) %> -
- <% else %> - <% raise "Invalid value for type: #{type}" %> - <% end %> +
+ <%= render Tailwind::Icon.new(name: @icon_name) %> +
<%= content %>
diff --git a/app/components/tailwind/alert_component.rb b/app/components/tailwind/alert_component.rb index a7010d404..7cf744227 100644 --- a/app/components/tailwind/alert_component.rb +++ b/app/components/tailwind/alert_component.rb @@ -16,14 +16,20 @@ def initialize(type:) @bg_class = T.let("bg-lavender", String) @alignment_class = T.let("items-center", String) @padding_class = T.let("px-4 py-3", String) + @icon_name = T.let(:tick, Symbol) + @icon_class = T.let("text-light-lavender", String) when :congratulations @bg_class = T.let("bg-lavender", String) @alignment_class = T.let("items-start", String) @padding_class = T.let("px-8 py-8", String) + @icon_name = :clapping + @icon_class = "text-light-lavender" when :warning @bg_class = "bg-error-red" @alignment_class = T.let("items-center", String) @padding_class = T.let("px-4 py-3", String) + @icon_name = :warning + @icon_class = "text-white" else raise "Invalid value for type: #{type}" end