Skip to content

Commit

Permalink
Fix zoom out view toggling issue when navigating pattern categories i…
Browse files Browse the repository at this point in the history
…n the inserter
  • Loading branch information
amitraj2203 committed Jun 6, 2024
1 parent 044a05f commit 86148c0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
* Internal dependencies
*/
import { PatternCategoryPreviews } from './pattern-category-previews';
import { useZoomOut } from '../../../hooks/use-zoom-out';

function PatternCategoryPreviewPanelInner( {
export function PatternCategoryPreviewPanel( {
rootClientId,
onInsert,
onHover,
Expand All @@ -24,17 +23,3 @@ function PatternCategoryPreviewPanelInner( {
/>
);
}

function PatternCategoryPreviewPanelWithZoomOut( props ) {
useZoomOut();
return <PatternCategoryPreviewPanelInner { ...props } />;
}

export function PatternCategoryPreviewPanel( props ) {
// When the pattern panel is showing, we want to use zoom out mode
if ( window.__experimentalEnableZoomedOutPatternsTab ) {
return <PatternCategoryPreviewPanelWithZoomOut { ...props } />;
}

return <PatternCategoryPreviewPanelInner { ...props } />;
}
22 changes: 21 additions & 1 deletion packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ import InserterSearchResults from './search-results';
import useInsertionPoint from './hooks/use-insertion-point';
import InserterTabs from './tabs';
import { store as blockEditorStore } from '../../store';
import { useZoomOut } from '../../hooks/use-zoom-out';

const ZoomOutHandler = ( { children, showPatternPanel } ) => {
// When the pattern panel is showing, we want to use zoom out mode
useZoomOut( showPatternPanel );

return <>{ children }</>;
};

const NOOP = () => {};
function InserterMenu(
Expand Down Expand Up @@ -306,7 +314,7 @@ function InserterMenu(
}
}, [] );

return (
const menuContent = (
<div
className={ clsx( 'block-editor-inserter__menu', {
'show-panel': showPatternPanel || showMediaPanel,
Expand Down Expand Up @@ -344,6 +352,18 @@ function InserterMenu(
) }
</div>
);

return (
<>
{ window.__experimentalEnableZoomedOutPatternsTab ? (
<ZoomOutHandler showPatternPanel={ showPatternPanel }>
{ menuContent }
</ZoomOutHandler>
) : (
menuContent
) }
</>
);
}

export const PrivateInserterMenu = forwardRef( InserterMenu );
Expand Down

0 comments on commit 86148c0

Please sign in to comment.