# `LedgerUI.Components.CardTable`
[🔗](https://github.com/devaction-labs/ledger_ui/blob/v0.2.0/lib/ledger_ui/components/card_table.ex#L1)

The "card" table: one row per record in a rounded tray (`lu-card`), 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).
  * `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).

# `card_table`

## Attributes

* `id` (`:string`) (required)
* `rows` (`:any`) (required) - A list or a `@streams.x` stream.
* `row_id` (`:any`) - Defaults to `nil`.
* `row_item` (`:any`) - Defaults to `&Function.identity/1`.
* `row_key` (`:any`) - Defaults to `nil`.
* `row_attrs` (`:any`) - Function of the row returning extra `<tr>` attributes. Defaults to `nil`.
* `status` (`:any`) - Function of the row returning a colour for the bar at its left, or `nil`. Defaults to `nil`.
* `on_select` (`:any`) - Defaults to `nil`.
* `on_select_all` (`:any`) - Defaults to `nil`.
* `selected` (`:list`) - Defaults to `[]`.
* `all_selected` (`:boolean`) - Defaults to `nil`.
* `select_all_label` (`:string`) - Defaults to `"Select all rows"`.
* `select_label` (`:string`) - Defaults to `"Select row"`.
* `panel_label` (`:string`) - The accessible name of the details panel. Defaults to `"Details"`.
* `on_sort` (`:any`) - Defaults to `nil`.
* `sort_by` (`:string`) - Defaults to `nil`.
* `sort_dir` (`:string`) - Defaults to `"asc"`. Must be one of `"asc"`, or `"desc"`.
* `target` (`:any`) - Defaults to `nil`.
* `title` (`:string`) - Defaults to `nil`.
* `description` (`:string`) - Defaults to `nil`.
* `meta` (`:string`) - A small muted text right after the title. Defaults to `nil`.
* `bordered` (`:boolean`) - `false` drops the tray's own border, shadow and background. Defaults to `true`.
* `row_expanded` (`:any`) - Defaults to `nil`.
* `row_editing` (`:any`) - Function of the row; true shows the `<:edit>` slot in place of the cells. Defaults to `nil`.
* `row_action` (`:any`) - Function of the row; false leaves out the content of its action cell. Defaults to `nil`.
* `breakpoints` (`:list`) - Widths (px) under which priority 1, 2, 3... leave, descending; the last is the card layout. Defaults to `[1180, 960, 720, 520]`.
* `body_class` (`:any`) - Classes of the `<tbody>`. Defaults to `nil`.
* `variant` (`:string`) - Defaults to `"rows"`. Must be one of `"rows"`, or `"flat"`.
* `class` (`:any`) - Defaults to `nil`.
* Global attributes are accepted.
## Slots

* `action` - The last cell of every row (a menu button); receives the row. Accepts attributes:

  * `priority` (`:integer`)
  * `card` (`:boolean`)
* `actions` - Buttons at the right of the heading.
* `col` (required) - A column; receives the row (after `row_item`). Accepts attributes:

  * `label` (`:string`)
  * `width` (`:string`)
  * `priority` (`:integer`)
  * `role` (`:string`)
  * `align` (`:string`) - Must be one of `"start"`, `"end"`, `"left"`, `"center"`, or `"right"`.
  * `truncate` (`:boolean`)
  * `class` (`:any`)
  * `sort_key` (`:string`)
  * `copy` (`:any`)
  * `copy_label` (`:string`)
  * `copied_label` (`:string`)
  * `copy_show` (`:string`)
  * `card` (`:boolean`)
  * `copy_tip` (`:string`)
  * `style` (`:string`)
* `detail` - A line of the details panel that opens when a row is clicked. Accepts attributes:

  * `label` (`:string`)
* `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}`.
* `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.

## Attributes

* `priority` (`:integer`) - 1 to 4: leaves where the columns of that priority leave. Defaults to `nil`.
* `when_hidden` (`:string`) - Defaults to `nil`.Must be one of `nil`, `"p1"`, `"p2"`, `"p3"`, or `"p4"`.
* `class` (`:any`) - Defaults to `nil`.
* Global attributes are accepted.
## Slots

* `inner_block` (required)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
