app/components/avo/fields/common/badge_viewer_component.html.erb in avo-3.0.0.pre19 vs app/components/avo/fields/common/badge_viewer_component.html.erb in avo-3.0.1.beta1

- old
+ new

@@ -1,23 +1,46 @@ -<span class="<%= classes %>" style="max-width: 120px;"><%= @value %></span> +<% + backgrounds = { + info: 'bg-blue-500', + success: 'bg-green-500', + danger: 'bg-red-500', + warning: 'bg-yellow-500', + } + + label = @value + background = :info + + @options.invert.each do |values, type| + if [values].flatten.map { |value| value }.include? @value + label = @value + background = type.to_sym + next + end + end + + classes = 'whitespace-nowrap rounded-md uppercase px-2 py-1 text-xs font-bold block text-center truncate ' + + classes += "#{backgrounds[background]} text-white" if backgrounds[background].present? +%> +<span class="<%= classes %>" style="max-width: 120px;"><%= label %></span>