08 · Tabelas

CardTable

variant rows · flat · prioridade de colunas p1–p4 · sub-linhas · ordenação

Tabela “em cartão” do segundo exemplo: bandeja arredondada, colunas mono para IDs e badges com contorno.

Linhas entrando e destaque andando

Pedido Cliente Status Total Hora
PED-2491 Mercadinho Bom Preço Pago R$ 1.284,90 14:02
↳ 3 itens · Arroz 5 kg, Óleo 900 ml, Café 500 g
PED-2492 Padaria Central Aberto R$ 312,00 14:40
PED-2493 Farmácia Vida Atrasado R$ 2.940,10 ontem
PED-2494 Açougue Serrinha Pago R$ 860,00 ontem
.heex
<% badge_color = fn "pos" -> "success"; "neg" -> "error"; _ -> "neutral" end %>
<% rows = [%{no: "PED-2491", cl: "Mercadinho Bom Preço", tone: "pos", st: "Pago", tot: "R$ 1.284,90", h: "14:02", dl: "0.00", sub: "↳ 3 itens · Arroz 5 kg, Óleo 900 ml, Café 500 g"}, %{no: "PED-2492", cl: "Padaria Central", tone: "", st: "Aberto", tot: "R$ 312,00", h: "14:40", dl: "1.50"}, %{no: "PED-2493", cl: "Farmácia Vida", tone: "neg", st: "Atrasado", tot: "R$ 2.940,10", h: "ontem", dl: "3.00"}, %{no: "PED-2494", cl: "Açougue Serrinha", tone: "pos", st: "Pago", tot: "R$ 860,00", h: "ontem", dl: "4.50"}] %>
<.card_table id="ct-live" rows={rows} body_class="mo-rows" row_attrs={&%{style: "--dl:#{&1.dl}s"}} row_expanded={&Map.has_key?(&1, :sub)}>
  <:col :let={o} label="Pedido" class="font-mono text-[13px]">{o.no}</:col>
  <:col :let={o} label="Cliente">{o.cl}</:col>
  <:col :let={o} label="Status"><.badge canvas color={badge_color.(o.tone)} dot>{o.st}</.badge></:col>
  <:col :let={o} label="Total" align="right" class="font-medium text-ink">{o.tot}</:col>
  <:col :let={o} label="Hora" align="right">{o.h}</:col>
  <:expand :let={o}>{o.sub}</:expand>
</.card_table>

variant rows × flat · sub-linhas

rows
Pedido Cliente Status Total Hora
PED-2491 Mercadinho Bom Preço Pago R$ 1.284,90 14:02
↳ 3 itens · Arroz 5 kg, Óleo 900 ml, Café 500 g
PED-2492 Padaria Central Aberto R$ 312,00 14:40
PED-2493 Farmácia Vida Atrasado R$ 2.940,10 ontem
flat
Pedido Cliente Status Total Hora
PED-2491 Mercadinho Bom Preço Pago R$ 1.284,90 14:02
PED-2492 Padaria Central Aberto R$ 312,00 14:40
PED-2493 Farmácia Vida Atrasado R$ 2.940,10 ontem
.heex
<% badge_color = fn "pos" -> "success"; "neg" -> "error"; _ -> "neutral" end %>
<% rows = [%{no: "PED-2491", cl: "Mercadinho Bom Preço", tone: "pos", st: "Pago", tot: "R$ 1.284,90", h: "14:02", dl: "0.00", sub: "↳ 3 itens · Arroz 5 kg, Óleo 900 ml, Café 500 g"}, %{no: "PED-2492", cl: "Padaria Central", tone: "", st: "Aberto", tot: "R$ 312,00", h: "14:40", dl: "0.35"}, %{no: "PED-2493", cl: "Farmácia Vida", tone: "neg", st: "Atrasado", tot: "R$ 2.940,10", h: "ontem", dl: "0.70"}] %>
<div class="grid grid-cols-2 gap-4">
  <div class="flex flex-col gap-1.5">
    <span class="font-mono text-xs text-muted">rows</span>
    <.card_table id="ct-rows" rows={rows} row_attrs={&%{style: "--dl:#{&1.dl}s"}} row_expanded={&Map.has_key?(&1, :sub)}>
      <:col :let={o} label="Pedido" class="font-mono text-[13px]">{o.no}</:col>
  <:col :let={o} label="Cliente">{o.cl}</:col>
  <:col :let={o} label="Status"><.badge canvas color={badge_color.(o.tone)} dot>{o.st}</.badge></:col>
  <:col :let={o} label="Total" align="right" class="font-medium text-ink">{o.tot}</:col>
  <:col :let={o} label="Hora" align="right">{o.h}</:col>
      <:expand :let={o}>{o.sub}</:expand>
    </.card_table>
  </div>
  <div class="flex flex-col gap-1.5">
    <span class="font-mono text-xs text-muted">flat</span>
    <.card_table id="ct-flat" variant="flat" rows={rows} row_attrs={&%{style: "--dl:#{&1.dl}s"}}>
      <:col :let={o} label="Pedido" class="font-mono text-[13px]">{o.no}</:col>
  <:col :let={o} label="Cliente">{o.cl}</:col>
  <:col :let={o} label="Status"><.badge canvas color={badge_color.(o.tone)} dot>{o.st}</.badge></:col>
  <:col :let={o} label="Total" align="right" class="font-medium text-ink">{o.tot}</:col>
  <:col :let={o} label="Hora" align="right">{o.h}</:col>
    </.card_table>
  </div>
</div>

prioridade das colunas (when_hidden p1–p4): some primeiro a de menor prioridade

p1p2p3p4tela larga: tudo
Pedido Cliente Status Total Hora
PED-2491 Mercadinho Bom Preço Pago R$ 1.284,90 14:02
PED-2492 Padaria Central Aberto R$ 312,00 14:40
p1p2p3p4≤ 1024px: some Hora
Pedido Cliente Status Total Hora
PED-2491 Mercadinho Bom Preço Pago R$ 1.284,90 14:02
PED-2492 Padaria Central Aberto R$ 312,00 14:40
p1p2p3p4≤ 768px: some Status
Pedido Cliente Status Total Hora
PED-2491 Mercadinho Bom Preço Pago R$ 1.284,90 14:02
PED-2492 Padaria Central Aberto R$ 312,00 14:40
.heex
<% rows = [%{no: "PED-2491", cl: "Mercadinho Bom Preço", tone: "pos", st: "Pago", tot: "R$ 1.284,90", h: "14:02", dl: "0.00"}, %{no: "PED-2492", cl: "Padaria Central", tone: "", st: "Aberto", tot: "R$ 312,00", h: "14:40", dl: "0.35"}] %>
<div class="flex flex-col gap-3.5">
  <div class="flex flex-col gap-1.5">
    <div class="flex flex-wrap gap-1.5"><span class="rounded-md px-[7px] py-0.5 font-mono text-[11px] bg-sunken text-muted">p1</span><span class="rounded-md px-[7px] py-0.5 font-mono text-[11px] bg-sunken text-muted">p2</span><span class="rounded-md px-[7px] py-0.5 font-mono text-[11px] bg-sunken text-muted">p3</span><span class="rounded-md px-[7px] py-0.5 font-mono text-[11px] bg-inverse text-on-inverse">p4</span><span class="rounded-md px-[7px] py-0.5 font-mono text-[11px] text-muted">tela larga: tudo</span></div>
    <.table id="pri-4" rows={rows} row_attrs={&%{style: "--dl:#{&1.dl}s"}}>
      <:col :let={o} label="Pedido" class="font-mono text-[13px]">{o.no}</:col>
        <:col :let={o} label="Cliente">{o.cl}</:col>
        <:col :let={o} label="Status" ><.badge canvas dot color={Map.get(%{"pos" => "success", "neg" => "error"}, o.tone, "neutral")}>{o.st}</.badge></:col>
        <:col :let={o} label="Total" align="right" class="font-medium text-ink">{o.tot}</:col>
        <:col :let={o} label="Hora" align="right">{o.h}</:col>
    </.table>
  </div>
  <div class="flex flex-col gap-1.5">
    <div class="flex flex-wrap gap-1.5"><span class="rounded-md px-[7px] py-0.5 font-mono text-[11px] bg-sunken text-muted">p1</span><span class="rounded-md px-[7px] py-0.5 font-mono text-[11px] bg-sunken text-muted">p2</span><span class="rounded-md px-[7px] py-0.5 font-mono text-[11px] bg-inverse text-on-inverse">p3</span><span class="rounded-md px-[7px] py-0.5 font-mono text-[11px] bg-sunken text-muted">p4</span><span class="rounded-md px-[7px] py-0.5 font-mono text-[11px] text-muted">≤ 1024px: some Hora</span></div>
    <.table id="pri-3" rows={rows} row_attrs={&%{style: "--dl:#{&1.dl}s"}}>
      <:col :let={o} label="Pedido" class="font-mono text-[13px]">{o.no}</:col>
        <:col :let={o} label="Cliente">{o.cl}</:col>
        <:col :let={o} label="Status" ><.badge canvas dot color={Map.get(%{"pos" => "success", "neg" => "error"}, o.tone, "neutral")}>{o.st}</.badge></:col>
        <:col :let={o} label="Total" align="right" class="font-medium text-ink">{o.tot}</:col>
        <:col :let={o} label="Hora" dim align="right">{o.h}</:col>
    </.table>
  </div>
  <div class="flex flex-col gap-1.5">
    <div class="flex flex-wrap gap-1.5"><span class="rounded-md px-[7px] py-0.5 font-mono text-[11px] bg-sunken text-muted">p1</span><span class="rounded-md px-[7px] py-0.5 font-mono text-[11px] bg-inverse text-on-inverse">p2</span><span class="rounded-md px-[7px] py-0.5 font-mono text-[11px] bg-sunken text-muted">p3</span><span class="rounded-md px-[7px] py-0.5 font-mono text-[11px] bg-sunken text-muted">p4</span><span class="rounded-md px-[7px] py-0.5 font-mono text-[11px] text-muted">≤ 768px: some Status</span></div>
    <.table id="pri-2" rows={rows} row_attrs={&%{style: "--dl:#{&1.dl}s"}}>
      <:col :let={o} label="Pedido" class="font-mono text-[13px]">{o.no}</:col>
        <:col :let={o} label="Cliente">{o.cl}</:col>
        <:col :let={o} label="Status"><.badge canvas dot color={Map.get(%{"pos" => "success", "neg" => "error"}, o.tone, "neutral")}>{o.st}</.badge></:col>
        <:col :let={o} label="Total" align="right" class="font-medium text-ink">{o.tot}</:col>
        <:col :let={o} label="Hora" dim align="right">{o.h}</:col>
    </.table>
  </div>
</div>

Valores da API que completam a paridade

Total sort_dir=asc
Total sort_dir=desc
.heex
<div class="grid grid-cols-4 gap-3.5">
  <div class="flex flex-col items-start gap-1.5"><.chip>Total <.icon name="arrow-up" size="sm" /></.chip><span class="font-mono text-[11px] text-muted">sort_dir=asc</span></div>
  <div class="flex flex-col items-start gap-1.5"><.chip>Total <.icon name="arrow-down" size="sm" /></.chip><span class="font-mono text-[11px] text-muted">sort_dir=desc</span></div>
</div>

Toolbar e barra de seleção

Pedidos
2 selecionados 2 pedidos prontos para ação
Pedido Cliente Total
PED-2491 Mercadinho Bom Preço R$ 1.284,90
PED-2492 Padaria Central R$ 312,00
PED-2493 Farmácia Vida R$ 2.940,10
PED-2494 Açougue Serrinha R$ 860,00
.heex
<% rows = [%{no: "PED-2491", cl: "Mercadinho Bom Preço", tot: "R$ 1.284,90"}, %{no: "PED-2492", cl: "Padaria Central", tot: "R$ 312,00"}, %{no: "PED-2493", cl: "Farmácia Vida", tot: "R$ 2.940,10"}, %{no: "PED-2494", cl: "Açougue Serrinha", tot: "R$ 860,00"}] %>
<%!-- `selected` vem do servidor (a LiveView dona da tabela); aqui é uma lista fixa para a barra aparecer --%>
<.card_table
  id="ct-selection"
  title="Pedidos"
  rows={rows}
  row_key={& &1.no}
  selected={["PED-2491", "PED-2493"]}
  on_select="select"
  on_select_all="select_all"
  selection_label="selecionado"
  selection_label_plural="selecionados"
>
  <:toolbar>
    <.input icon="search" placeholder="Buscar pedido" aria-label="Buscar pedido" class="max-w-[260px]" />
    <.button canvas size="sm">Exportar</.button>
  </:toolbar>
  <:selection :let={%{count: n}}>
    <span>{n} pedidos prontos para ação</span>
    <.button canvas size="sm">Arquivar</.button>
  </:selection>
  <:col :let={o} label="Pedido" class="font-mono text-[13px]">{o.no}</:col>
  <:col :let={o} label="Cliente">{o.cl}</:col>
  <:col :let={o} label="Total" align="right" class="font-medium text-ink">{o.tot}</:col>
</.card_table>

Carregando (loading)

Pedidos
Pedido Cliente Total
.heex
<.card_table id="ct-loading" title="Pedidos" rows={[]} loading loading_rows={4} loading_label="Carregando pedidos">
  <:col label="Pedido">{nil}</:col>
  <:col label="Cliente">{nil}</:col>
  <:col label="Total" align="right">{nil}</:col>
</.card_table>

Erro com tentar novamente (error + on_retry)

Pedidos
.heex
<.card_table
  id="ct-error"
  title="Pedidos"
  rows={[]}
  error="Não foi possível carregar os pedidos."
  on_retry="retry"
  retry_label="Tentar novamente"
>
  <:col label="Pedido">{nil}</:col>
  <:col label="Cliente">{nil}</:col>
  <:col label="Total" align="right">{nil}</:col>
</.card_table>

Experimente: row_groups com stream e expand (inserir, remover, reordenar)

Abra um detalhe com a seta e mexa na lista: a linha de detalhe acompanha.
Pedidos
Pedido Cliente Total
PED-2491 Mercadinho Bom Preço R$ 1.284,90
Entrega agendada para terça, 14h.
PED-2492 Padaria Central R$ 312,00
PED-2493 Farmácia Vida R$ 2.940,10
Aguarda aprovação do financeiro.
PED-2494 Açougue Serrinha R$ 860,00
.heex
<%!-- stream + :expand: um <tbody> por linha, o detalhe acompanha a linha ao inserir no topo, remover ou reordenar --%>
<.live_component module={LedgerShowcaseWeb.Demos.RowsDemo} id="rows-card-table" kind={:card_table} />

Experimente: copy_toast (copie o número do pedido)

Pedidos
Pedido Cliente Total
Mercadinho Bom Preço R$ 1.284,90
Padaria Central R$ 312,00
Farmácia Vida R$ 2.940,10
.heex
<% orders = [%{no: "PED-2491", cl: "Mercadinho Bom Preço", tot: "R$ 1.284,90"}, %{no: "PED-2492", cl: "Padaria Central", tot: "R$ 312,00"}, %{no: "PED-2493", cl: "Farmácia Vida", tot: "R$ 2.940,10"}] %>
<%!-- o toast sai no toaster da página (aqui um toaster contido, só para a demo) --%>
<div class="flex flex-col gap-3">
  <.card_table id="ct-copy" title="Pedidos" rows={orders} copy_toast copy_toast_message="%s copiado">
    <:col :let={o} label="Pedido" class="font-mono text-[13px]" copy={& &1.no} copy_label="Copiar o número do pedido" copied_label="Copiado">{o.no}</:col>
    <:col :let={o} label="Cliente">{o.cl}</:col>
    <:col :let={o} label="Total" align="right" class="font-medium text-ink">{o.tot}</:col>
  </.card_table>
  <.toaster id="ct-copy-toaster" contained />
</div>

Uso

<.card_table id="cases" rows={@cases}>…</.card_table>

Regras

  • Avatar mono de iniciais nas linhas; meta (idade/sexo) em mono muted ao lado do nome.
  • Status e risco em badges outline com fundo tonal leve; Critical leva ponto.
  • A bandeja (lu-card) dá a borda dupla arredondada sem pesar a tabela.

Referência da API

Todos os function components, atributos, valores e slots que este componente cobre.

The "card" table: one row per record in a rounded tray (styled with utilities only), with an optional heading, a footer line and sub-lines. For long lists (orders, invoices, clients).

<.card_table id="orders" rows={@streams.orders} on_select="select" selected={@selected}
  status={&order_status/1}>
  <:col :let={{_id, o}} label="Pedido" class="mono">{o.number}</:col>
  <:col :let={{_id, o}} label="Cliente">
    {o.client}
    <.ctable_sub priority={2}>{o.issuer}</.ctable_sub>
  </:col>
  <:col :let={{_id, o}} label="Total" align="right">{o.total}</:col>
  <:foot><span>Mostrando 1–6 de 128</span></:foot>
</.card_table>

It renders LedgerUI.Components.Table.table/1 inside the tray, so rows (list or stream), sorting, selection and the other row_* attrs work as there. variant="flat" is the plain table of the canvas dashboards (lu-table flat), in a card only when it has a title, :top, :actions or :foot.

Columns leave by priority (1 to 4) when the table's own box is narrower than breakpoints ([1180, 960, 720, 520] by default; between 2 and 5 strictly descending integers, else ArgumentError). A <.ctable_sub> is a second line inside a cell that leaves by its own priority, or shows only once the columns of when_hidden (p1..p4) have left. <:expand :let={row}> is a full-width line under each row for which row_expanded is true.

Card layout, panel, copy, edit

  • Under the last breakpoint (520 by default) rows with a column role (head, status, title, value) become two-line cards; card keeps a column in its own line, truncate, width shape the tracks, <:action card={false}> leaves the action cell out.
  • With <:detail> slots or columns with priority, a click on a row (rows variant) opens a panel under it (hook LedgerUI.CardTable, on the <tbody>); panel_label names it.
  • copy / copy_label / copied_label / copy_show / copy_tip on a column draw a copy button (same hook). A copy shows a toast with the value in bold (ledger:toast, as clipboard/1; the page needs a toaster): copy_toast={false} turns it off, copy_toast_message="%s copiado" sets the text, and both can be set on one column too.
  • A stream with <:expand> or a details panel renders one <tbody> per row (row_groups), so the detail rows follow their row on a reset, at: 0 insert and delete (#24).
  • row_editing + <:edit> swap a row for an inline form; row_action drops the action of a row.

status paints an inset bar through box-shadow on the row (data-status carries the colour name).

The tray, its heading, description and footer are styled here; the table inside (rows, cells, breakpoints, details panel) is LedgerUI.Components.Table. ctable_sub hides itself with the same container-query utilities (Table.Layout), from the breakpoints it is given.

<.card_table>

Attr Type Default Values / notes
id (required) :string
rows (required) :any A list or a @streams.x stream.
row_id :any nil
row_item :any &Function.identity/1
row_key :any nil
row_attrs :any nil Function of the row returning extra <tr> attributes.
status :any nil Function of the row returning a colour for the bar at its left, or nil.
on_select :any nil
on_select_all :any nil
selected :list []
all_selected :boolean nil
select_all_label :string "Select all rows"
select_label :string "Select row"
panel_label :string "Details" The accessible name of the details panel.
on_sort :any nil
sort_by :string nil
sort_dir :string "asc" asc, desc
target :any nil
title :string nil
description :string nil
meta :string nil A small muted text right after the title.
bordered :boolean true false drops the tray's own border, shadow and background.
row_expanded :any nil
row_editing :any nil Function of the row; true shows the <:edit> slot in place of the cells.
row_action :any nil Function of the row; false leaves out the content of its action cell.
breakpoints :list [1180, 960, 720, 520] Widths (px) under which priority 1, 2, 3... leave, descending; the last is the card layout.
body_class :any nil Classes of the <tbody>.
row_groups :boolean nil One <tbody> per row (with its panel and :expand rows), so a stream moves them together. nil turns it on for a stream with :expand/row_expanded or a details panel; false keeps the single <tbody>. See Table.
variant :string "rows" rows, flat
copy_toast :boolean true A toast (event ledger:toast on the page's toaster) with the copied value in bold after a copy column copies. false turns it off; a column's own copy_toast wins. Not shown while loading or with an error (no rows then).
copy_toast_message :string nil The toast text, %s is the copied value ("%s copiado"). Default: "%s · <copied_label>".
selection_label :string "selected" The text after the count in the :selection badge, for one selected.
selection_label_plural :string nil Same, for several (selection_label when nil).
selection_badge :boolean true false leaves the count badge out of the :selection strip (the slot draws all of it).
loading :boolean false Skeleton lines (loading_rows, with the columns) in place of the rows.
loading_rows :integer 5
loading_label :string "Loading"
error :string nil A message: shows the error state in place of the rows (wins over loading).
on_retry :any nil Event name or JS of the retry button of the error state.
retry_label :string "Tentar novamente"
class :any nil

Any other HTML/phx attribute goes to the root element.

Slots:

  • <:action> - attrs: priority, card - The last cell of every row (a menu button); receives the row.
  • <:actions> - Buttons at the right of the heading.
  • <:col> (required) - attrs: label, width, priority, role, align, truncate, class, sort_key, copy, copy_label, copied_label, copy_show, card, copy_tip, style, copy_toast, copy_toast_message - A column; receives the row (after row_item).
  • <:detail> - attrs: label - A line of the details panel that opens when a row is clicked.
  • <:edit> - Inline form in place of the cells of a row being edited.
  • <:empty> - Shown when there are no rows. Receives %{id, rows, selected, title}.
  • <:expand> - A full-width line under a row (see row_expanded); receives the row.
  • <:foot> - A line inside the card under the rows. Receives %{id, rows, selected, title}.
  • <:selection> - A strip under the toolbar, only while something is selected, with the accent-soft fill and no border. Receives %{count, selected}; the count badge is drawn before it.
  • <:toolbar> - A strip inside the card, between the heading and the table (search, filters, export), with a hairline under it.
  • <:top> - With variant="flat", what heads the card instead of the title (tabs).

<.ctable_sub>

A second line inside a card_table cell (12px, faint) that leaves by its own priority; or, with when_hidden="p2", shows only once the columns of priority 2 have left.

Attr Type Default Values / notes
priority :integer nil 1 to 4: leaves where the columns of that priority leave.
when_hidden :string nil nil, p1, p2, p3, p4
breakpoints :list [1180, 960, 720] The widths of the table's priorities 1, 2, 3...: the breakpoints of the card_table without its last (card) width.
class :any nil

Any other HTML/phx attribute goes to the root element.

Slots:

  • <:inner_block> (required)