colored_pill avec classes explicites pour JIT Tailwind

This commit is contained in:
Jérémy Lecour 2022-01-23 16:41:51 +01:00 committed by Jérémy Lecour
parent 7dba35c320
commit 17c08306b3
2 changed files with 14 additions and 4 deletions

View file

@ -5,8 +5,18 @@ module ApplicationHelper
options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
end
color = options.fetch(:color).presence || "gray"
classes = "px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-#{color}-100 text-#{color}-800"
color_classes = case options.fetch(:color)
when "red"
"bg-red-100 text-red-800"
when "green"
"bg-green-100 text-green-800"
when "orange"
"bg-orange-100 text-orange-800"
else
"bg-gray-100 text-gray-800"
end
classes = "px-2 inline-flex text-xs leading-5 font-semibold rounded-full #{color_classes}"
if block_given?
content_tag(:span, class: classes, &block)

View file

@ -55,14 +55,14 @@
<% if user.confirmed? %>
<%= colored_pill_tag("Confirmed", color: "green") %>
<% else %>
<%= colored_pill_tag("Unconfirmed", color: "yellow") %>
<%= colored_pill_tag("Unconfirmed", color: "orange") %>
<% end %>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<% if user.admin? %>
<%= colored_pill_tag("Yes", color: "green") %>
<% else %>
<%= colored_pill_tag("No", color: "yellow") %>
<%= colored_pill_tag("No", color: "gray") %>
<% end %>
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">