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

Block Previews: dynamic preview size #19987

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
/**
* External dependencies
*/
import { filter, findIndex, flow, groupBy, isEmpty, map, sortBy, without, includes } from 'lodash';
import {
filter,
findIndex,
flow,
get,
groupBy,
isEmpty,
map,
sortBy,
without,
includes,
} from 'lodash';
import scrollIntoView from 'dom-scroll-into-view';
import classnames from 'classnames';

Expand Down Expand Up @@ -251,6 +262,7 @@ export class InserterMenu extends Component {
! isEmpty( itemsPerCollection );
const hoveredItemBlockType = hoveredItem ? getBlockType( hoveredItem.name ) : null;
const hasHelpPanel = hasItems && showInserterHelpPanel;
const viewportWidth = get( hoveredItemBlockType, 'example.viewportWidth', 500 );

// Disable reason (no-autofocus): The inserter menu is a modal display, not one which
// is always visible, and one which already incurs this behavior of autoFocus via
Expand Down Expand Up @@ -416,7 +428,7 @@ export class InserterMenu extends Component {
<div className="block-editor-inserter__preview-content">
<BlockPreview
padding={ 10 }
viewportWidth={ 500 }
viewportWidth={ viewportWidth }
blocks={
hoveredItemBlockType.example
? getBlockFromExample( hoveredItem.name, {
Expand Down