{% extends 'base.html.twig' %} {% block title %}Search Bar - Design System - Bubul{% endblock %} {% block body %}
{# ===== HEADER ===== #}
Molécules /

Search Bar

Barre de recherche avec fonctionnalités avancées

{# ===== COMPOSITION ===== #}

Composition

Icon + Input + Button + Kbd = SearchBar
{# ===== USAGE ===== #}

Usage

{% verbatim %}{% include '_molecules/search-bar/search-bar.html.twig' with {
    placeholder: 'Rechercher un cours...',
    action: '/courses',
    showShortcut: true,
    clearable: true
} %}{% endverbatim %}

Fichier : templates/_molecules/search-bar/search-bar.html.twig

{# ===== EXEMPLE SIMPLE ===== #}

Exemple simple

{% include '_molecules/search-bar/search-bar.html.twig' with { placeholder: 'Rechercher...', action: '#' } %}
{# ===== VARIANTES ===== #}

Variantes

Paramètre : variant

Default

{% include '_molecules/search-bar/search-bar.html.twig' with { placeholder: 'Rechercher...', variant: 'default' } %}

Bordered

{% include '_molecules/search-bar/search-bar.html.twig' with { placeholder: 'Rechercher...', variant: 'bordered' } %}

Filled (sur fond sombre)

{% include '_molecules/search-bar/search-bar.html.twig' with { placeholder: 'Rechercher...', variant: 'filled' } %}
{# ===== TAILLES ===== #}

Tailles

Paramètre : size

Small (sm)

{% include '_molecules/search-bar/search-bar.html.twig' with { placeholder: 'Rechercher...', size: 'sm' } %}

Medium (md) - défaut

{% include '_molecules/search-bar/search-bar.html.twig' with { placeholder: 'Rechercher...', size: 'md' } %}

Large (lg)

{% include '_molecules/search-bar/search-bar.html.twig' with { placeholder: 'Rechercher...', size: 'lg' } %}
{# ===== AVEC BOUTON ===== #}

Avec bouton

Paramètre : showButton: true

{% include '_molecules/search-bar/search-bar.html.twig' with { placeholder: 'Rechercher un cours, un module...', showButton: true, buttonText: 'Rechercher', action: '#' } %}
{# ===== AVEC RACCOURCI CLAVIER ===== #}

Avec raccourci clavier

Paramètre : showShortcut: true

{% include '_molecules/search-bar/search-bar.html.twig' with { placeholder: 'Rechercher...', showShortcut: true, shortcut: '⌘K' } %}

Le raccourci est masqué sur mobile pour économiser l'espace.

{# ===== AVEC VALEUR INITIALE ===== #}

Avec valeur pré-remplie

Le bouton clear apparaît quand il y a du texte

{% include '_molecules/search-bar/search-bar.html.twig' with { placeholder: 'Rechercher...', value: 'Symfony', clearable: true } %}
{# ===== CAS D'USAGE HEADER ===== #}

Cas d'usage : Header

{# Simulation d'un header #}
{% include '_atoms/icon/icon.html.twig' with { name: 'bubul-logo', size: 'xl', color: 'primary' } only %} Bubul
{% include '_molecules/search-bar/search-bar.html.twig' with { placeholder: 'Rechercher dans Bubul...', showShortcut: true, variant: 'filled', action: '#' } %}
{% include '_atoms/button/button.html.twig' with { icon: 'bell', variant: 'ghost', size: 'sm' } only %} {% include '_atoms/avatar/avatar.html.twig' with { initials: 'JD', size: 'sm' } only %}
{# ===== PARAMÈTRES ===== #}

Paramètres

Paramètre Type Défaut Description
placeholderstring'Rechercher...'Texte du placeholder
valuestring''Valeur initiale
namestring'q'Nom du champ
actionstringnullURL du formulaire
showButtonboolfalseAfficher bouton submit
buttonTextstring'Rechercher'Texte du bouton
showShortcutboolfalseAfficher raccourci
shortcutstring'⌘K'Raccourci affiché
instantboolfalseRecherche temps réel
clearablebooltrueBouton effacer
sizestring'md'sm, md, lg
variantstring'default'default, bordered, filled
classstring''Classes additionnelles
{# ===== API JAVASCRIPT ===== #}

API JavaScript (instant search)

// Écouter les recherches instantanées (avec debounce 300ms)
document.getElementById('my-search').addEventListener('instantSearch', (e) => {
    console.log('Recherche:', e.detail.query);
    // Effectuer la recherche AJAX...
});
{% endblock %}