{#- chirp-ui: Table component Responsive table with header configuration and row helper. Usage: from "chirpui/table.html" import table, row call table(headers=["Name", "Email", "Role"]) row("Alice", "alice@example.com", "Admin") row("Bob", "bob@example.com", "User") end Per-column alignment: call table(headers=["Name", "Status", "Count"], align=["left", "center", "right"]) row("Alice", "Active", "42") end Column widths (CSS values or proportions): call table(headers=["Name", "Status"], widths=["2fr", "1fr"]) Slots: caption (table caption), row_actions (header cell for actions column). Sortable headers: call table(headers=["Name", "Email"], sortable=true, sort_url="/users", hx_target="#user-table") row(user.name, user.email) end Row with actions: pass row_actions(...) as last cell when actions_header=true Sticky header: call table(headers=[...], sticky_header=true) -#} {% def table(headers=none, sortable=false, sort_url=none, hx_target=none, striped=false, sticky_header=false, actions_header=false, align=none, widths=none, compact=false, cls="") %}
{% if widths %} {% for w in widths %} {% end %} {% if actions_header %}{% end %} {% end %} {% if headers %} {% for header in headers %} {% set col_align = align[loop.index0] if align and loop.index0 < align | length else "" %} {% end %} {% if actions_header %} {% end %} {% end %} {% slot %}
{% slot caption %}
{{ header }}
{% end %} {% def row(*cells) %} {% for cell in cells %} {{ cell }} {% end %} {% end %} {% def aligned_row(cells, align) %} {% for cell in cells %} {% set col_align = align[loop.index0] if align and loop.index0 < align | length else "" %} {{ cell }} {% end %} {% end %} {% def table_empty(message="No data available", icon="◇") %} {{ message }} {% end %}