-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add Post level components to allow easy building of page level blocks #178
Conversation
…components in a query loop
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.
@fabiankaegy awesome work as usual!
I've left some minor comments and one suggestion for improvement with onChange
. I think aside from some minor things this is good to go as is and the rest can be follow up too.
I didn't add comments on every repeated occurrence of the defaultProps
subject but I can do that too if useful.
I can't wait for this to be out!
Co-authored-by: Antonio Laguna <[email protected]>
Co-authored-by: Antonio Laguna <[email protected]>
Thank you so much @Antonio-Laguna for you thorough feedback :) I've addressed all your feedback and think I got all the instances of the As mentioned above I will create a follow up for the Once the CI checks are passing I will merge this into develop as the initial round ready for some more wider testing :) |
High-Level Goal
WordPress itself ships a lot of
Post-
level blocks. These are atomic building blocks that are mostly usefull within the site editor and post templates inside of the Query Loop block.The issue though is that often times on tightly controlled client builds we want to be able to have more control over the actual markup generated by these elements. And the fact that blocks only support one InnerBlock area means that we cannot achieve every layout and markup with the
Post-
level blocks.In order to combat this the idea in this PR is to introduce Block Components that resemble the functionality of the
Post-
level component that can be used freely inside any block and take care of all the complex logic required to get these to read/write the correct data from the global post and or query loop post template.The Components:
PostTitle
PostFeaturedImage
PostExcerpt
PostAuthor
PostAuthor.Avatar
PostAuthor.Name
PostAuthor.LastName
PostAuthor.Bio
PostAuthor.Email
PostTermList
PostTermList.ListItem
PostTermList.TermLink
PostCategoryList
PostCategoryList.ListItem
PostCategoryList.TermLink
PostPrimaryTerm
(Requires Yoast SEO for the Primary Term functionality)PostPrimaryCategory
(Requires Yoast SEO for the Primary Term functionality)PostDate
PostContext
PostMeta
Component Structure
These components can be grouped into two categories. There are the components which save and display a singular entity like the
PostTitle
,PostExcerpt
,PostPrimaryTerm
etc. These pass through all of the attributes to the actual HTML element and therefore allow full customization of the markup straight out of the box.But then there also are components that can render multiple pieces of information at once. Some examples of this are the
PostAuthor
orPostTerms
. These can also be used in the same way but then you don't have full control over the markup they produce. In order to still have full control over the markup these components accept render functions or even child components in order to build the markup.All these components are reading the current
postId
/postType
of the post that is getting edited. This however can be changed by wrapping thePost
components in thePostContext
wrapper which makes thepostId
,postType
and whether or not the elements should be editable to all the elements wrapped within.Examples
All the
Post
components are reading/writing data to a post instead of an attribute. They can be used in any block and can inherit both the global post (currently being edited) or also the current post when the block these components are getting used in is a descendant of a query loop.If you just want to use the global post you can use these components like shown in the
Hero
block in theexamples
If on the other hand, you want to get the info from the current post within a query loop/post template you can pass in the block context.
These values can then be used in the
<PostContext>
component to make the values available to allPost-
level components used within.Closing #177
Testing Instructions
If you want to test this PR you can either clone this repo and build something in the
example
project bundled with the repo. Or you can install this prerelease version like so:Props: @fabiankaegy @Antonio-Laguna