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

Fix: block styles preview is not displayed #43837

Merged
merged 3 commits into from
Sep 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {
isReusableBlock,
createBlock,
getBlockType,
getBlockFromExample,
} from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
Expand All @@ -15,8 +16,11 @@ import BlockCard from '../block-card';
import BlockPreview from '../block-preview';

function InserterPreviewPanel( { item } ) {
const { name, title, icon, description, initialAttributes, example } = item;
const { name, title, icon, description, initialAttributes } = item;
const isReusable = isReusableBlock( item );
const hoveredItemBlockType = getBlockType( name );
ramonjd marked this conversation as resolved.
Show resolved Hide resolved
const example = item.example || hoveredItemBlockType.example;
Copy link
Contributor Author

@t-hamano t-hamano Sep 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, it is not explicitly stated that the example can be used for block variations.
To clarify what this code is intended to do, should I leave any comments here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth adding a small comment to explain why you're checking for both, for sure 👍


return (
<div className="block-editor-inserter__preview-container">
<div className="block-editor-inserter__preview">
Expand All @@ -27,7 +31,7 @@ function InserterPreviewPanel( { item } ) {
viewportWidth={ example?.viewportWidth ?? 500 }
blocks={
example
? getBlockFromExample( item.name, {
? getBlockFromExample( name, {
Copy link
Contributor Author

@t-hamano t-hamano Sep 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a small improvement 👍

attributes: {
...example.attributes,
...initialAttributes,
Expand Down