-
Notifications
You must be signed in to change notification settings - Fork 428
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
Slots V2 #503
Slots V2 #503
Conversation
ed34155
to
c9a3656
Compare
I really like the |
I like this API much better, including the terminology "renders" over "slots". It actually reminds me quite a bit of ActiveRecord I am curious, what would it look like if somebody wanted to reverse the order of what's rendered from the components |
Thanks for all of your hard work on this! The One of the things I am most excited about with How will the DSL behave when a subclassed component needs to override the slot?
What about templates? If I'm SO THRILLED y'all are working so hard on making this an important part of Rails. I didn't like the Rails view/helper system ten years and I like it even less now. Component-based setups are really awesome way to shore up some of the issues with a viewmodel-less MVC scenario. |
That's a great question. Right now you would you would call That being said, this PR is trending away from slots being their own user defined classes, and more towards being functions that can return HTML or a component instance that will be rendered on the page. I think being able to delegate to an existing component provides an escape hatch for inheritance if it's necessary.
In this example,
Yep! Exactly. I think that should be the existing behavior too.
Thank you! That means a lot. ❤️ |
0774c71
to
424b5a7
Compare
dfbcfca
to
20cff66
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work a couple of questions about details
55f6d2e
to
2491135
Compare
TODO: collection slot rendering:
|
TODO: Add to |
TODO: Add test for subcomponent with |
TODO: Note that slots V1 is deprecated. |
test/app/components/sub_component_component/my_highlight_component.html.erb
Outdated
Show resolved
Hide resolved
71d1e96
to
120d1a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this. This is great.
4b8685f
to
1cb99bc
Compare
Co-authored-by: Joel Hawksley <joelhawksley@github.com>
Co-authored-by: Joel Hawksley <joelhawksley@github.com>
Co-authored-by: Joel Hawksley <joelhawksley@github.com>
3979f81
to
cc3e134
Compare
Just pushed up a PR that should resolve the last bit of docs feedback. |
Co-authored-by: Joel Hawksley <joelhawksley@github.com>
Co-authored-by: Joel Hawksley <joelhawksley@github.com>
Is this available in the view_component gem yet? The latest version I'm seeing is 2.22.1 from Nov 10. 🙇♀️ |
Ah, 2.23.0 has it, thanks @BlakeWilliams! |
Summary
This PR introduces the second iteration of slots,
Slotable::V2
. This takesfeedback we've received about the original iteration of slots as well as the
experiences we've had with the original iteration of slots and builds on them.
Here's an overview of the changes:
with_slot
becomesrenders_one
with_slot
collections becomerenders_many
class_name
argument, and instead accept a component or a lambda that allow you to extend the slot.content
in templates to render their content, they instead useto_s
. e.g.<%= item.content %>
becomes<%= item %>
#slot
method, instead they use the slot method directly. e.g.c.slot(:row, theme: :yellow)
becomesc.row(theme: yellow)
V1 example
Defining a component
Defining a component's template
Using a component
V2 equivalent of the above example
Defining a component
Defining a component's template
Defining the
Row
component's template:Using a component