ubicloud/views/components/table_card.erb
Jeremy Evans 750ebdc055 Change from erb_formatter to herb/formatter
Currently, herb/formatter has at least 4 bugs the prevent us from
switching to it (https://github.com/marcoroth/herb/issues 476, 477,
478, and 479). This includes manual fixes for each issue.

herb/formatter also introduces a rubocop violation for the
Layout/AssignmentIndentation cop. This disables that cop.
2025-09-05 14:01:01 -07:00

104 lines
3.7 KiB
Text

<%# locals: (title: nil, headers: [], rows:, empty_state: nil, right_items: nil, footer: nil) %>
<div>
<% if title || right_items %>
<div class="md:flex md:items-center md:justify-between pb-2 lg:pb-4">
<div class="min-w-0 flex-1">
<h3
class="
text-2xl font-bold leading-7 text-gray-900 sm:truncate
sm:text-2xl sm:tracking-tight
"
>
<%= title %>
</h3>
</div>
<% if right_items %>
<div class="mt-4 flex md:ml-4 md:mt-0"><%== right_items.join %></div>
<% end %>
</div>
<% end %>
<div
class="
overflow-hidden rounded-lg shadow ring-1 ring-black ring-opacity-5
bg-white divide-y divide-gray-200
"
>
<table class="min-w-full divide-y divide-gray-300">
<% unless headers.empty? || rows.empty? %>
<thead class="bg-gray-50">
<tr>
<% headers.each_with_index do |name, i| %>
<th
scope="col"
<% if i == 0 %>
class="
pl-4 pr-3 sm:pl-6 py-3.5 text-left text-sm font-semibold
text-gray-900
"
<% elsif i + 1 == headers.length %>
class="
pl-3 pr-4 sm:pr-6 py-3.5 text-left text-sm font-semibold
text-gray-900
"
<% else %>
class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900"
<% end %>
>
<%= name %>
</th>
<% end %>
</tr>
</thead>
<% end %>
<tbody class="divide-y divide-gray-200 bg-white">
<% if rows.empty? %>
<tr>
<td
colspan="<%= headers.length %>"
class="text-center py-4 px-8 lg:px-32"
>
<% if empty_state.is_a?(Hash) %>
<%== part("components/empty_state", **empty_state) %>
<% else %>
<%== empty_state %>
<% end %>
</td>
</tr>
<% else %>
<% rows.each do |columns, row_opts| %>
<% row_opts ||= {} %>
<tr id="<%= row_opts[:id] %>">
<% columns.each_with_index do |(value, col_opts), i| %>
<% col_opts ||= {} %>
<td <% if i == 0
cls="pl-4 pr-3 sm:pl-6 py-4 text-gray-900 font-medium whitespace-nowrap text-sm"
elsif i + 1 == columns.length
cls="pl-3 pr-4 sm:pr-6 py-4 text-gray-500 whitespace-nowrap text-sm"
else
cls="px-3 py-4 text-gray-500 whitespace-nowrap text-sm"
end %> class="<%= cls %> <%= col_opts[:extra_class] %>">
<% if value.is_a?(Array) %>
<% (first_value, first_opts), (second_value, second_opts) = value %>
<div class="font-medium text-gray-900">
<%== part("components/value_content", content: first_value, opts: first_opts) %>
</div>
<% if second_value %>
<div class="mt-1 text-gray-500 text-xs">
<%== part("components/value_content", content: second_value, opts: second_opts) %>
</div>
<% end %>
<% else %>
<%== part("components/value_content", content: value, opts: col_opts) %>
<% end %>
</td>
<% end %>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<%== footer %>
</div>
</div>