-
Notifications
You must be signed in to change notification settings - Fork 4.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
Unify BlockPreview & BlockPreviewContent into one component #16801
Conversation
afecdb4
to
097bc0f
Compare
I made It is used this way:
but I was wondering whether to made it into something more like HOC which will take the same props as
|
Rebased against #16033 |
…16033) * export BlockPreview * Update to accept multiple Blocks * Update reusable Blocks preview to use the new single blocks prop * Remove unecessary clone of Blocks Not sure why this was introduced. * Remove export. This is being handled in another PR See #16801 * Simplify casting to array via lodash * Utilise cloneBlocks to safely merge attributes on blocks prop * Spread reusable block initial attrs correctly * Fix cloneBlock fn to check for innerBlocks before attempting to map The `innerBlocks` of the `block` being cloned can be `undefined`. Therefore, by attempting to map these we trigger an error. Fixed to introduce existence check before attempting to manipulate innerBlocks. * Simplify modifying passed block attrs via cloneBlock * Removes unecessary spread operation initalAttributes is already an object so no need to spread into an object. * block-preview: ensuring to cast BlockEditorProvider value prop as an Array * don't call cloneBlock on a non-block object * bring back the old behavior of cloneBlock
097bc0f
to
3251ebd
Compare
packages/block-editor/src/components/block-preview/dropdown-wrapper.js
Outdated
Show resolved
Hide resolved
I like the idea of combining the blocks: <BlockPreviewDropdownWrapper>
<BlockPreview blocks={ [ … ] } />
</BlockPreviewDropdownWrapper> However, maybe it worths create the new |
Forgot to mention that if we want to expose the |
This was my concern and that's why I've introduced the DropdownWrapper to abstract the styling. Knowing this, I've reverted my last commit and we now have a copy of the "aside" in both Inserter and Switcher. I think all feedback is now addressed here. |
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.
I think we may have lost a border around the previews in the change here but tbh I don't think it's worse. It may be better design-wise.
That was intentional :) Glad you noticed. That border just felt extraneous and was so subtle it was barely noticeable anyways. |
…16033) * export BlockPreview * Update to accept multiple Blocks * Update reusable Blocks preview to use the new single blocks prop * Remove unecessary clone of Blocks Not sure why this was introduced. * Remove export. This is being handled in another PR See #16801 * Simplify casting to array via lodash * Utilise cloneBlocks to safely merge attributes on blocks prop * Spread reusable block initial attrs correctly * Fix cloneBlock fn to check for innerBlocks before attempting to map The `innerBlocks` of the `block` being cloned can be `undefined`. Therefore, by attempting to map these we trigger an error. Fixed to introduce existence check before attempting to manipulate innerBlocks. * Simplify modifying passed block attrs via cloneBlock * Removes unecessary spread operation initalAttributes is already an object so no need to spread into an object. * block-preview: ensuring to cast BlockEditorProvider value prop as an Array * don't call cloneBlock on a non-block object * bring back the old behavior of cloneBlock
* export BlockPreview * Update reusable Blocks preview to use the new single blocks prop * Remove export. This is being handled in another PR See #16801 * mark all usages with red for easier visual tracking * make a new unified component * use new component in style thumbnail * update usage in block switcher, add isScaled & className support * revert initial state in block switcher * use in block inserter * use the new unified component as default, migrate usages * drop word 'unified' from classname * remove extra import. h/t @retrofox * remove border around previews * fix styling of scaled previews * make abstract component for styling previews inside dropdowns * move block switcher & inserter to use common component for styling * drop the old editor-block-preview class * revert dropdown component abstraction This reverts commit 5bc673e. This reverts commit 3006c01.
…16033) * export BlockPreview * Update to accept multiple Blocks * Update reusable Blocks preview to use the new single blocks prop * Remove unecessary clone of Blocks Not sure why this was introduced. * Remove export. This is being handled in another PR See #16801 * Simplify casting to array via lodash * Utilise cloneBlocks to safely merge attributes on blocks prop * Spread reusable block initial attrs correctly * Fix cloneBlock fn to check for innerBlocks before attempting to map The `innerBlocks` of the `block` being cloned can be `undefined`. Therefore, by attempting to map these we trigger an error. Fixed to introduce existence check before attempting to manipulate innerBlocks. * Simplify modifying passed block attrs via cloneBlock * Removes unecessary spread operation initalAttributes is already an object so no need to spread into an object. * block-preview: ensuring to cast BlockEditorProvider value prop as an Array * don't call cloneBlock on a non-block object * bring back the old behavior of cloneBlock
* export BlockPreview * Update reusable Blocks preview to use the new single blocks prop * Remove export. This is being handled in another PR See #16801 * mark all usages with red for easier visual tracking * make a new unified component * use new component in style thumbnail * update usage in block switcher, add isScaled & className support * revert initial state in block switcher * use in block inserter * use the new unified component as default, migrate usages * drop word 'unified' from classname * remove extra import. h/t @retrofox * remove border around previews * fix styling of scaled previews * make abstract component for styling previews inside dropdowns * move block switcher & inserter to use common component for styling * drop the old editor-block-preview class * revert dropdown component abstraction This reverts commit 5bc673e. This reverts commit 3006c01.
Description
This PR updates the way
BlockPreview
&BlockPreviewContent
are used. We want to soon make previews available for plugin developers and these two components were quite confusing together as seen in #16033 (comment).This PR introduces a new version of
BlockPreview
which is used for both scaled and full-size previews (controlled by a propisScaled
) and allows you to add customclassName
to the preview wrapper for further styling if needed.BlockPreviewContent
is gone.The boolean prop
isScaled
is a solution that simulates how the component is currently used in the codebase. It will be soon replaced with different way of doing scaling that is being cooked in #16113. For now, I think it's a good solution that will keep our current usages working the same way while paving the way for the new scaling API and exporting the component for devs to use in plugins.How has this been tested?
Screenshots
This is
<BlockPreview isScaled blocks={ [ … ] } />
inside Block Styles:This is the same preview inside the block switcher. The "panel" on the right was moved from the
BlockPreview
component directly into places where it is being used from (Inserter and Swicther). BlockPreview component is now always only the previewed content and nothing else.Types of changes
Checklist: