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

Grid interactivity: Show grid visualizer when block inspector is closed #61429

Merged
merged 2 commits into from
May 13, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@
* WordPress dependencies
*/
import { useState, useEffect } from '@wordpress/element';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs';
import BlockPopoverCover from '../block-popover/cover';
import { store as blockEditorStore } from '../../store';
import { getComputedCSS } from './utils';

export function GridVisualizer( { clientId } ) {
const isDistractionFree = useSelect(
( select ) =>
select( blockEditorStore ).getSettings().isDistractionFree,
[]
);
const blockElement = useBlockElement( clientId );
if ( ! blockElement ) {

if ( isDistractionFree || ! blockElement ) {
return null;
}

return (
<BlockPopoverCover
className="block-editor-grid-visualizer"
Expand Down
13 changes: 6 additions & 7 deletions packages/block-editor/src/layouts/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export default {
inspectorControls: function GridLayoutInspectorControls( {
layout = {},
onChange,
clientId,
layoutBlockSupport = {},
} ) {
const { allowSizingOnChildren = false } = layoutBlockSupport;
Expand All @@ -90,14 +89,14 @@ export default {
onChange={ onChange }
/>
) }
{ window.__experimentalEnableGridInteractivity && (
<GridVisualizer clientId={ clientId } />
) }
</>
);
},
toolBarControls: function GridLayoutToolbarControls() {
return null;
toolBarControls: function GridLayoutToolbarControls( { clientId } ) {
if ( ! window.__experimentalEnableGridInteractivity ) {
return null;
}
return <GridVisualizer clientId={ clientId } />;
},
getLayoutStyle: function getLayoutStyle( {
selector,
Expand Down Expand Up @@ -136,7 +135,7 @@ export default {
} else if ( minimumColumnWidth ) {
rules.push(
`grid-template-columns: repeat(auto-fill, minmax(min(${ minimumColumnWidth }, 100%), 1fr))`,
`container-type: inline-size`
'container-type: inline-size'
);
}

Expand Down
Loading