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

52 lines
1.8 KiB
Plaintext
Raw Normal View History

2022-11-17 22:24:28 -05:00
<div id={@id} class="w-full overflow-x-auto rounded-lg shadow-lg bg-primary-900">
<table class="min-w-full table-auto text-center bg-primary-900">
<thead class="border-b border-primary-800">
2022-03-05 23:13:37 -05:00
<tr>
<%= for %{key: key, label: label} = column <- @columns do %>
<%= if column |> Map.get(:sortable, true) do %>
2023-01-25 23:11:31 -05:00
<th class={["p-2", column[:class]]}>
2022-03-05 23:13:37 -05:00
<span
2022-11-16 23:05:59 -05:00
class="cursor-pointer flex justify-center items-center space-x-2"
2022-03-05 23:13:37 -05:00
phx-click="sort_by"
phx-value-sort-key={key}
phx-target={@myself}
>
2022-11-17 22:24:28 -05:00
<span><%= label %></span>
2022-03-05 23:13:37 -05:00
<%= if @last_sort_key == key do %>
<%= case @sort_mode do %>
<% :asc -> %>
2022-11-17 22:24:28 -05:00
<i class="w-0 float-right fas fa-sm fa-chevron-down"></i>
2022-03-05 23:13:37 -05:00
<% :desc -> %>
2022-11-17 22:24:28 -05:00
<i class="w-0 float-right fas fa-sm fa-chevron-up"></i>
2022-03-05 23:13:37 -05:00
<% end %>
<% else %>
2022-11-17 22:24:28 -05:00
<i class="w-0 float-right fas fa-sm fa-chevron-up opacity-0"></i>
2022-03-05 23:13:37 -05:00
<% end %>
</span>
</th>
<% else %>
2023-01-25 23:11:31 -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 11:29:06 -05:00
<tr
:for={{values, i} <- @rows |> Enum.with_index()}
class={if i |> Integer.is_even(), do: @row_class, else: @alternate_row_class}
>
<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 11:29:06 -05:00
</td>
</tr>
2022-03-05 23:13:37 -05:00
</tbody>
</table>
</div>