Skip to content
Merged
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
25 changes: 21 additions & 4 deletions packages/block-library/src/template-part/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ import {
useTemplatePartArea,
} from './utils/hooks';

const SUPPORTED_AREAS = [ 'header', 'footer' ];

/**
* Returns the list of supported template part areas for pattern replacement.
* Includes 'overlay' only if the navigation overlays experiment is enabled.
*
* @return {string[]} Array of supported area names.
*/
function getSupportedAreas() {
const isOverlayExperimentEnabled =
typeof window !== 'undefined' &&
window.__experimentalNavigationOverlays === true;
return isOverlayExperimentEnabled
? [ ...SUPPORTED_AREAS, 'navigation-overlay' ]
: SUPPORTED_AREAS;
}

function ReplaceButton( {
isEntityAvailable,
area,
Expand All @@ -54,10 +71,9 @@ function ReplaceButton( {
templatePartId
);
const hasReplacements = !! templateParts.length;
const supportedAreas = getSupportedAreas();
const canReplace =
isEntityAvailable &&
hasReplacements &&
( area === 'header' || area === 'footer' );
isEntityAvailable && hasReplacements && supportedAreas.includes( area );

if ( ! canReplace ) {
return null;
Expand All @@ -80,10 +96,11 @@ function TemplatesList( { area, clientId, isEntityAvailable, onSelect } ) {
// This hook fetches patterns, so don't run it unconditionally in the main
// edit function!
const blockPatterns = useAlternativeBlockPatterns( area, clientId );
const supportedAreas = getSupportedAreas();
const canReplace =
isEntityAvailable &&
!! blockPatterns.length &&
( area === 'header' || area === 'footer' );
supportedAreas.includes( area );

if ( ! canReplace ) {
return null;
Expand Down
Loading