memEx/lib/lokal_web/components/table_component.html.heex

49 lines
1.6 KiB
Plaintext
Raw Normal View History

2022-03-05 23:13:37 -05:00
<div class="w-full overflow-x-auto border border-gray-600 rounded-lg shadow-lg bg-black">
<table class="min-w-full table-auto text-center bg-white">
<thead class="border-b border-primary-600">
<tr>
<%= for %{key: key, label: label} = column <- @columns do %>
<%= if column |> Map.get(:sortable, true) do %>
2023-01-25 23:13:18 -05:00
<th class={["p-2", column[:class]]}>
2022-03-05 23:13:37 -05:00
<span
class="cursor-pointer"
phx-click="sort_by"
phx-value-sort-key={key}
phx-target={@myself}
>
<span class="underline"><%= label %></span>
<%= if @last_sort_key == key do %>
<%= case @sort_mode do %>
<% :asc -> %>
<i class="fas fa-sm fa-chevron-down"></i>
<% :desc -> %>
<i class="fas fa-sm fa-chevron-up"></i>
<% end %>
<% else %>
<i class="fas fa-sm fa-chevron-up opacity-0"></i>
<% end %>
</span>
</th>
<% else %>
2023-01-25 23:13:18 -05:00
<th class={["p-2", column[:class]]}>
2022-03-05 23:13:37 -05:00
<%= label %>
</th>
<% end %>
<% end %>
</tr>
</thead>
<tbody>
2023-02-04 09:16:51 -05:00
<tr :for={values <- @rows}>
<td :for={%{key: key} = value <- @columns} class={["p-2", value[:class]]}>
<%= case values |> Map.get(key) do %>
<% {_custom_sort_value, value} -> %>
<%= value %>
<% value -> %>
<%= value %>
2022-03-05 23:13:37 -05:00
<% end %>
2023-02-04 09:16:51 -05:00
</td>
</tr>
2022-03-05 23:13:37 -05:00
</tbody>
</table>
</div>