defmodule PinchflatWeb.CustomComponents.TableComponents do @moduledoc false use Phoenix.Component @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 :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 end def table(assigns) do ~H"""
<%= col[:label] %>
length(@rows) && "border-b border-[#eee] dark:border-π", col[:class] ]} > <%= render_slot(col, @row_item.(row)) %>
""" end end