Files
orion/app/templates/shared/macros/cards.html
Samir Boulahtit 64ab9031d2 feat: add shared Jinja macros for reusable UI components
Add comprehensive macro library in app/templates/shared/macros/:

- pagination.html: pagination(), pagination_simple()
- alerts.html: loading_state(), error_state(), alert(), toast()
- badges.html: badge(), status_badge(), role_badge(), severity_badge()
- buttons.html: btn(), btn_primary(), btn_danger(), action_button()
- forms.html: form_input(), form_select(), form_textarea(), form_toggle()
- tables.html: table_wrapper(), table_header(), table_empty_state()
- cards.html: stat_card(), card(), info_card(), filter_card()
- headers.html: page_header(), section_header(), breadcrumbs()

These macros standardize TailAdmin styling with Alpine.js integration
and dark mode support, reducing code duplication across templates.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-06 18:34:59 +01:00

207 lines
6.6 KiB
HTML

{#
Card Macros
===========
Reusable card components including stats cards, info cards, and action cards.
Usage:
{% from 'shared/macros/cards.html' import stat_card, info_card, card %}
{{ stat_card('users', 'Total Users', 'stats.total', 'blue') }}
{{ info_card('User Details', 'View and edit user information') }}
#}
{#
Stat Card
=========
A statistics card with icon and value.
Parameters:
- icon: Icon name
- label: Card label/title
- value: Alpine.js expression for the value
- color: 'orange' | 'green' | 'blue' | 'purple' | 'red' | 'yellow' (default: 'orange')
- format: Optional format function to apply to value
#}
{% macro stat_card(icon, label, value, color='orange', format=none) %}
{% 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="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
<div class="p-3 mr-4 rounded-full {{ colors[color] }}">
<span x-html="$icon('{{ icon }}', 'w-5 h-5')"></span>
</div>
<div>
<p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">
{{ label }}
</p>
<p class="text-lg font-semibold text-gray-700 dark:text-gray-200"
x-text="{% if format %}{{ format }}({{ value }}){% else %}{{ value }} || 0{% endif %}">
0
</p>
</div>
</div>
{% endmacro %}
{#
Stats Grid
==========
A grid container for stat cards.
Parameters:
- columns: Number of columns (default: 4)
#}
{% macro stats_grid(columns=4) %}
{% set col_classes = {
2: 'md:grid-cols-2',
3: 'md:grid-cols-3',
4: 'md:grid-cols-2 xl:grid-cols-4'
} %}
<div class="grid gap-6 mb-8 {{ col_classes.get(columns, 'md:grid-cols-4') }}">
{{ caller() }}
</div>
{% endmacro %}
{#
Card
====
A basic card container.
Parameters:
- title: Card title (optional)
- subtitle: Card subtitle (optional)
- class_extra: Additional CSS classes
- padding: Whether to add padding (default: true)
#}
{% macro card(title=none, subtitle=none, class_extra='', padding=true) %}
<div class="bg-white rounded-lg shadow-xs dark:bg-gray-800 {{ 'p-6' if padding else '' }} {{ class_extra }}">
{% if title %}
<div class="{% if padding %}{% else %}p-4 border-b dark:border-gray-700{% endif %}">
<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>
{% endif %}
<div class="{% if title and not padding %}p-4{% endif %}">
{{ caller() }}
</div>
</div>
{% endmacro %}
{#
Info Card
=========
An informational card with icon and description.
Parameters:
- icon: Icon name
- title: Card title
- description: Card description
- color: Icon color (default: 'purple')
- href: Optional link URL
#}
{% macro info_card(icon, title, description, color='purple', href=none) %}
{% set colors = {
'purple': 'text-purple-500 bg-purple-100 dark:text-purple-100 dark:bg-purple-500',
'blue': 'text-blue-500 bg-blue-100 dark:text-blue-100 dark:bg-blue-500',
'green': 'text-green-500 bg-green-100 dark:text-green-100 dark:bg-green-500',
'orange': 'text-orange-500 bg-orange-100 dark:text-orange-100 dark:bg-orange-500'
} %}
{% if href %}
<a href="{{ href }}" class="block p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800 hover:shadow-md transition-shadow">
{% else %}
<div class="p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
{% endif %}
<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>
<h4 class="text-lg font-semibold text-gray-700 dark:text-gray-200">{{ title }}</h4>
<p class="text-sm text-gray-600 dark:text-gray-400">{{ description }}</p>
</div>
</div>
{% if href %}
</a>
{% else %}
</div>
{% endif %}
{% endmacro %}
{#
Quick Actions Card
==================
A card with quick action buttons and status badges.
Parameters:
- title: Card title (default: 'Quick Actions')
#}
{% macro quick_actions_card(title='Quick Actions') %}
<div class="px-4 py-3 mb-6 bg-white rounded-lg shadow-md dark:bg-gray-800">
<h3 class="mb-4 text-lg font-semibold text-gray-700 dark:text-gray-200">
{{ title }}
</h3>
<div class="flex flex-wrap items-center gap-3">
{{ caller() }}
</div>
</div>
{% endmacro %}
{#
Coming Soon Card
================
A placeholder card for features under development.
Parameters:
- emoji: Emoji to display
- title: Feature title
- description: Feature description
- back_url: URL for back button
- back_label: Back button text (default: 'Go Back')
#}
{% macro coming_soon_card(emoji='📦', title='Coming Soon', description='This feature is under development.', back_url='/', back_label='Go Back') %}
<div class="w-full mb-8 overflow-hidden rounded-lg shadow-xs">
<div class="w-full p-12 bg-white dark:bg-gray-800 text-center">
<div class="text-6xl mb-4">{{ emoji }}</div>
<h3 class="text-xl font-semibold text-gray-700 dark:text-gray-200 mb-2">
{{ title }}
</h3>
<p class="text-gray-600 dark:text-gray-400 mb-6">
{{ description }}
</p>
<a href="{{ back_url }}"
class="inline-flex items-center px-4 py-2 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-purple-600 border border-transparent rounded-lg hover:bg-purple-700 focus:outline-none focus:shadow-outline-purple">
{{ back_label }}
</a>
</div>
</div>
{% endmacro %}
{#
Filter Card
===========
A card for search and filter controls.
Parameters:
- show_condition: Alpine.js condition (default: '!loading')
#}
{% macro filter_card(show_condition='!loading') %}
<div x-show="{{ show_condition }}" class="mb-6 p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
{{ caller() }}
</div>
</div>
{% endmacro %}