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

Move theme location settings to navigation editor sidebar #29458

Merged
merged 9 commits into from
Mar 24, 2021
20 changes: 1 addition & 19 deletions packages/edit-navigation/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import { find } from 'lodash';
/**
* WordPress dependencies
*/
import { Button, Dropdown, DropdownMenu } from '@wordpress/components';
import { DropdownMenu } from '@wordpress/components';
import { PinnedItems } from '@wordpress/interface';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import SaveButton from './save-button';
import ManageLocations from './manage-locations';
import MenuSwitcher from '../menu-switcher';

export default function Header( {
Expand Down Expand Up @@ -85,23 +84,6 @@ export default function Header( {
) }
</DropdownMenu>

<Dropdown
contentClassName="edit-navigation-header__manage-locations"
position="bottom left"
renderToggle={ ( { isOpen, onToggle } ) => (
<Button
isTertiary
aria-expanded={ isOpen }
onClick={ onToggle }
>
{ __( 'Manage locations' ) }
</Button>
) }
renderContent={ () => (
<ManageLocations menus={ menus } />
) }
/>

<SaveButton navigationPost={ navigationPost } />
<PinnedItems.Slot scope="core/edit-navigation" />
</div>
Expand Down
45 changes: 0 additions & 45 deletions packages/edit-navigation/src/components/header/manage-locations.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ import { InspectorControls } from '@wordpress/block-editor';
*/
import AutoAddPagesPanel from './auto-add-pages-panel';
import DeleteMenuPanel from './delete-menu-panel';
import ManageLocations from './manage-locations';
import { NameEditor } from '../name-editor';
import { PanelBody } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

export default function InspectorAdditions( { menuId, onDeleteMenu } ) {
export default function InspectorAdditions( {
menuId,
menus,
onDeleteMenu,
onSelectMenu,
isManageLocationsModalOpen,
closeManageLocationsModal,
openManageLocationsModal,
} ) {
const selectedBlock = useSelect(
( select ) => select( 'core/block-editor' ).getSelectedBlock(),
[]
Expand All @@ -25,11 +34,21 @@ export default function InspectorAdditions( { menuId, onDeleteMenu } ) {

return (
<InspectorControls>
<PanelBody title={ __( 'Menu Settings' ) }>
<PanelBody title={ __( 'Menu settings' ) }>
<NameEditor />
<AutoAddPagesPanel menuId={ menuId } />
<DeleteMenuPanel onDeleteMenu={ onDeleteMenu } />
</PanelBody>
<PanelBody title={ __( 'Theme locations' ) }>
<ManageLocations
menus={ menus }
selectedMenuId={ menuId }
onSelectMenu={ onSelectMenu }
isModalOpen={ isManageLocationsModalOpen }
closeModal={ closeManageLocationsModal }
openModal={ openManageLocationsModal }
/>
</PanelBody>
</InspectorControls>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/**
* WordPress dependencies
*/
import {
Spinner,
SelectControl,
CheckboxControl,
Button,
Modal,
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { useMenuLocations } from '../../hooks';

export default function ManageLocations( {
onSelectMenu,
isModalOpen,
openModal,
closeModal,
menus,
selectedMenuId,
} ) {
const {
menuLocations,
assignMenuToLocation,
toggleMenuLocationAssignment,
} = useMenuLocations();

if ( ! menuLocations ) {
return <Spinner />;
}

if ( ! menuLocations.length ) {
return <p>{ __( 'There are no available menu locations.' ) }</p>;
}

const themeLocationCountTextMain = sprintf(
// translators: Number of available theme locations.
__(
'Your current theme provides %d different locations to place menu.'
),
menuLocations.length
);

const themeLocationCountTextModal = sprintf(
// translators: Number of available theme locations.
__(
'Your current theme supports %d different locations. Select which menu appears in each location.'
),
menuLocations.length
);

const menusWithSelection = menuLocations.map( ( { name, menu } ) => {
const menuOnLocation = menus
.filter( ( { id } ) => ! [ 0, selectedMenuId ].includes( id ) )
.find( ( { id } ) => id === menu );

return (
<li
key={ name }
className="edit-navigation-manage-locations__checklist-item"
>
<CheckboxControl
className="edit-navigation-manage-locations__menu-location-checkbox"
checked={ menu === selectedMenuId }
onChange={ () =>
toggleMenuLocationAssignment( name, selectedMenuId )
}
label={ name }
help={
menuOnLocation &&
sprintf(
// translators: menu name.
__( 'Currently using %s' ),
menuOnLocation.name
)
}
/>
</li>
);
} );

const menuLocationCard = menuLocations.map( ( menuLocation ) => (
<div
key={ menuLocation.name }
className="edit-navigation-manage-locations__menu-entry"
>
<SelectControl
key={ menuLocation.name }
className="edit-navigation-manage-locations__select-menu"
label={ menuLocation.description }
labelPosition="top"
value={ menuLocation.menu }
options={ [
{ value: 0, label: __( '-' ), key: 0 },
...menus.map( ( { id, name } ) => ( {
key: id,
value: id,
label: name,
} ) ),
] }
onChange={ ( menuId ) => {
assignMenuToLocation( menuLocation.name, Number( menuId ) );
} }
/>
<Button
isSecondary
style={ {
visibility: !! menuLocation.menu ? 'visible' : 'hidden',
} }
className="edit-navigation-manage-locations__edit-button"
onClick={ () => (
closeModal(), onSelectMenu( menuLocation.menu )
) }
>
{ __( 'Edit' ) }
</Button>
</div>
) );

return (
<>
<div className="edit-navigation-manage-locations__theme-location-text-main">
{ themeLocationCountTextMain }
</div>
<ul className="edit-navigation-manage-locations__checklist">
{ menusWithSelection }
</ul>
<Button
isSecondary
className="edit-navigation-manage-locations__open-menu-locations-modal-button"
aria-expanded={ isModalOpen }
onClick={ openModal }
>
{ __( 'Manage locations' ) }
</Button>
{ isModalOpen && (
<Modal
className="edit-navigation-manage-locations__modal"
title={ __( 'Manage locations' ) }
onRequestClose={ closeModal }
>
<div className="edit-navigation-manage-locations__theme-location-text-modal">
{ themeLocationCountTextModal }
</div>
{ menuLocationCard }
</Modal>
) }
</>
);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
.edit-navigation-inspector-additions__delete-menu-panel {
text-align: center;
}

.edit-navigation-manage-locations__modal {
max-width: 360px;
}

.edit-navigation-manage-locations__delete-menu-panel {
text-align: center;
}

.edit-navigation-manage-locations__menu-entry .components-base-control {
width: 100%;
}

.edit-navigation-manage-locations__edit-button {
flex: 1;
}

.edit-navigation-manage-locations__menu-entry {
display: flex;
margin-bottom: $grid-unit-15;
margin-top: $grid-unit-15;
.components-custom-select-control,
.components-custom-select-control__button {
width: 100%;
}
button {
height: 100%;
}
}

.edit-navigation-manage-locations__select-menu {
padding-right: $grid-unit-10;
}

.edit-navigation-manage-locations__open-menu-locations-modal-button {
width: 100%;
justify-content: center;
}

.edit-navigation-manage-locations__theme-location-text-main,
.edit-navigation-manage-locations__theme-location-text-modal {
margin-bottom: $grid-unit-30;
}
16 changes: 16 additions & 0 deletions packages/edit-navigation/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export default function Layout( { blockEditorSettings } ) {
navigationPost,
selectMenu,
deleteMenu,
openManageLocationsModal,
closeManageLocationsModal,
isManageLocationsModalOpen,
} = useNavigationEditor();

const [ blocks, onInput, onChange ] = useNavigationBlockEditor(
Expand Down Expand Up @@ -167,6 +170,19 @@ export default function Layout( { blockEditorSettings } ) {
blocks={ blocks }
/>
<InspectorAdditions
isManageLocationsModalOpen={
isManageLocationsModalOpen
}
openManageLocationsModal={
openManageLocationsModal
}
closeManageLocationsModal={
closeManageLocationsModal
}
onSelectMenu={
selectMenu
}
menus={ menus }
menuId={
selectedMenuId
}
Expand Down
Loading