响应式 Twig 模板

一个互动式 UI
PHP Twig 中

在舒适的 Symfony 环境中开发你的界面。
无需 Javascript。

composer require symfony/ux-live-component
// ... use statements hidden - click to show
use App\Service\UxPackageRepository; use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; use Symfony\UX\LiveComponent\Attribute\LiveProp; use Symfony\UX\LiveComponent\DefaultActionTrait;

#[AsLiveComponent('SearchPackages', template: 'components/Package/SearchPackages.html.twig')]
class SearchPackages
{
    use DefaultActionTrait;

    #[LiveProp(writable: true, url: true)]
    public ?string $query = null;

    public function __construct(private UxPackageRepository $packageRepo)
    {
    }

    public function getPackages(): array
    {
        return $this->packageRepo->findAll($this->query);
    }
}
<div{{ attributes }}>

    <input type="text"  data-model="query" placeholder="Results update as you type..." class="form-control" />

    <div class="PackageList pt-3" data-loading="addClass(opacity-50)">
        {% for package in computed.packages %}
            {{ include('components/Package/PackageListItem.html.twig', {package}) }}
         {% else %}
            No packages found "{{ query }}"
        {% endfor %}
    </div>

</div>

安装它

$ composer require symfony/ux-live-component

Live Component 演示

了解您还可以构建什么

阅读完整文档
Infinite Scroll - 2/2 demo preview

无限滚动 - 2/2

滚动加载、灵活的布局网格、多彩的加载动画以及... 更多 T 恤衫!

grid pagination loading scroll

Infinite Scroll - 1/2 demo preview

无限滚动 - 1/2

当您向下滚动页面时加载更多项目。

grid pagination navigation

Live Memory Card Game demo preview

Live Memory Card Game

使用 Live Components 打造令人难忘的游戏 UX!

game time events LiveAction

Auto-Validating Form demo preview

自动验证表单

创建一个表单,当用户输入数据时,实时验证每个字段!

form validation inline

Dependent Form Fields demo preview

依赖表单字段

选择第一个字段后,自动重新加载第二个字段的选项。

form field events

Inline Editing demo preview

在线编辑

激活具有实时验证的在线编辑表单。

form inline LiveAction

Auto-Updating Chart demo preview

自动更新图表

实时渲染和更新 Chart.js 图表。

chart data LiveAction stimulus

Invoice Creator demo preview

发票创建器

创建一个发票 + 行项目,并在您键入时更新。

form entity events LiveAction

Uploading files demo preview

上传文件

通过 LiveAction 从您的 live component 上传文件。

form file upload LiveAction