Skip to content

[TwigComponent] props reflexion #1387

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

Closed
WebMamba opened this issue Jan 11, 2024 · 7 comments · Fixed by #1652
Closed

[TwigComponent] props reflexion #1387

WebMamba opened this issue Jan 11, 2024 · 7 comments · Fixed by #1652

Comments

@WebMamba
Copy link
Contributor

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?

@smnandre
Copy link
Member

What would be the "rules" ?

@WebMamba
Copy link
Contributor Author

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?

@weaverryan
Copy link
Member

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 :)

@WebMamba
Copy link
Contributor Author

This is not the case, and you actually had this issue during your live coding at the SymfonyCon 😁

@smnandre
Copy link
Member

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 :))

@smnandre
Copy link
Member

Wait.... @weaverryan is right :)

I just added the "foo" as props in the template

Capture d’écran 2024-01-11 à 22 51 24 Capture d’écran 2024-01-11 à 22 51 35

@smnandre
Copy link
Member

Is there something i missed there guys ? @weaverryan @WebMamba

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants