-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[11.x] allow guessing of nested component #52669
base: 11.x
Are you sure you want to change the base?
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. |
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.