akyos / ux-filters
A Symfony bundle to manage filters in live Component
1.0.3
2024-10-30 16:35 UTC
Requires
- php: ^8.0
- symfony/doctrine-bridge: *
- symfony/form: *
- symfony/orm-pack: ^2.4
- symfony/translation: *
- symfony/ux-live-component: ^2.21
This package is auto-updated.
Last update: 2024-10-30 16:35:50 UTC
README
A Symfony bundle to manage filters in live Component
Sample:
Php file
<?php namespace App\Twig\Components\Product; use Akyos\UXFilters\Class\Text; use Akyos\UXFilters\Trait\ComponentWithFilterTrait; use Akyos\UXPagination\Trait\ComponentWithPaginationTrait; use App\Entity\Product; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; use Symfony\UX\LiveComponent\DefaultActionTrait; #[AsLiveComponent] final class Index extends AbstractController { use DefaultActionTrait; use ComponentWithFilterTrait; use ComponentWithPaginationTrait; public function __construct() { $this->repository = Product::class; $this->setLimit(3); } protected function setFilters(): iterable { yield (new Text('name', 'Name'))->setSearchType('like')->setParams([ 'entity.name', 'entity.description', ]); } }
Template
<div{{ attributes }}> {{ form(formFilters) }} {% for product in elements %} <div class="product"> <div class="product__content"> <h3 class="product__title">{{ product.name }}</h3> <p class="product__price">{{ product.description|raw }}</p> <p class="product__price">{{ product.price }}</p> </div> </div> {% endfor %} {{ pagination|raw }} </div>