defmodule PinchflatWeb.CustomComponents.TableComponents do @moduledoc false use Phoenix.Component import PinchflatWeb.CoreComponents import PinchflatWeb.CustomComponents.TextComponents @doc """ Renders a table component with the given rows and columns. ## Examples <.table rows={@users}> <:col :let={user} label="Name"><%= user.name %> """ attr :rows, :list, required: true attr :table_class, :string, default: "" attr :sort_key, :string, default: nil attr :sort_direction, :string, default: nil attr :row_item, :any, default: &Function.identity/1, doc: "the function for mapping each row before calling the :col and :action slots" slot :col, required: true do attr :label, :string attr :class, :string attr :sort_key, :string end def table(assigns) do ~H"""
|
{col[:label]}
<.icon
:if={to_string(@sort_key) == col[:sort_key]}
name={if @sort_direction == :asc, do: "hero-chevron-up", else: "hero-chevron-down"}
class="w-3 h-3 mt-2 ml-1 absolute"
/>
|
|---|
| {render_slot(col, @row_item.(row))} |