feat(view): add x-slot define attribute to declare slot ownership in nested components#2104
Open
iamdadmin wants to merge 3 commits intotempestphp:3.xfrom
Open
feat(view): add x-slot define attribute to declare slot ownership in nested components#2104iamdadmin wants to merge 3 commits intotempestphp:3.xfrom
iamdadmin wants to merge 3 commits intotempestphp:3.xfrom
Conversation
Contributor
Author
|
This isn't a breaking change, happily; it doesn't change the behaviour of Writing up some docs now. |
Benchmark ResultsComparison of Open to see the benchmark results
Generated by phpbench against commit 6e7867c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Consider this
x-headercomponent, which uses anx-containerto position it's content.x-containeritself is just a<div>with some classes for formatting, it has only a default slot.<header> <x-slot name="top" /> <x-container> <x-slot name="left"> // this slot is assumed to exist within x-container <x-header-left /> </x-slot> <div> I am in the center </div> <x-slot name="right"> // this slot is assumed to exist within x-container <x-header-right /> </x-slot> </x-container> <x-slot name="bottom" /> </header>At the callsite, if you want to override the default content of the "left" or "right" slot, you can't, because tempest/view assumes these are slots of
x-container.This, for example, doesn't match because
x-headeritself doesn't have a "left" slot.<x-header> <x-slot name="left">Some content I want to insert</x-slot> </x-header>This PR adds the ability to
definea slot, as owned in the ViewComponent it'sdefined in. Thex-headerbecomes:<header> <x-slot name="top" /> <x-container> <x-slot define="left"> // define this slot as a slot of x-header, compiled and passed into x-container's default slot <x-header-left /> </x-slot> <div> I am in the center </div> <x-slot define="right"> // define this slot as a slot of x-header, compiled and passed into x-container's default slot <x-header-right /> </x-slot> </x-container> <x-slot name="bottom" /> </header>At the callsite, this now works
<x-header> <x-slot name="left">Some content I want to insert</x-slot> </x-header>You can also push content into a child's named slot this way:
<div class="outer"> <x-inner> <x-slot name="left"> <x-slot define="left"><x-header-left /></x-slot> </x-slot> </x-inner> </div>At the callsite:
<x-outer> <x-slot name="left">My override</x-slot> </x-outer>