{# # ============================================================================ # ATOM: LABEL # ============================================================================ # # Étiquette de formulaire paramétrable utilisant 100% Tailwind CSS. # Composant autonome pour associer un texte à un champ de formulaire. # # ============================================================================ # PARAMÈTRES # ============================================================================ # # | Paramètre | Type | Défaut | Description | # |----------------|---------|-----------|------------------------------------------| # | text | string | (requis) | Texte du label | # | for | string | null | ID du champ associé (attribut for) | # | required | bool | false | Affiche l'astérisque obligatoire | # | optional | bool | false | Affiche "(optionnel)" | # | size | string | 'md' | Taille: sm, md, lg | # | variant | string | 'default' | Style: default, secondary, inline | # | tooltip | string | null | Texte d'info-bulle | # | icon | string | null | Nom de l'icône avant le texte | # | disabled | bool | false | Style désactivé (grisé) | # | class | string | '' | Classes additionnelles | # # ============================================================================ # EXEMPLES D'UTILISATION # ============================================================================ # # Label simple: # {% include '_atoms/form/label.html.twig' with { # text: 'Adresse email', # for: 'email' # } %} # # Label obligatoire avec tooltip: # {% include '_atoms/form/label.html.twig' with { # text: 'Mot de passe', # for: 'password', # required: true, # tooltip: 'Minimum 8 caractères' # } %} # # Label optionnel: # {% include '_atoms/form/label.html.twig' with { # text: 'Téléphone', # for: 'phone', # optional: true # } %} # # Label avec icône: # {% include '_atoms/form/label.html.twig' with { # text: 'Fichier', # icon: 'file-text', # for: 'file-upload' # } %} # # ============================================================================ #} {# ============================================================================ CONFIGURATION DES VALEURS PAR DÉFAUT ============================================================================ #} {% set text = text ?? '' %} {% set for = for ?? null %} {% set required = required ?? false %} {% set optional = optional ?? false %} {% set size = size ?? 'md' %} {% set variant = variant ?? 'default' %} {% set tooltip = tooltip ?? null %} {% set icon = icon ?? null %} {% set disabled = disabled ?? false %} {% set class = class ?? '' %} {# ============================================================================ CLASSES TAILWIND - TAILLES ============================================================================ #} {% set sizeClasses = { 'sm': 'text-xs', 'md': 'text-sm', 'lg': 'text-base' } %} {% set iconSizes = { 'sm': 'xs', 'md': 'sm', 'lg': 'md' } %} {# ============================================================================ CLASSES TAILWIND - VARIANTES ============================================================================ #} {% set variantClasses = { 'default': 'block font-medium text-gray-700 mb-1.5', 'secondary': 'block font-normal text-gray-500 mb-1', 'inline': 'inline-flex items-center font-medium text-gray-700' } %} {# ============================================================================ CLASSES TAILWIND - ÉTATS ============================================================================ #} {% set disabledClasses = disabled ? 'text-gray-400 cursor-not-allowed' : '' %} {# ============================================================================ ASSEMBLAGE DES CLASSES ============================================================================ #} {% set labelClasses = [ variantClasses[variant] ?? variantClasses['default'], sizeClasses[size] ?? sizeClasses['md'], disabledClasses, class ]|join(' ')|trim %} {# ============================================================================ RENDU HTML ============================================================================ #}