feat: complete TailAdmin parity with remaining macro features

Add missing features identified in TailAdmin gap analysis:

cards.html:
- stat_card_with_trend: Stats card with up/down trend indicator and percentage
- card_with_menu: Card with dropdown menu in header
- card_with_menu_simple: Simplified version with menu_items parameter

tables.html:
- sortable_table_header: Table header with sortable columns, sort indicators,
  and Alpine.js integration for sort state management

forms.html:
- searchable_select: Dropdown with search/filter functionality
- multi_select: Multi-select dropdown with tag display

This completes feature parity with TailAdmin free template.
The tailadmin-free-tailwind-dashboard-template folder can now be deleted.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-06 19:32:42 +01:00
parent c0e44c2751
commit fbd3a45c38
3 changed files with 457 additions and 0 deletions

View File

@@ -49,6 +49,65 @@
{% endmacro %}
{#
Stat Card with Trend
====================
A statistics card with icon, value, and trend indicator.
Parameters:
- icon: Icon name
- label: Card label/title
- value: Alpine.js expression for the value
- trend_value: Alpine.js expression for trend percentage (e.g., '+12.5%' or '-3.2%')
- trend_direction: Alpine.js expression for direction ('up' | 'down' | 'neutral')
- color: Card color theme
- format: Optional format function
- compare_label: Label for comparison period (default: 'vs last month')
#}
{% macro stat_card_with_trend(icon, label, value, trend_value, trend_direction='neutral', color='orange', format=none, compare_label='vs last month') %}
{% set colors = {
'orange': 'text-orange-500 bg-orange-100 dark:text-orange-100 dark:bg-orange-500',
'green': 'text-green-500 bg-green-100 dark:text-green-100 dark:bg-green-500',
'blue': 'text-blue-500 bg-blue-100 dark:text-blue-100 dark:bg-blue-500',
'purple': 'text-purple-500 bg-purple-100 dark:text-purple-100 dark:bg-purple-500',
'red': 'text-red-500 bg-red-100 dark:text-red-100 dark:bg-red-500',
'yellow': 'text-yellow-500 bg-yellow-100 dark:text-yellow-100 dark:bg-yellow-500',
'teal': 'text-teal-500 bg-teal-100 dark:text-teal-100 dark:bg-teal-500'
} %}
<div class="p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
<div class="flex items-center justify-between">
<div class="flex items-center">
<div class="p-3 mr-4 rounded-full {{ colors[color] }}">
<span x-html="$icon('{{ icon }}', 'w-5 h-5')"></span>
</div>
<div>
<p class="text-sm font-medium text-gray-600 dark:text-gray-400">{{ label }}</p>
<p class="text-2xl font-semibold text-gray-700 dark:text-gray-200"
x-text="{% if format %}{{ format }}({{ value }}){% else %}{{ value }} || 0{% endif %}">0</p>
</div>
</div>
<div class="text-right">
<span class="inline-flex items-center text-sm font-medium"
:class="{
'text-green-600 dark:text-green-400': {{ trend_direction }} === 'up',
'text-red-600 dark:text-red-400': {{ trend_direction }} === 'down',
'text-gray-500 dark:text-gray-400': {{ trend_direction }} === 'neutral'
}">
<svg x-show="{{ trend_direction }} === 'up'" class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18"/>
</svg>
<svg x-show="{{ trend_direction }} === 'down'" class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 14l-7 7m0 0l-7-7m7 7V3"/>
</svg>
<span x-text="{{ trend_value }}"></span>
</span>
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">{{ compare_label }}</p>
</div>
</div>
</div>
{% endmacro %}
{#
Stats Grid
==========
@@ -97,6 +156,110 @@
{% endmacro %}
{#
Card with Menu
==============
A card with a dropdown menu in the header.
Parameters:
- title: Card title
- subtitle: Card subtitle (optional)
- menu_var: Alpine.js variable for menu open state (default: 'menuOpen')
- class_extra: Additional CSS classes
#}
{% macro card_with_menu(title, subtitle=none, menu_var='menuOpen', class_extra='') %}
<div x-data="{ {{ menu_var }}: false }" class="bg-white rounded-lg shadow-xs dark:bg-gray-800 {{ class_extra }}">
<div class="flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700">
<div>
<h3 class="text-lg font-semibold text-gray-700 dark:text-gray-200">{{ title }}</h3>
{% if subtitle %}
<p class="text-sm text-gray-600 dark:text-gray-400">{{ subtitle }}</p>
{% endif %}
</div>
<div class="relative">
<button
@click="{{ menu_var }} = !{{ menu_var }}"
@click.outside="{{ menu_var }} = false"
class="p-2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors"
>
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
<path d="M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"/>
</svg>
</button>
<div
x-show="{{ menu_var }}"
x-transition
class="absolute right-0 mt-1 w-48 bg-white dark:bg-gray-800 rounded-lg shadow-lg border border-gray-200 dark:border-gray-700 py-1 z-10"
>
{{ caller_menu() if caller_menu is defined else '' }}
</div>
</div>
</div>
<div class="p-4">
{{ caller() }}
</div>
</div>
{% endmacro %}
{#
Card with Menu (Simple)
=======================
A simpler card with menu that accepts menu items as a parameter.
Parameters:
- title: Card title
- menu_items: List of menu items [{'label': '', 'onclick': '', 'icon': '', 'variant': ''}]
- subtitle: Card subtitle (optional)
- class_extra: Additional CSS classes
#}
{% macro card_with_menu_simple(title, menu_items=[], subtitle=none, class_extra='') %}
<div x-data="{ menuOpen: false }" class="bg-white rounded-lg shadow-xs dark:bg-gray-800 {{ class_extra }}">
<div class="flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700">
<div>
<h3 class="text-lg font-semibold text-gray-700 dark:text-gray-200">{{ title }}</h3>
{% if subtitle %}
<p class="text-sm text-gray-600 dark:text-gray-400">{{ subtitle }}</p>
{% endif %}
</div>
{% if menu_items %}
<div class="relative">
<button
@click="menuOpen = !menuOpen"
@click.outside="menuOpen = false"
class="p-2 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors"
>
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
<path d="M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"/>
</svg>
</button>
<div
x-show="menuOpen"
x-transition
class="absolute right-0 mt-1 w-48 bg-white dark:bg-gray-800 rounded-lg shadow-lg border border-gray-200 dark:border-gray-700 py-1 z-10"
>
{% for item in menu_items %}
<button
@click="{{ item.onclick }}; menuOpen = false"
class="flex items-center w-full px-4 py-2 text-sm font-medium transition-colors {{ 'text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20' if item.variant == 'danger' else 'text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700' }}"
>
{% if item.icon %}
<span x-html="$icon('{{ item.icon }}', 'w-4 h-4 mr-3')"></span>
{% endif %}
{{ item.label }}
</button>
{% endfor %}
</div>
</div>
{% endif %}
</div>
<div class="p-4">
{{ caller() }}
</div>
</div>
{% endmacro %}
{#
Info Card
=========

View File

@@ -544,3 +544,227 @@
</div>
</div>
{% endmacro %}
{#
Searchable Select
=================
A select dropdown with search/filter functionality.
Parameters:
- label: Field label
- x_model: Alpine.js x-model binding for selected value
- options_var: Alpine.js variable containing options array
- value_key: Key for option value (default: 'value')
- label_key: Key for option label (default: 'label')
- search_var: Alpine.js variable for search query (default: 'searchQuery')
- open_var: Alpine.js variable for dropdown open state (default: 'isOpen')
- placeholder: Placeholder text (default: 'Select...')
- search_placeholder: Search input placeholder (default: 'Search...')
- required: Whether the field is required
- disabled: Alpine.js expression for disabled state
- no_results_text: Text shown when no results (default: 'No results found')
Usage:
<div x-data="{
selected: '',
selectedLabel: '',
searchQuery: '',
isOpen: false,
options: [
{ id: '1', name: 'Option 1' },
{ id: '2', name: 'Option 2' }
],
get filteredOptions() {
if (!this.searchQuery) return this.options;
return this.options.filter(o => o.name.toLowerCase().includes(this.searchQuery.toLowerCase()));
},
selectOption(option) {
this.selected = option.id;
this.selectedLabel = option.name;
this.isOpen = false;
this.searchQuery = '';
}
}">
{{ searchable_select('Category', 'selected', 'filteredOptions', value_key='id', label_key='name') }}
</div>
#}
{% macro searchable_select(label, x_model, options_var, value_key='value', label_key='label', search_var='searchQuery', open_var='isOpen', placeholder='Select...', search_placeholder='Search...', required=false, disabled=none, no_results_text='No results found') %}
<div class="mb-4">
<label class="block text-sm">
<span class="text-gray-700 dark:text-gray-400">
{{ label }}{% if required %} <span class="text-red-600">*</span>{% endif %}
</span>
<div class="relative mt-1">
{# Selected value display / trigger button #}
<button
type="button"
@click="{{ open_var }} = !{{ open_var }}"
@click.outside="{{ open_var }} = false"
{% if disabled %}:disabled="{{ disabled }}"{% endif %}
class="flex items-center justify-between w-full px-4 py-2 text-sm text-left bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg hover:border-gray-400 dark:hover:border-gray-500 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
:class="{ 'ring-2 ring-purple-500 border-transparent': {{ open_var }} }"
>
<span
:class="!{{ x_model }} ? 'text-gray-400' : 'text-gray-700 dark:text-gray-300'"
x-text="selectedLabel || '{{ placeholder }}'"
>{{ placeholder }}</span>
<svg
class="w-4 h-4 ml-2 text-gray-400 transition-transform"
:class="{ 'rotate-180': {{ open_var }} }"
fill="none" stroke="currentColor" viewBox="0 0 24 24"
>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/>
</svg>
</button>
{# Dropdown panel #}
<div
x-show="{{ open_var }}"
x-transition:enter="transition ease-out duration-100"
x-transition:enter-start="transform opacity-0 scale-95"
x-transition:enter-end="transform opacity-100 scale-100"
x-transition:leave="transition ease-in duration-75"
x-transition:leave-start="transform opacity-100 scale-100"
x-transition:leave-end="transform opacity-0 scale-95"
class="absolute z-50 w-full mt-1 bg-white dark:bg-gray-800 rounded-lg shadow-lg border border-gray-200 dark:border-gray-700 overflow-hidden"
>
{# Search input #}
<div class="p-2 border-b border-gray-200 dark:border-gray-700">
<div class="relative">
<span class="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none">
<svg class="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
</svg>
</span>
<input
type="text"
x-model="{{ search_var }}"
@click.stop
placeholder="{{ search_placeholder }}"
class="w-full pl-9 pr-4 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md focus:border-purple-500 focus:ring-1 focus:ring-purple-500 dark:bg-gray-700 dark:text-gray-300"
>
</div>
</div>
{# Options list #}
<ul class="max-h-60 overflow-y-auto py-1">
<template x-for="option in {{ options_var }}" :key="option.{{ value_key }}">
<li>
<button
type="button"
@click="selectOption(option)"
class="flex items-center justify-between w-full px-4 py-2 text-sm text-left transition-colors"
:class="{{ x_model }} === option.{{ value_key }}
? 'bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300'
: 'text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700'"
>
<span x-text="option.{{ label_key }}"></span>
<svg
x-show="{{ x_model }} === option.{{ value_key }}"
class="w-4 h-4 text-purple-600"
fill="none" stroke="currentColor" viewBox="0 0 24 24"
>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
</svg>
</button>
</li>
</template>
<li x-show="{{ options_var }}.length === 0" class="px-4 py-3 text-sm text-center text-gray-500 dark:text-gray-400">
{{ no_results_text }}
</li>
</ul>
</div>
</div>
</label>
</div>
{% endmacro %}
{#
Multi-Select with Tags
======================
A multi-select dropdown that shows selected items as tags.
Parameters:
- label: Field label
- selected_var: Alpine.js variable for selected values array
- options_var: Alpine.js variable containing options array
- value_key: Key for option value (default: 'value')
- label_key: Key for option label (default: 'label')
- placeholder: Placeholder text (default: 'Select items...')
- max_items: Maximum number of items (optional)
Required Alpine.js methods:
toggleOption(option) - Add/remove option from selection
removeOption(value) - Remove option by value
isSelected(value) - Check if option is selected
getLabel(value) - Get label for a value
#}
{% macro multi_select(label, selected_var, options_var, value_key='value', label_key='label', placeholder='Select items...', max_items=none) %}
<div x-data="{ isOpen: false }" class="mb-4">
<label class="block text-sm">
<span class="text-gray-700 dark:text-gray-400">{{ label }}</span>
<div class="relative mt-1">
{# Selected tags display / trigger #}
<div
@click="isOpen = !isOpen"
@click.outside="isOpen = false"
class="min-h-[42px] px-3 py-2 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg cursor-pointer hover:border-gray-400 dark:hover:border-gray-500 focus:outline-none"
:class="{ 'ring-2 ring-purple-500 border-transparent': isOpen }"
>
<div class="flex flex-wrap gap-1">
<template x-for="value in {{ selected_var }}" :key="value">
<span class="inline-flex items-center px-2 py-1 text-xs font-medium text-purple-700 bg-purple-100 rounded-full dark:bg-purple-900/30 dark:text-purple-300">
<span x-text="getLabel(value)"></span>
<button
type="button"
@click.stop="removeOption(value)"
class="ml-1 hover:text-purple-900 dark:hover:text-purple-100"
>
<svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
</svg>
</button>
</span>
</template>
<span x-show="{{ selected_var }}.length === 0" class="text-gray-400 text-sm py-0.5">{{ placeholder }}</span>
</div>
</div>
{# Dropdown #}
<div
x-show="isOpen"
x-transition
class="absolute z-50 w-full mt-1 bg-white dark:bg-gray-800 rounded-lg shadow-lg border border-gray-200 dark:border-gray-700 max-h-60 overflow-y-auto"
>
<template x-for="option in {{ options_var }}" :key="option.{{ value_key }}">
<button
type="button"
@click="toggleOption(option)"
{% if max_items %}:disabled="{{ selected_var }}.length >= {{ max_items }} && !isSelected(option.{{ value_key }})"{% endif %}
class="flex items-center justify-between w-full px-4 py-2 text-sm text-left transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
:class="isSelected(option.{{ value_key }})
? 'bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300'
: 'text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700'"
>
<span x-text="option.{{ label_key }}"></span>
<svg
x-show="isSelected(option.{{ value_key }})"
class="w-4 h-4 text-purple-600"
fill="none" stroke="currentColor" viewBox="0 0 24 24"
>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
</svg>
</button>
</template>
</div>
</div>
</label>
{% if max_items %}
<p class="text-xs text-gray-500 dark:text-gray-400 mt-1">
<span x-text="{{ selected_var }}.length"></span> / {{ max_items }} selected
</p>
{% endif %}
</div>
{% endmacro %}

View File

@@ -48,6 +48,76 @@
{% 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') %}
<thead>
<tr class="text-xs font-semibold tracking-wide text-left text-gray-500 uppercase border-b dark:border-gray-700 bg-gray-50 dark:text-gray-400 dark:bg-gray-800">
{% for col in columns %}
<th class="px-4 py-3 {{ col.width if col.width else '' }}">
{% if col.sortable %}
<button
@click="{{ on_sort }}('{{ col.key }}')"
class="flex items-center space-x-1 hover:text-gray-700 dark:hover:text-gray-200 transition-colors group"
>
<span>{{ col.label }}</span>
<span class="flex flex-col">
<svg
class="w-3 h-3 -mb-1 transition-colors"
:class="{{ sort_key_var }} === '{{ col.key }}' && {{ sort_dir_var }} === 'asc' ? 'text-purple-600 dark:text-purple-400' : 'text-gray-300 dark:text-gray-600 group-hover:text-gray-400'"
fill="currentColor" viewBox="0 0 20 20"
>
<path d="M5 12l5-5 5 5H5z"/>
</svg>
<svg
class="w-3 h-3 -mt-1 transition-colors"
:class="{{ sort_key_var }} === '{{ col.key }}' && {{ sort_dir_var }} === 'desc' ? 'text-purple-600 dark:text-purple-400' : 'text-gray-300 dark:text-gray-600 group-hover:text-gray-400'"
fill="currentColor" viewBox="0 0 20 20"
>
<path d="M15 8l-5 5-5-5h10z"/>
</svg>
</span>
</button>
{% else %}
{{ col.label }}
{% endif %}
</th>
{% endfor %}
</tr>
</thead>
{% endmacro %}
{#
Table Body Wrapper
==================