Add <twig:Turbo:Stream:*> components#2227
Conversation
Kocal
left a comment
There was a problem hiding this comment.
LGTM, can you add some tests to check that components nicely render please?
Thanks :)
|
I don't know if the symfony phpstorm plugin works with third party components, but it might incorrectly offer autocompletions for all properties on all components, because they're inherited from TurboStreamComponent. |
4fe373d to
56fea2e
Compare
<twig:turbo-stream-*> components<twig:Turbo:Stream:*> components
|
I figured out I could use anonymous twig components, so here we are. Tags are now like: <twig:Turbo:Stream:Append target="#some-id">
<div>Append this</div>
</twig:Turbo:Stream:Append> |
56fea2e to
c192166
Compare
Is there a specific reason why the attribute is called |
c192166 to
2fa8803
Compare
Good question. Turbo accepts both target and targets. The former accepts an HTML id, the latter a CSS selector. I'm for not supporting Turbo's target attribute. |
I think Nevertheless, great DX improvements with the two PR's 👍 |
8ca1361 to
1c2205c
Compare
f9b54e8 to
b4aa5c2
Compare
|
#2230 should be fixed for tests to be green. |
de35442 to
be54f18
Compare
|
All green :) |
be54f18 to
bfdbb46
Compare
|
PR rebased and conflicts fixed, I merge when the CI is green. |
|
Thank you Nicolas! :) |
|
Is there any benefit from these components in a real application? This package can also be used without TwigComponent. Maybe we should be closer to the package https://github.com/hotwired/turbo-rails? |
|
The benefit is structured declaration: you cannot make a typo, the IDE can help you, etc. |
|
I don't about the turbo-rails package, so feel free to open issues/PRs with the specific things you think would be useful for Symfony apps. I'd be happy to review them. |
You right, but twig component not part of twig(I hope this will change) how blade+components in laravel. In projects where not used twig components will have to install +1 package, this could be a problem. Instead, we can use only twig functions: {% turbo_stream 'apend', dom_id(todo) %}
{% turbo_frame_tag 'target' %}I don't mind twig components with html syntax, but look at PR twigphp/Twig#3867 (comment) there are some problems with this. My idea is to use standard features twig to cover as many projects as possible. |
|
I love this PR, and this is such a good example of anonymous components exposed by bundles ! (thanks @yceruto again) (note to myself: I'm thinking we should use this in the documentation to illustrate!) Thank you @nicolas-grekas ❤️ |
|
Also, in my mind there is no "feature" here that would need to be delivered without TwigComponent. Anyone can do something similar with pure Twig if they want (via embeds or macros).. but for those who have the TwigComponent installed, it's a great sugar syntax / DX improvement.
You then can use It is 100.00% compatible with Twig standard features and will stay this way. |
…dre) This PR was merged into the 2.x branch. Discussion ---------- [Turbo] Document `<twig:Turbo:Stream:*>` Hi, I added docs for #2227. I will document `<twig:Turbo:Stream>` in a second phase. What do you think? Do you have any suggestions? Close #2315 Commits ------- f572ab5 Update src/Turbo/doc/index.rst 79a0180 Remove too many links 8441ec3 Document <twig:Turbo:Stream:*>
…dre) This PR was merged into the 2.x branch. Discussion ---------- [Turbo] Document `<twig:Turbo:Stream:*>` Hi, I added docs for symfony/ux#2227. I will document `<twig:Turbo:Stream>` in a second phase. What do you think? Do you have any suggestions? Close #2315 Commits ------- f572ab5e78a Update src/Turbo/doc/index.rst 79a01807bc4 Remove too many links 8441ec3eafc Document <twig:Turbo:Stream:*>
This PR provides Twig components for turbo-streams:
Sibling PR to #2196
See #2196 (comment) for some background.