-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Navigation: Extract components (#45850)
- Loading branch information
Showing
2 changed files
with
177 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
packages/block-library/src/navigation/edit/menu-inspector-controls.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
__experimentalOffCanvasEditor as OffCanvasEditor, | ||
InspectorControls, | ||
} from '@wordpress/block-editor'; | ||
import { | ||
PanelBody, | ||
__experimentalHStack as HStack, | ||
__experimentalHeading as Heading, | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ManageMenusButton from './manage-menus-button'; | ||
import NavigationMenuSelector from './navigation-menu-selector'; | ||
|
||
const WrappedNavigationMenuSelector = ( { | ||
clientId, | ||
currentMenuId, | ||
handleUpdateMenu, | ||
convertClassicMenu, | ||
onCreateNew, | ||
createNavigationMenuIsSuccess, | ||
createNavigationMenuIsError, | ||
} ) => ( | ||
<NavigationMenuSelector | ||
currentMenuId={ currentMenuId } | ||
clientId={ clientId } | ||
onSelectNavigationMenu={ ( menuId ) => { | ||
handleUpdateMenu( menuId ); | ||
} } | ||
onSelectClassicMenu={ async ( classicMenu ) => { | ||
const navMenu = await convertClassicMenu( | ||
classicMenu.id, | ||
classicMenu.name, | ||
'draft' | ||
); | ||
if ( navMenu ) { | ||
handleUpdateMenu( navMenu.id, { | ||
focusNavigationBlock: true, | ||
} ); | ||
} | ||
} } | ||
onCreateNew={ onCreateNew } | ||
createNavigationMenuIsSuccess={ createNavigationMenuIsSuccess } | ||
createNavigationMenuIsError={ createNavigationMenuIsError } | ||
/* translators: %s: The name of a menu. */ | ||
actionLabel={ __( "Switch to '%s'" ) } | ||
/> | ||
); | ||
const MenuInspectorControls = ( { | ||
clientId, | ||
convertClassicMenu, | ||
createNavigationMenuIsSuccess, | ||
createNavigationMenuIsError, | ||
currentMenuId = null, | ||
handleUpdateMenu, | ||
isNavigationMenuMissing, | ||
innerBlocks, | ||
isManageMenusButtonDisabled, | ||
onCreateNew, | ||
} ) => { | ||
const isOffCanvasNavigationEditorEnabled = | ||
window?.__experimentalEnableOffCanvasNavigationEditor === true; | ||
|
||
return ( | ||
<InspectorControls> | ||
<PanelBody | ||
title={ | ||
isOffCanvasNavigationEditorEnabled ? null : __( 'Menu' ) | ||
} | ||
> | ||
{ isOffCanvasNavigationEditorEnabled ? ( | ||
<> | ||
<HStack className="wp-block-navigation-off-canvas-editor__header"> | ||
<Heading | ||
className="wp-block-navigation-off-canvas-editor__title" | ||
level={ 2 } | ||
> | ||
{ __( 'Menu' ) } | ||
</Heading> | ||
<WrappedNavigationMenuSelector | ||
clientId={ clientId } | ||
currentMenuId={ currentMenuId } | ||
handleUpdateMenu={ handleUpdateMenu } | ||
convertClassicMenu={ convertClassicMenu } | ||
onCreateNew={ onCreateNew } | ||
createNavigationMenuIsSuccess={ | ||
createNavigationMenuIsSuccess | ||
} | ||
createNavigationMenuIsError={ | ||
createNavigationMenuIsError | ||
} | ||
/> | ||
</HStack> | ||
{ currentMenuId && isNavigationMenuMissing ? ( | ||
<p>{ __( 'Select or create a menu' ) }</p> | ||
) : ( | ||
<OffCanvasEditor | ||
blocks={ innerBlocks } | ||
isExpanded={ true } | ||
selectBlockInCanvas={ false } | ||
/> | ||
) } | ||
</> | ||
) : ( | ||
<> | ||
<WrappedNavigationMenuSelector | ||
clientId={ clientId } | ||
currentMenuId={ currentMenuId } | ||
handleUpdateMenu={ handleUpdateMenu } | ||
convertClassicMenu={ convertClassicMenu } | ||
onCreateNew={ onCreateNew } | ||
createNavigationMenuIsSuccess={ | ||
createNavigationMenuIsSuccess | ||
} | ||
createNavigationMenuIsError={ | ||
createNavigationMenuIsError | ||
} | ||
/> | ||
<ManageMenusButton | ||
disabled={ isManageMenusButtonDisabled } | ||
/> | ||
</> | ||
) } | ||
</PanelBody> | ||
</InspectorControls> | ||
); | ||
}; | ||
|
||
export default MenuInspectorControls; |