Skip to content

Commit

Permalink
Only show grid when selected or dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Jul 5, 2024
1 parent 2caa87f commit e01d2ad
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions packages/block-editor/src/hooks/grid-visualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,41 @@
*/
import { createHigherOrderComponent } from '@wordpress/compose';
import { addFilter } from '@wordpress/hooks';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { GridVisualizer, useGridLayoutSync } from '../components/grid';
import { store as blockEditorStore } from '../store';

function GridLayoutSync( props ) {
useGridLayoutSync( props );
}

function GridTools( { clientId, layout } ) {
const { isSelected, isDragging } = useSelect( ( select ) => {
const { isBlockSelected, isDraggingBlocks } =
select( blockEditorStore );

return {
isSelected: isBlockSelected( clientId ),
isDragging: isDraggingBlocks(),
};
} );

if ( ! isSelected && ! isDragging ) {
return null;
}

return (
<>
<GridVisualizer clientId={ clientId } parentLayout={ layout } />
<GridLayoutSync clientId={ clientId } />
</>
);
}

const addGridVisualizerToBlockEdit = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
if (
Expand All @@ -24,12 +49,10 @@ const addGridVisualizerToBlockEdit = createHigherOrderComponent(

return (
<>
<GridVisualizer
<GridTools
clientId={ props.clientId }
parentLayout={ props.attributes.layout }
layout={ props.attributes.layout }
/>
<GridLayoutSync clientId={ props.clientId } />

<BlockEdit { ...props } />
</>
);
Expand Down

0 comments on commit e01d2ad

Please sign in to comment.