{# # ============================================================================ # ATOM: TOGGLE (Switch) # ============================================================================ # # Interrupteur on/off paramétrable utilisant 100% Tailwind CSS. # # ============================================================================ # PARAMÈTRES # ============================================================================ # # | Paramètre | Type | Défaut | Description | # |-------------|---------|-----------|------------------------------------------| # | label | string | null | Label du toggle | # | checked | bool | false | État activé | # | name | string | null | Attribut name | # | id | string | null | Attribut id | # | value | string | '1' | Valeur quand activé | # | disabled | bool | false | Désactivé | # | error | string | null | Message d'erreur | # | hint | string | null | Texte d'aide | # | size | string | 'md' | Taille: sm, md, lg | # | labelPosition | string | 'right' | Position label: left, right | # | variant | string | 'primary' | Couleur: primary, success, warning | # | class | string | '' | Classes additionnelles | # | attr | object | {} | Attributs HTML additionnels | # # ============================================================================ # EXEMPLES D'UTILISATION # ============================================================================ # # Toggle simple: # {% include '_atoms/form/toggle.html.twig' with { # label: 'Notifications', # name: 'notifications' # } %} # # Toggle activé avec hint: # {% include '_atoms/form/toggle.html.twig' with { # label: 'Mode sombre', # checked: true, # hint: 'Réduit la fatigue oculaire' # } %} # # Toggle success (pour statuts actif/inactif): # {% include '_atoms/form/toggle.html.twig' with { # label: 'Compte actif', # variant: 'success', # checked: user.isActive # } %} # # ============================================================================ #} {# ============================================================================ CONFIGURATION DES VALEURS PAR DÉFAUT ============================================================================ #} {% set label = label ?? null %} {% set checked = checked ?? false %} {% set name = name ?? null %} {% set id = id ?? (name ? 'toggle-' ~ name : 'toggle-' ~ random()) %} {% set value = value ?? '1' %} {% set disabled = disabled ?? false %} {% set error = error ?? null %} {% set hint = hint ?? null %} {% set size = size ?? 'md' %} {% set labelPosition = labelPosition ?? 'right' %} {% set variant = variant ?? 'primary' %} {% set class = class ?? '' %} {% set attr = attr ?? {} %} {# ============================================================================ CLASSES TAILWIND - TAILLES ============================================================================ #} {% set trackSizeClasses = { 'sm': 'w-8 h-5', 'md': 'w-11 h-6', 'lg': 'w-14 h-8' } %} {% set thumbSizeClasses = { 'sm': 'w-3 h-3', 'md': 'w-4 h-4', 'lg': 'w-6 h-6' } %} {% set thumbTranslateClasses = { 'sm': 'peer-checked:translate-x-3.5', 'md': 'peer-checked:translate-x-5', 'lg': 'peer-checked:translate-x-6' } %} {% set labelSizeClasses = { 'sm': 'text-sm', 'md': 'text-base', 'lg': 'text-lg' } %} {# ============================================================================ CLASSES TAILWIND - VARIANTES (couleur quand activé) ============================================================================ #} {% set variantClasses = { 'primary': 'peer-checked:bg-primary', 'success': 'peer-checked:bg-success', 'warning': 'peer-checked:bg-warning', 'error': 'peer-checked:bg-error', 'cohorts': 'peer-checked:bg-cohorts' } %} {# ============================================================================ CLASSES TAILWIND - ÉTATS ============================================================================ #} {% set disabledClasses = disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer' %} {# ============================================================================ RENDU HTML ============================================================================ #}
{# ----- Error message ----- #} {% if error %}

{{ error }}

{% endif %}