-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[8.x] Consume Blade Directive #39080
Conversation
Amazing @taylorotwell Is it possible to access recursively? <x-menu color="blue">
<x-menu.item>
<x-link>Acceess here color</x-lik>
</x-menu.item>
...
</x-menu> |
In your example, you are at a level where you already have access to the color - so just type it in? <x-menu color="blue">
<x-menu.item>
<x-link>blue</x-lik>
</x-menu.item>
...
</x-menu> |
This is a great one..👍 |
@inxilpro yeah I think this whole idea needs a bit more work IMO. Spatie took a |
So in this specific example would this implementation not work with the tailwind tree shaking? I realize that this is just an example and an actual implementation could be used in the abstract and so this feature will still be awesome to have available. 🤙🏻 |
@taylorotwell Another related issue would be slot props laravel/ideas#2116 (comment) has a package does this https://github.com/konradkalemba/blade-components-scoped-slots could be part of the core? |
It seems like a child component could theoretically call abstract class Component
{
protected $consumes = [];
public function data()
{
$this->attributes = $this->attributes ?: $this->newAttributeBag();
return array_merge(
$this->extractPublicProperties(),
$this->extractPublicMethods(),
$this->getConsumableComponentData()
);
}
protected function getConsumableComponentData()
{
return View::getConsumableComponentData($this->consumes);
}
} |
@inxilpro if the child is an anonymous component that unfortunately doesn't solve the issue |
But doesn't |
No - it mainly only addresses it for slots sadly. For example: <div>
<x-menu-item />
</div> If this code example is the source of the parent component, that |
Ooh. I have an idea! How would you feel if this just worked implicitly? For example, in the code sample above |
@inxilpro I'm not entirely opposed to that if you want to PR it to this branch. |
@taylorotwell take a look at #39092 when you have a chance. |
Alright. I put together one more try with #39100. |
From an idea by @calebporzio ...
When building complex Blade components, it's hard / impossible to access data passed into the parent from children in the parent's slot.
For a concrete example of the problem (using a
x-menu
component):Usage
Notice we are passing in a "color" attribute to the parent component. Here's the parent component definition:
x-menu
Now this component has access to
$color
, but it doesn't actually need it. We need to access$color
from eachmenu-item
component:x-menu.item
Can now be done via
@consume
directive in the child... defaults are also supported if no consumable data with the given name can be found in the parent component stack...x-menu.item