Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add make:twig-component maker #1019

Merged
merged 1 commit into from
Sep 19, 2022
Merged

Conversation

kbond
Copy link
Member

@kbond kbond commented Nov 25, 2021

Adds a maker for symfony/ux-twig-component/symfony/ux-live-component.

Creating a standard twig component:

bin/console make:twig-component

 The name of your twig component (ie NotificationComponent):
 > Notification

 Make this a live component? (yes/no) [no]: # (defaults to yes if symfony/ux-live-component installed)
 > no

 created: src/Twig/Components/NotificationComponent.php
 created: templates/components/notification.html.twig
           
  Success!
// src/Twig/Components/NotificationComponent.php

<?php

namespace App\Twig\Components;

use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent('notification')]
final class NotificationComponent
{
}
{# templates/components/notification.html.twig #}

<div{{ attributes }}>
    <!-- component html -->
</div>

Creating a live twig component:

bin/console make:twig-component --live # fails if symfony/ux-live-component is not installed

 The name of your twig component (ie NotificationComponent):
 > Notification

 created: src/Twig/Components/NotificationComponent.php
 created: templates/components/notification.html.twig
           
  Success!
// src/Twig/Components/NotificationComponent.php

<?php

namespace App\Twig\Components;

use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\DefaultActionTrait;

#[AsLiveComponent('notification')]
final class NotificationComponent
{
    use DefaultActionTrait;
}
{# templates/components/notification.html.twig #}

<div{{ attributes }}>
    <!-- component html -->
</div>

Ref: symfony/ux#108

@kbond
Copy link
Member Author

kbond commented Nov 25, 2021

(I'll add tests once we finalize the maker and stubs)

@jrushlow
Copy link
Collaborator

@kbond - is this ready to move forward? a rebase and tests would be awesome when you get some free time

@jrushlow jrushlow added the Status: Needs Work Additional work is needed label Feb 22, 2022
@jrushlow jrushlow added the Feature New Feature label Mar 3, 2022
@kbond
Copy link
Member Author

kbond commented Sep 12, 2022

Sorry for the delay. Updated this PR to work with the latest version of twig/live components. If we are good with the templates/maker, I'll add tests.

Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great - let's write some tests and good to go 👍

src/Maker/MakeTwigComponent.php Show resolved Hide resolved
@kbond
Copy link
Member Author

kbond commented Sep 14, 2022

Ok, this is ready. Assuming symfony/ux#460 is merged, we can add support for this in the maker.

@weaverryan
Copy link
Member

Test failures unrelated - thanks Kevin!

@weaverryan weaverryan merged commit 2fa4e95 into symfony:main Sep 19, 2022
@weaverryan
Copy link
Member

When this is released, we should update the docs to show this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature Status: Needs Work Additional work is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants