{# Table Macros ============ Reusable table components. Usage: {% from 'shared/macros/tables.html' import table_wrapper, table_header, table_empty_state %} {% call table_wrapper() %} {{ table_header(['Name', 'Email', 'Status', 'Actions']) }} ... {% endcall %} #} {# Table Wrapper ============= Wraps the table with proper overflow and shadow styling. #} {% macro table_wrapper(class_extra='') %}
{{ caller() }}
{% endmacro %} {# Table Header ============ Renders the table header row. Parameters: - columns: List of column names - sortable: Whether columns are sortable (default: false) - future enhancement #} {% macro table_header(columns) %} {% for column in columns %} {{ column }} {% endfor %} {% endmacro %} {# Sortable Table Header ===================== Renders a table header with sortable columns. Parameters: - columns: List of column definitions [{'label': '', 'key': '', 'sortable': true/false, 'width': ''}] - sort_key_var: Alpine.js variable for current sort key (default: 'sortKey') - sort_dir_var: Alpine.js variable for sort direction (default: 'sortDir') - on_sort: Alpine.js handler when column is clicked (default: 'sortBy') Usage: {{ sortable_table_header([ {'label': 'Name', 'key': 'name', 'sortable': true}, {'label': 'Email', 'key': 'email', 'sortable': true}, {'label': 'Status', 'key': 'status', 'sortable': false}, {'label': 'Actions', 'key': 'actions', 'sortable': false, 'width': 'w-24'} ]) }} Required Alpine.js: sortKey: 'name', sortDir: 'asc', sortBy(key) { if (this.sortKey === key) { this.sortDir = this.sortDir === 'asc' ? 'desc' : 'asc'; } else { this.sortKey = key; this.sortDir = 'asc'; } this.loadItems(); } #} {% macro sortable_table_header(columns, sort_key_var='sortKey', sort_dir_var='sortDir', on_sort='sortBy') %} {% for col in columns %} {% if col.sortable %} {% else %} {{ col.label }} {% endif %} {% endfor %} {% endmacro %} {# Table Body Wrapper ================== Wraps the tbody with proper styling. #} {% macro table_body() %} {{ caller() }} {% endmacro %} {# Table Empty State ================= Shows a centered message when the table has no data. Parameters: - colspan: Number of columns to span - icon: Icon name (default: 'inbox') - title: Empty state title - message: Empty state message - show_condition: Alpine.js condition (default: 'true') - has_filters: Whether to show filter hint (default: true) #} {% macro table_empty_state(colspan, icon='inbox', title='No data found', message='', show_condition='true', has_filters=true) %} {% endmacro %} {# Table Row ========= A standard table row with hover styling. #} {% macro table_row(class_extra='') %} {{ caller() }} {% endmacro %} {# Table Cell ========== A standard table cell. #} {% macro table_cell(class_extra='') %} {{ caller() }} {% endmacro %} {# Table Cell with Text ==================== A simple text cell. Parameters: - text: Static text or Alpine.js expression for x-text - is_dynamic: Whether text is Alpine.js expression (default: false) - truncate: Whether to truncate with max-width (default: false) - max_width: Max width class (default: 'max-w-xs') #} {% macro table_cell_text(text, is_dynamic=false, truncate=false, max_width='max-w-xs') %} {% if truncate %}

{% if not is_dynamic %}{{ text }}{% endif %}

{% else %} {% if is_dynamic %} {% else %} {{ text }} {% endif %} {% endif %} {% endmacro %} {# Table Cell with Avatar ====================== A cell with avatar image and text. Parameters: - image_src: Image source (Alpine.js expression) - title: Primary text (Alpine.js expression) - subtitle: Secondary text (Alpine.js expression, optional) - fallback_icon: Icon to show if no image (default: 'user') #} {% macro table_cell_avatar(image_src, title, subtitle=none, fallback_icon='user') %}

{% if subtitle %}

{% endif %}
{% endmacro %} {# Table Cell with Date ==================== A cell that formats a date. Parameters: - date_var: Alpine.js variable containing the date - format_func: JavaScript date formatting function (default: 'formatDate') #} {% macro table_cell_date(date_var, format_func='formatDate') %} {% endmacro %} {# Table Loading Overlay ===================== An overlay shown while table data is loading. Parameters: - show_condition: Alpine.js condition (default: 'loading') - message: Loading message #} {% macro table_loading_overlay(show_condition='loading', message='Loading...') %}

{{ message }}

{% endmacro %}