ux
ux copied to clipboard
[TwigComponent] props reflexion
Hey! I want your though before to start working on something. Today if you have a TwigComponent
#[AsTwigComponent]
class Button
{
...
}
{% props label %}
<button>
{{ label }}
</button>
The props label defined in the template will not be taken in to account because the Button component is not an anonymous component. What do you think about letting the ability to merge props defined into the template with props defined in the class. If a conflict happen raise an error. WDYT?
What would be the "rules" ?
If you have:
#[AsTwigComponent]
class UserCard
{
public string $user = null;
public string $language = 'fr';
}
{% props size = 'md' %}
// content here
//Then you can access {{ size }} {{ language }} {{ user }}
Do you see what I mean?
I thought it already worked this way? I thought that, even if your component is NOT anonymous, if you have {% props %}
, it would covert anything listed there from an attribute into a prop. Are you sure that's not already the case? Or tell me if I'm misunderstanding the issue also :)
This is not the case, and you actually had this issue during your live coding at the SymfonyCon 😁
In your example can you mount your component with size ? I imagine yes ?
<twig:UserCard size="foo" />
right ?
How would you handle it PHP-side in your mount methods ? DOes it appear in the component Metadata ? In the Events then ? How would it work with LiveComponents ?
Maybe those answers are really simple... but if "not", i fear this add much complexity to a limited gain. I mean, declaring properties in two different places in not the most frequent thing we see right ?
Do you have maybe a full example where that addition feel like a immediate DX improvment ?
(side note: I still think we should have a more distinct usage / interface between pure static components and php ones :))
Wait.... @weaverryan is right :)
I just added the "foo" as props in the template
Is there something i missed there guys ? @weaverryan @WebMamba