Skip to content
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

[Proposal] Render slots for components #1389

Closed
assertchris opened this issue Nov 15, 2018 · 3 comments
Closed

[Proposal] Render slots for components #1389

assertchris opened this issue Nov 15, 2018 · 3 comments

Comments

@assertchris
Copy link

@assertchris assertchris commented Nov 15, 2018

Given

I love components, but there's something about them that makes it a little harder to compose them, than the client-side libraries we're used to. There's no way, currently, to use $slot as a function.

I can't, for instance, do this:

@component('components.list', ['items' => $items])
    <!-- treat slot as though it must be rendered once for each item -->
    {{ $item->label }}
@endcomponent

...and then to create that component as:

@foreach($items as $item)
    {{ $slot($item) }}
@endforeach

Propsal

If we add the following blade directive:

screenshot 2018-11-15 at 08 47 51

...and modify the ManagesComponents concern slightly:

screenshot 2018-11-15 at 08 48 26

...then we can make components like this:

screenshot 2018-11-15 at 08 49 15

...which can be used like this:

screenshot 2018-11-15 at 08 49 59

Whaddya think?

@assertchris assertchris changed the title [Proposal] Render children for components [Proposal] Render slots for components Nov 15, 2018
@assertchris
Copy link
Author

@assertchris assertchris commented Nov 15, 2018

Inb4 someone points out you can already do this (slightly less appealing) thing:

screenshot 2018-11-15 at 08 56 30

@tylernathanreed
Copy link

@tylernathanreed tylernathanreed commented Dec 7, 2018

My work around for this involves declaring multiple slots, such as items.0.title, items.0.body, items.1.title, items.1.body. Making this work requires diciphering the $__data variable, which feels for like a hack than a feature.

Having some sort of array-based support for components would be great for accordions, lists, tab panels, etc.

@assertchris
Copy link
Author

@assertchris assertchris commented Jul 20, 2020

If you've landed here, all these years later; I made a stand-alone library that enables this very thing (requires PHP 7.4 and Laravel 7): https://github.com/assertchris/laravel-renderless-components

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

Successfully merging a pull request may close this issue.

None yet
2 participants