Skip to content

Commit

Permalink
Grid interactivity: Show grid visualizer when block inspector is clos…
Browse files Browse the repository at this point in the history
…ed (#61429)

* Grid interactivity: Show grid visualizer when block inspector is closed

* Hide grid visualizer when distraction free mode is enabled
  • Loading branch information
noisysocks authored May 13, 2024
1 parent 406f4b7 commit c90eb55
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
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

0 comments on commit c90eb55

Please sign in to comment.