{# # ============================================================================ # MOLECULE: ENROLLED CARD # ============================================================================ # # Carte d'utilisateur inscrit avec avatar, infos, progression et actions. # Idéal pour les listes d'inscrits, cohortes, équipes. # # ============================================================================ # COMPOSITION (Atomes utilisés) # ============================================================================ # # - _atoms/avatar/avatar.html.twig # - _atoms/icon/icon.html.twig # - _molecules/progress-ring/progress-ring.html.twig (optionnel) # - _molecules/action-bar/action-bar.html.twig (optionnel) # # ============================================================================ # PARAMÈTRES # ============================================================================ # # | Paramètre | Type | Défaut | Description | # |---------------|---------|-----------|-----------------------------------| # | name | string | (requis) | Nom de la personne | # | email | string | null | Email ou info secondaire | # | avatar | string | null | URL de l'avatar (ou initiales) | # | initials | string | null | Initiales (si pas d'avatar) | # | progress | number | null | Progression 0-100 (affiche ring) | # | status | string | null | Statut (active, pending, etc.) | # | badge | object | null | Badge { label, variant } | # | actions | array | null | Actions (voir action-bar) | # | href | string | null | URL (rend la carte cliquable) | # | size | string | 'md' | sm, md, lg | # | class | string | '' | Classes additionnelles | # # ============================================================================ # EXEMPLES D'UTILISATION # ============================================================================ # # Simple: # {% include '_molecules/enrolled-card/enrolled-card.html.twig' with { # name: 'Jean Dupont', # email: 'jean@example.com' # } %} # # Avec progression et actions: # {% include '_molecules/enrolled-card/enrolled-card.html.twig' with { # name: 'Marie Martin', # email: 'marie@example.com', # progress: 75, # actions: [ # { icon: 'eye', title: 'Voir', href: '/users/1' }, # { icon: 'trash', title: 'Retirer', variant: 'danger' } # ] # } %} # # Avec badge de statut: # {% include '_molecules/enrolled-card/enrolled-card.html.twig' with { # name: 'Pierre Durand', # email: 'pierre@example.com', # badge: { label: 'Admin', variant: 'primary' } # } %} # # ============================================================================ #} {# ============================================================================ CONFIGURATION DES VALEURS PAR DÉFAUT ============================================================================ #} {% set name = name ?? 'Utilisateur' %} {% set email = email ?? null %} {% set avatar = avatar ?? null %} {% set initials = initials ?? null %} {% set progress = progress ?? null %} {% set status = status ?? null %} {% set badge = badge ?? null %} {% set actions = actions ?? null %} {% set href = href ?? null %} {% set size = size ?? 'md' %} {% set class = class ?? '' %} {# Auto-generate initials if not provided #} {% if not initials and not avatar %} {% set nameParts = name|split(' ') %} {% set initials = (nameParts[0]|first|upper) ~ (nameParts[1] is defined ? nameParts[1]|first|upper : '') %} {% endif %} {# ============================================================================ CLASSES TAILWIND ============================================================================ #} {% set sizeConfig = { 'sm': { 'padding': 'px-3 py-2', 'avatar': 'sm', 'name': 'text-sm', 'email': 'text-xs', 'gap': 'gap-2', 'progressSize': 'sm' }, 'md': { 'padding': 'px-4 py-3', 'avatar': 'md', 'name': 'text-sm', 'email': 'text-xs', 'gap': 'gap-3', 'progressSize': 'sm' }, 'lg': { 'padding': 'px-5 py-4', 'avatar': 'lg', 'name': 'text-base', 'email': 'text-sm', 'gap': 'gap-4', 'progressSize': 'md' } } %} {% set sConfig = sizeConfig[size] ?? sizeConfig['md'] %} {% set statusColors = { 'active': 'bg-green-100 text-green-800', 'pending': 'bg-yellow-100 text-yellow-800', 'inactive': 'bg-gray-100 text-gray-600', 'suspended': 'bg-red-100 text-red-800' } %} {# ============================================================================ RENDU HTML ============================================================================ #} {% set tag = href ? 'a' : 'div' %} <{{ tag }} {% if href %}href="{{ href }}"{% endif %} class="flex items-center {{ sConfig.gap }} {{ sConfig.padding }} bg-white rounded-xl border border-gray-200 {{ href ? 'hover:border-primary/30 hover:shadow-sm transition-all cursor-pointer' : '' }} {{ class }}" > {# Avatar #} {% include '_atoms/avatar/avatar.html.twig' with { src: avatar, initials: initials, alt: name, size: sConfig.avatar } only %} {# Info #}
{{ email }}
{% endif %} {% if status and not badge %} {{ status|capitalize }} {% endif %}