Files
ubicloud/views/components/form/radio_small_cards.erb
Jeremy Evans becfda63a2 Cover radio_small_cards view
The only caller of this is the resource_creation_form, which only passes
4 locals, so make those 4 locals required, and remove other locals.

As description isn't used, remove the branch for it.

Add a test for an error display.

After changes:

Line Coverage: 99.85% (11705 / 11722)
Branch Coverage: 98.44% (3095 / 3144)
2025-01-14 09:04:22 -08:00

45 lines
1.9 KiB
Plaintext

<%# locals: (name:, label:, options:, attributes:) %>
<% selected = flash.dig("old", name) || selected
error = flash.dig("errors", name)
is_content_array = options[0][1].is_a?(Array) %>
<div class="space-y-2">
<label class="text-sm font-medium leading-6 text-gray-900"><%= label %></label>
<fieldset class="radio-small-cards">
<legend class="sr-only"><%= label %></legend>
<% grid_cols = is_content_array ? "md:grid-cols-2 xl:grid-cols-3" : "sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4" %>
<div class="grid gap-3 grid-cols-1 <%= grid_cols %>">
<% options.each_with_index do |(opt_val, opt_text, opt_classes, opt_attrs), idx| %>
<label class="<%= opt_classes %>">
<input
type="radio"
name="<%= name %>"
value="<%= opt_val %>"
class="peer sr-only"
<% attributes.merge(opt_attrs || {}).each do |atr_key, atr_value| %>
<%= atr_key %>="<%= atr_value %>"
<% end%>
>
<% if is_content_array %>
<span class="radio-small-card justify-between p-4">
<span class="flex flex-col">
<span class="text-md font-semibold"><%= opt_text[0] %></span>
<span class="text-sm opacity-80"><span class="block sm:inline"><%= opt_text[1] %></span></span>
</span>
<span class="mt-2 flex text-sm sm:ml-4 sm:mt-0 sm:flex-col sm:text-right">
<span class="font-medium"><%= opt_text[2] %></span>
<span class="ml-1 opacity-50 sm:ml-0"><%= opt_text[3] %></span>
</span>
</span>
<% else %>
<span class="radio-small-card justify-center p-3 text-sm font-semibold"><%= opt_text %></span>
<% end %>
</label>
<% end %>
</div>
</fieldset>
<% if error %>
<p class="text-sm text-red-600 leading-6" id="<%= name %>-error"><%= error %></p>
<% end %>
</div>