{# Button Macros ============= Reusable button components for actions, navigation, and forms. Usage: {% from 'shared/macros/buttons.html' import btn, btn_primary, btn_secondary, btn_danger, action_button %} {{ btn_primary('Save Changes', icon='save', type='submit') }} {{ btn_secondary('Cancel', href='/back') }} {{ btn_danger('Delete', onclick='deleteItem()') }} {{ action_button('eye', 'viewItem()', 'blue', 'View details') }} #} {# Base Button =========== A flexible button component that can be styled as primary, secondary, etc. Parameters: - text: Button text - variant: 'primary' | 'secondary' | 'danger' | 'success' | 'warning' | 'ghost' (default: 'primary') - size: 'sm' | 'md' | 'lg' (default: 'md') - icon: Icon name (optional, uses $icon helper) - icon_position: 'left' | 'right' (default: 'left') - type: 'button' | 'submit' | 'reset' (default: 'button') - href: If provided, renders as tag instead of {% endif %} {% endmacro %} {# Convenience macros for common button types #} {% macro btn_primary(text, icon=none, icon_position='left', type='button', href=none, onclick=none, disabled=none, loading=none, size='md') %} {{ btn(text, 'primary', size, icon, icon_position, type, href, onclick, disabled, loading) }} {% endmacro %} {% macro btn_secondary(text, icon=none, icon_position='left', type='button', href=none, onclick=none, disabled=none, loading=none, size='md') %} {{ btn(text, 'secondary', size, icon, icon_position, type, href, onclick, disabled, loading) }} {% endmacro %} {% macro btn_danger(text, icon=none, icon_position='left', type='button', href=none, onclick=none, disabled=none, loading=none, size='md') %} {{ btn(text, 'danger', size, icon, icon_position, type, href, onclick, disabled, loading) }} {% endmacro %} {% macro btn_success(text, icon=none, icon_position='left', type='button', href=none, onclick=none, disabled=none, loading=none, size='md') %} {{ btn(text, 'success', size, icon, icon_position, type, href, onclick, disabled, loading) }} {% endmacro %} {% macro btn_ghost(text, icon=none, icon_position='left', type='button', href=none, onclick=none, disabled=none, loading=none, size='md') %} {{ btn(text, 'ghost', size, icon, icon_position, type, href, onclick, disabled, loading) }} {% endmacro %} {# Action Button (Icon Only) ========================= A small icon button for table actions (view, edit, delete). Parameters: - icon: Icon name - onclick: JavaScript onclick handler - color: 'blue' | 'purple' | 'red' | 'green' | 'gray' (default: 'gray') - title: Tooltip text - disabled: Alpine.js expression for disabled state - href: If provided, renders as tag #} {% macro action_button(icon, onclick=none, color='gray', title='', disabled=none, href=none) %} {% set colors = { 'blue': 'text-blue-600 hover:bg-blue-50 dark:text-blue-400 dark:hover:bg-gray-700', 'purple': 'text-purple-600 hover:bg-purple-50 dark:text-purple-400 dark:hover:bg-gray-700', 'red': 'text-red-600 hover:bg-red-50 dark:text-red-400 dark:hover:bg-gray-700', 'green': 'text-green-600 hover:bg-green-50 dark:text-green-400 dark:hover:bg-gray-700', 'gray': 'text-gray-600 hover:bg-gray-50 dark:text-gray-400 dark:hover:bg-gray-700', 'orange': 'text-orange-600 hover:bg-orange-50 dark:text-orange-400 dark:hover:bg-gray-700' } %} {% set base_classes = 'flex items-center justify-center p-2 rounded-lg focus:outline-none transition-colors disabled:opacity-50 disabled:cursor-not-allowed' %} {% if href %} {% else %} {% endif %} {% endmacro %} {# Action Button Group =================== A group of action buttons (typically for table rows). Usage: {{ action_button_group([ {'icon': 'eye', 'onclick': 'view(item)', 'color': 'blue', 'title': 'View'}, {'icon': 'edit', 'onclick': 'edit(item)', 'color': 'purple', 'title': 'Edit'}, {'icon': 'delete', 'onclick': 'delete(item)', 'color': 'red', 'title': 'Delete'} ]) }} #} {% macro action_button_group(buttons) %}
{% for button in buttons %} {{ action_button( button.icon, button.get('onclick'), button.get('color', 'gray'), button.get('title', ''), button.get('disabled'), button.get('href') ) }} {% endfor %}
{% endmacro %} {# Button Group ============ A group of buttons with proper spacing. #} {% macro button_group(class_extra='') %}
{{ caller() }}
{% endmacro %} {# Back Button =========== A standardized back navigation button. Parameters: - href: URL to navigate back to - text: Button text (default: 'Back') #} {% macro back_button(href, text='Back') %} {{ text }} {% endmacro %} {# Submit Button with Loading ========================== A form submit button with built-in loading state. Parameters: - text: Button text - loading_text: Text shown while loading (default: 'Saving...') - loading_var: Alpine.js variable for loading state (default: 'saving') - icon: Icon name (default: 'save') #} {% macro submit_button(text='Save', loading_text='Saving...', loading_var='saving', icon='save') %} {% endmacro %}