{# Flowbite Components Macros Collection de macros Twig pour utiliser facilement les composants Flowbite dans vos templates. Usage: {% import 'flowbite_components/macros.html.twig' as flowbite %} {{ flowbite.alert('success', 'Opération réussie!') }} #} {# Alert Component @param type string - Type d'alerte: 'info', 'success', 'warning', 'error' @param message string - Message à afficher @param dismissible boolean - Si l'alerte peut être fermée @param icon boolean - Afficher l'icône #} {% macro alert(type = 'info', message = '', dismissible = false, icon = true) %} {% set colors = { 'info': {'bg': 'bg-blue-50', 'text': 'text-blue-800', 'border': 'border-blue-300', 'icon': 'fa-info-circle'}, 'success': {'bg': 'bg-green-50', 'text': 'text-green-800', 'border': 'border-green-300', 'icon': 'fa-check-circle'}, 'warning': {'bg': 'bg-yellow-50', 'text': 'text-yellow-800', 'border': 'border-yellow-300', 'icon': 'fa-exclamation-triangle'}, 'error': {'bg': 'bg-red-50', 'text': 'text-red-800', 'border': 'border-red-300', 'icon': 'fa-times-circle'} } %} {% set color = colors[type] ?? colors.info %} {% endmacro %} {# Button Component @param label string - Texte du bouton @param type string - Type de bouton: 'primary', 'secondary', 'success', 'danger', 'warning' @param size string - Taille: 'sm', 'md', 'lg' @param icon string - Classe Font Awesome de l'icône (optionnel) @param attributes string - Attributs HTML supplémentaires #} {% macro button(label, type = 'primary', size = 'md', icon = null, attributes = '') %} {% set colors = { 'primary': 'text-white bg-blue-700 hover:bg-blue-800 focus:ring-blue-300', 'secondary': 'text-gray-900 bg-white border border-gray-300 hover:bg-gray-100 focus:ring-gray-200', 'success': 'text-white bg-green-700 hover:bg-green-800 focus:ring-green-300', 'danger': 'text-white bg-red-700 hover:bg-red-800 focus:ring-red-300', 'warning': 'text-white bg-yellow-400 hover:bg-yellow-500 focus:ring-yellow-300' } %} {% set sizes = { 'sm': 'px-3 py-2 text-xs', 'md': 'px-5 py-2.5 text-sm', 'lg': 'px-5 py-3 text-base' } %} {% endmacro %} {# Badge Component @param label string - Texte du badge @param color string - Couleur: 'blue', 'gray', 'red', 'green', 'yellow', 'indigo', 'purple', 'pink' @param icon string - Classe Font Awesome de l'icône (optionnel) #} {% macro badge(label, color = 'blue', icon = null) %} {% if icon %} {% endif %} {{ label }} {% endmacro %} {# Input Component @param name string - Nom de l'input @param label string - Label de l'input @param type string - Type d'input: 'text', 'email', 'password', 'number', etc. @param placeholder string - Placeholder @param value string - Valeur par défaut @param required boolean - Champ requis @param error string - Message d'erreur (optionnel) @param icon string - Classe Font Awesome de l'icône (optionnel) #} {% macro input(name, label, type = 'text', placeholder = '', value = '', required = false, error = null, icon = null) %}
{% if icon %}
{% else %} {% endif %} {% if error %}

{{ error }}

{% endif %}
{% endmacro %} {# Select Component @param name string - Nom du select @param label string - Label du select @param options array - Options [{value: '', label: ''}] @param selected string - Valeur sélectionnée @param required boolean - Champ requis #} {% macro select(name, label, options = [], selected = '', required = false) %}
{% endmacro %} {# Card Component @param title string - Titre de la card @param content string - Contenu de la card @param footer string - Pied de page (optionnel) @param icon string - Classe Font Awesome de l'icône (optionnel) #} {% macro card(title, content, footer = null, icon = null) %}
{% if icon %} {% endif %}
{{ title }}
{{ content|raw }}
{% if footer %}
{{ footer|raw }}
{% endif %}
{% endmacro %} {# Modal Trigger Button @param modalId string - ID du modal à ouvrir @param label string - Texte du bouton @param type string - Type de bouton @param icon string - Classe Font Awesome de l'icône (optionnel) #} {% macro modalButton(modalId, label, type = 'primary', icon = null) %} {% set colors = { 'primary': 'text-white bg-blue-700 hover:bg-blue-800 focus:ring-blue-300', 'danger': 'text-white bg-red-700 hover:bg-red-800 focus:ring-red-300' } %} {% endmacro %} {# Toast Notification @param type string - Type: 'success', 'error', 'warning', 'info' @param message string - Message à afficher @param dismissible boolean - Si le toast peut être fermé #} {% macro toast(type = 'success', message = '', dismissible = true) %} {% set icons = { 'success': {'icon': 'fa-check', 'color': 'text-green-500 bg-green-100'}, 'error': {'icon': 'fa-times', 'color': 'text-red-500 bg-red-100'}, 'warning': {'icon': 'fa-exclamation-triangle', 'color': 'text-orange-500 bg-orange-100'}, 'info': {'icon': 'fa-info-circle', 'color': 'text-blue-500 bg-blue-100'} } %} {% set config = icons[type] ?? icons.success %} {% endmacro %} {# Breadcrumb Component @param items array - Éléments du breadcrumb [{label: '', url: ''}] #} {% macro breadcrumb(items = []) %} {% endmacro %} {# Progress Bar @param label string - Label de la barre @param percentage int - Pourcentage de progression (0-100) @param color string - Couleur: 'blue', 'green', 'red', 'yellow', 'purple' @param showPercentage boolean - Afficher le pourcentage #} {% macro progressBar(label, percentage, color = 'blue', showPercentage = true) %}
{% if label or showPercentage %}
{% if label %} {{ label }} {% endif %} {% if showPercentage %} {{ percentage }}% {% endif %}
{% endif %}
{% endmacro %} {# Avatar Component @param initials string - Initiales à afficher @param color string - Couleur: 'blue', 'green', 'purple', 'gray' @param online boolean - Afficher l'indicateur en ligne #} {% macro avatar(initials, color = 'blue', online = false) %}
{{ initials }}
{% if online %} {% endif %}
{% endmacro %} {# Breadcrumb Component (Macro version) @param items array - Éléments du breadcrumb [{label: '', url: ''}] Le dernier élément (sans url) représente la page courante Exemple: {{ flowbite.breadcrumb([ {label: 'Accueil', url: path('app_home')}, {label: 'Utilisateurs', url: path('users_list')}, {label: 'Profil'} ]) }} #} {% macro breadcrumb(items = []) %} {% if items|length > 0 %} {% endif %} {% endmacro %} {# Company Logo Component @param company Company - Entité Company @param size string - Taille: 'small' (40px), 'medium' (48px), 'large' (80px), 'xlarge' (96px) @param rounded string - Type d'arrondi: 'rounded' (léger), 'rounded-lg' (moyen), 'rounded-full' (cercle) @param classes string - Classes CSS supplémentaires Exemple: {{ flowbite.company_logo(company, 'large', 'rounded-lg') }} #} {% macro company_logo(company, size = 'medium', rounded = 'rounded-lg', classes = '') %} {% set sizes = { 'small': 'h-10 w-10', 'medium': 'h-12 w-12', 'large': 'h-20 w-20', 'xlarge': 'h-24 w-24' } %} {% set sizeClass = sizes[size] ?? sizes.medium %} {{ company.name }} {% endmacro %} {# User Avatar Component @param user User - Entité User @param size string - Taille: 'small' (32px), 'medium' (40px), 'large' (48px), 'xlarge' (64px) @param showOnline boolean - Afficher l'indicateur en ligne @param classes string - Classes CSS supplémentaires Exemple: {{ flowbite.user_avatar(user, 'medium', true) }} #} {% macro user_avatar(user, size = 'medium', showOnline = false, classes = '') %} {% set sizes = { 'small': 'h-8 w-8 text-xs', 'medium': 'h-10 w-10 text-sm', 'large': 'h-12 w-12 text-base', 'xlarge': 'h-16 w-16 text-lg' } %} {% set sizeClass = sizes[size] ?? sizes.medium %}
{% if user.profilePhoto %} {{ user.firstName ~ ' ' ~ user.lastName }} {% else %}
{{ user.firstName|slice(0, 1)|upper }}{{ user.lastName|slice(0, 1)|upper }}
{% endif %} {% if showOnline and user.isActive %} {% endif %}
{% endmacro %}