-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test search dropdown live * working searchbar * live SearchDropdown * live SearchDropdown wip * live SearchDropdown wip --------- Co-authored-by: Lucanis <[email protected]>
- Loading branch information
Showing
6 changed files
with
217 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,55 @@ | ||
{% set type = type|default('classic') %} {# type: 'classic'|'white' #} | ||
{% set type = type|default('classic') %} | ||
{# type: 'classic'|'white' #} | ||
{% set value = value|default('') %} | ||
|
||
{% set classes = '' %} | ||
{% if type != 'classic' %}{% set classes = classes ~ ' SearchBar--' ~ type %}{% endif %} | ||
{% if type != 'classic' %} | ||
{% set classes = classes ~ ' SearchBar--' ~ type %} | ||
{% endif %} | ||
|
||
<label class="SearchBar {{ classes }}" aria-label={{"Search"|trans}}> | ||
<button class='w-4 h-4'>{{ ux_icon("search") }}</button> | ||
<input type="text" name="query" placeholder={{"e.g. Shoes, T-shirts, ..."|trans}} autocomplete='off' value="{{ value }}"/> | ||
</label> | ||
<div {{ attributes }} class="w-[500px] 2xl:w-[800px] z-50 self-center"> | ||
<label class="SearchBar" aria-label={{"Search"|trans}}> | ||
<button class='w-4 h-4'>{{ ux_icon("search") }}</button> | ||
<input type="text" name="query" placeholder={{"e.g. Shoes, T-shirts, ..."|trans}} autocomplete='off' data-model="debounce(300)|query"/> | ||
</label> | ||
|
||
{% if this.products|length > 0 or this.categories|length > 0 %} | ||
<div class="SearchDropdown"> | ||
<div class="SearchDropdown-results-grid"> | ||
<div class="mb-8 SearchDropdown-results-products"> | ||
<div class="mb-[14px] text-sm uppercase text-grey"> | ||
Produits | ||
</div> | ||
|
||
{% if this.products|length == 0 %} | ||
<div class="font-medium">Aucun résultat pour cette recherche</div> | ||
{% else %} | ||
<div class="SearchDropdown-results"> | ||
{% for product in this.products %} | ||
{% include '@components/Organisms/ProductCard/ProductCard.html.twig' with product %} | ||
{% endfor %} | ||
</div> | ||
{% endif %} | ||
</div> | ||
<div class="mb-8 SearchDropdown-results-categories"> | ||
<div class="mb-[14px] uppercase text-grey text-sm">Catégories</div> | ||
|
||
<div class="SearchDropdown-results"> | ||
<div class="SearchDropdown-results-categories-list"> | ||
{% for category in this.categories %} | ||
<a href={{category.publicUrl}} class="underline" key={result.id}> | ||
{{category.i18ns.title}} | ||
</a> | ||
{% endfor %} | ||
</div> | ||
</div> | ||
</div> | ||
{% if this.products|length > 4 %} | ||
<a href="/search?query={{query}}" class="mx-auto mt-8 Button"> | ||
Voir tous les produits | ||
</a> | ||
{% endif %} | ||
</div> | ||
</div> | ||
{% endif %} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Thelia package. | ||
* http://www.thelia.net | ||
* | ||
* (c) OpenStudio <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FlexyBundle\Twig; | ||
|
||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; | ||
use Symfony\UX\LiveComponent\Attribute\LiveProp; | ||
use Symfony\UX\LiveComponent\DefaultActionTrait; | ||
use TwigEngine\Service\DataAccess\DataAccessService; | ||
|
||
#[AsLiveComponent(template: '@components/Molecules/SearchBar/SearchBar.html.twig')] | ||
class SearchBar | ||
{ | ||
use DefaultActionTrait; | ||
|
||
#[LiveProp(writable: true)] | ||
public string $query = ''; | ||
|
||
private DataAccessService $dataAccessService; | ||
|
||
public function __construct(DataAccessService $dataAccessService) | ||
{ | ||
$this->dataAccessService = $dataAccessService; | ||
} | ||
|
||
public function getProducts(): array | ||
{ | ||
if (empty($this->query)) { | ||
return []; | ||
} | ||
|
||
return $this->dataAccessService->resources('/api/front/products', ['title' => $this->query, "limit" => 4]); | ||
} | ||
|
||
public function getCategories(): array | ||
{ | ||
if (empty($this->query)) { | ||
return []; | ||
} | ||
|
||
return $this->dataAccessService->resources('/api/front/categories', ['title' => $this->query, "limit" => 4]); | ||
} | ||
} |