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

Zoomed-Out Mode: Don't show blocks in zoomed out view #59245

Merged
merged 6 commits into from
Feb 24, 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
14 changes: 10 additions & 4 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,22 @@ function InserterMenu(
insertionIndex: __experimentalInsertionIndex,
shouldFocusBlock,
} );
const { showPatterns } = useSelect(
const { isZoomOutMode, showPatterns } = useSelect(
( select ) => {
const { hasAllowedPatterns } = unlock( select( blockEditorStore ) );
const { hasAllowedPatterns, __unstableGetEditorMode } = unlock(
select( blockEditorStore )
);
return {
isZoomOutMode: __unstableGetEditorMode() === 'zoom-out',
showPatterns: hasAllowedPatterns( destinationRootClientId ),
};
},
[ destinationRootClientId ]
);

const mediaCategories = useMediaCategories( destinationRootClientId );
const showMedia = mediaCategories.length > 0;
const showMedia = mediaCategories.length > 0 && ! isZoomOutMode;
const showBlocks = ! isZoomOutMode;

const onInsert = useCallback(
( blocks, meta, shouldForceFocusBlock ) => {
Expand Down Expand Up @@ -249,19 +253,21 @@ function InserterMenu(
__experimentalInsertionIndex
}
showBlockDirectory
showBlocks={ showBlocks }
shouldFocusBlock={ shouldFocusBlock }
/>
</div>
) }
{ showAsTabs && (
<InserterTabs
showBlocks={ showBlocks }
showPatterns={ showPatterns }
showMedia={ showMedia }
onSelect={ handleSetSelectedTab }
tabsContents={ inserterTabsContents }
/>
) }
{ ! delayedFilterValue && ! showAsTabs && (
{ ! delayedFilterValue && ! showAsTabs && showBlocks && (
<div className="block-editor-inserter__no-tab-container">
{ blocksTab }
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function InserterSearchResults( {
shouldFocusBlock = true,
prioritizePatterns,
selectBlockOnInsert,
showBlocks = true,
} ) {
const debouncedSpeak = useDebounce( speak, 500 );

Expand Down Expand Up @@ -167,7 +168,7 @@ function InserterSearchResults( {
const hasItems =
filteredBlockTypes.length > 0 || filteredBlockPatterns.length > 0;

const blocksUI = !! filteredBlockTypes.length && (
const blocksUI = showBlocks && !! filteredBlockTypes.length && (
<InserterPanel
title={ <VisuallyHidden>{ __( 'Blocks' ) }</VisuallyHidden> }
>
Expand Down
3 changes: 2 additions & 1 deletion packages/block-editor/src/components/inserter/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ const mediaTab = {
};

function InserterTabs( {
showBlocks = true,
showPatterns = false,
showMedia = false,
onSelect,
tabsContents,
} ) {
const tabs = [
blocksTab,
showBlocks && blocksTab,
showPatterns && patternsTab,
showMedia && mediaTab,
].filter( Boolean );
Expand Down
Loading