-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[11.x] allow guessing of nested component #52669
[11.x] allow guessing of nested component #52669
Conversation
sometimes components will be part of a larger component grouping, and you may wish to group those components in a folder. as a simple example we'll use the classic "Card" component, which may be organized as such: - `App\View\Components\Card\Card` - `App\View\Components\Card\Header` - `App\View\Components\Card\Body` to utilize these in your Blade file you would: ```blade <x-card.card> <x-card.header>Title</x-card.header> <x-card.body>lorem ipsum</x-card.body> </x-card.card> ``` while this is fine, it doesn't read as nice as it could. with this commit, we can now omit the trailing duplicated word, as long as the class name matches the folder name. ```blade <x-card> <x-card.header>Title</x-card.header> <x-card.body>lorem ipsum</x-card.body> </x-card> ``` we do something similar with [Anonymous components](https://laravel.com/docs/11.x/blade#anonymous-index-components)
This feels like magic; how about creating |
@bert-w the point of this is to avoid that, and be able to group you components appropriately. it's the same as what we do with anonymous components. |
hm this does introduce a conflict however if you have both |
Think we would probably want a test here. |
@bert-w correct. I addressed that in my original comment. someone please check my work on this test. I was not able to figure out how to get it to work with the aliases |
@browner12, I have a sincere question! Won't we have some kind of "conflict" with this PR? I mean, your example: <x-card>
<x-card.header>Title</x-card.header>
<x-card.body>lorem ipsum</x-card.body>
</x-card> ... won't it result in the component being understood as anonymous, possibly invoking |
From how I'm reading the class, the anonymous check happens after my check, and all the other class based checks. Let me know if you're reading it differently. However, you might be able to consider this a BC break (?) under the following scenario:
Prior to the change if you included Although that seems like a very unlikely contrived example. I'll leave it to @taylorotwell to judge if that justifies pushing to 12.x |
@browner12 do you think it's possible to make anonymous components consistent? Right now we require the anon component to be named |
@taylorotwell it definitely looks possible to support the folder name convention for anonymous components. I believe we would just need to adjust the It seem unlikely, and very odd that someone would intentionally use both the "index" and "folder" name in their view folder for anonymous components as it doesn't make a ton of sense semantically.
However, I believe we would still be okay as long as we give the I will say I don't use the alias feature for 3rd party custom components, so I'm not sure if that would be affected any differently. I would propose we add this feature in a separate PR if you'd like to go forward with it. |
I think I would rather see it in this PR if that's alright - since I wouldn't merge this one without the other change because of the inconsistency. |
gotcha, fair. I'll work on that. |
per @taylorotwell s request, allow users to name their root components with `index.blade.php` OR the name of the component folder.
these are copy/paste adjustments of the existing "index" tests.
@taylorotwell the anonymous components now support using the folder name instead of
and then use it like this still: <x-accordion>
<x-accordion.item>Item 1</x-accordion.item>
<x-accordion.item>Item 2</x-accordion.item>
<x-accordion.item>Item 3</x-accordion.item>
</x-accordion> the |
Thanks! |
* allow guessing of nested component sometimes components will be part of a larger component grouping, and you may wish to group those components in a folder. as a simple example we'll use the classic "Card" component, which may be organized as such: - `App\View\Components\Card\Card` - `App\View\Components\Card\Header` - `App\View\Components\Card\Body` to utilize these in your Blade file you would: ```blade <x-card.card> <x-card.header>Title</x-card.header> <x-card.body>lorem ipsum</x-card.body> </x-card.card> ``` while this is fine, it doesn't read as nice as it could. with this commit, we can now omit the trailing duplicated word, as long as the class name matches the folder name. ```blade <x-card> <x-card.header>Title</x-card.header> <x-card.body>lorem ipsum</x-card.body> </x-card> ``` we do something similar with [Anonymous components](https://laravel.com/docs/11.x/blade#anonymous-index-components) * minor formatting * add test for nested default component parsing * minor formatting * allow using folder name for anonymous index components per @taylorotwell s request, allow users to name their root components with `index.blade.php` OR the name of the component folder. * fix tests the code changes add an extra `exists()` call, so we'll adjust our numbers here. * add some tests these are copy/paste adjustments of the existing "index" tests.
This doesn't seem to work with correctly with vendor prefixes, when I've More info: rapidez/blade-components#6 |
thanks for catching that @royduin . I was curious how the vendor prefixes would do with this. Luckily it looks like it doesn't break any existing behavior, so we just need to fix it for the new behavior. |
Hey @browner12, do we needs some docs on this? Currently it's undocumented. |
yup, was just thinking about that today. i'll get on it |
we can now use either `index.blade.php` or `{directory}.blade.php` for our anonymous index components. laravel/framework#52669
* new allowed filename for anonymous index components we can now use either `index.blade.php` or `{directory}.blade.php` for our anonymous index components. laravel/framework#52669 * Update blade.md --------- Co-authored-by: Taylor Otwell <[email protected]>
* document "index" class components laravel/framework#52669 * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
sometimes components will be part of a larger component grouping, and you may wish to group those components in a folder.
as a simple example we'll use the classic "Card" component, which may be organized as such:
App\View\Components\Card\Card
App\View\Components\Card\Header
App\View\Components\Card\Body
to utilize these in your Blade file you would:
while this is fine, it doesn't read as nice as it could. with this commit, we can now omit the trailing duplicated word, as long as the class name matches the folder name.
we do something similar with Anonymous components
If a component at the root level exists with the same name as the folder, it will take precedence.
Tried to write a test for this, but was honestly a little lost.