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

Navigation: Refactor display panel to use ToolsPanel #68011

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
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
170 changes: 115 additions & 55 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import { EntityProvider, store as coreStore } from '@wordpress/core-data';

import { useDispatch, useSelect } from '@wordpress/data';
import {
PanelBody,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
ToggleControl,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
Expand Down Expand Up @@ -72,6 +73,7 @@ import DeletedNavigationWarning from './deleted-navigation-warning';
import AccessibleDescription from './accessible-description';
import AccessibleMenuDescription from './accessible-menu-description';
import { unlock } from '../../lock-unlock';
import { useToolsPanelDropdownMenuProps } from '../../utils/hooks';

function ColorTools( {
textColor,
Expand Down Expand Up @@ -583,11 +585,25 @@ function Navigation( {
`overlay-menu-preview`
);

const dropdownMenuProps = useToolsPanelDropdownMenuProps();

const stylingInspectorControls = (
<>
<InspectorControls>
{ hasSubmenuIndicatorSetting && (
<PanelBody title={ __( 'Display' ) }>
<ToolsPanel
label={ __( 'Display' ) }
resetAll={ () => {
setAttributes( {
showSubmenuIcon: true,
openSubmenusOnClick: false,
overlayMenu: 'mobile',
hasIcon: true,
icon: 'handle',
} );
} }
dropdownMenuProps={ dropdownMenuProps }
>
{ isResponsive && (
<>
<Button
Expand Down Expand Up @@ -615,76 +631,120 @@ function Navigation( {
</>
) }
</Button>
<div id={ overlayMenuPreviewId }>
{ overlayMenuPreview && (
{ overlayMenuPreview && (
<div
id={ overlayMenuPreviewId }
className="wp-block-navigation__overlay-menu-preview-controls"
>
<OverlayMenuPreview
setAttributes={ setAttributes }
hasIcon={ hasIcon }
icon={ icon }
hidden={ ! overlayMenuPreview }
/>
) }
</div>
</div>
) }
</>
) }
<ToggleGroupControl
__next40pxDefaultSize
__nextHasNoMarginBottom

<ToolsPanelItem
hasValue={ () => overlayMenu !== 'mobile' }
label={ __( 'Overlay Menu' ) }
aria-label={ __( 'Configure overlay menu' ) }
value={ overlayMenu }
help={ __(
'Collapses the navigation options in a menu icon opening an overlay.'
) }
onChange={ ( value ) =>
setAttributes( { overlayMenu: value } )
onDeselect={ () =>
setAttributes( { overlayMenu: 'mobile' } )
}
isBlock
isShownByDefault
>
<ToggleGroupControlOption
value="never"
label={ __( 'Off' ) }
/>
<ToggleGroupControlOption
value="mobile"
label={ __( 'Mobile' ) }
/>
<ToggleGroupControlOption
value="always"
label={ __( 'Always' ) }
/>
</ToggleGroupControl>
<ToggleGroupControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Overlay Menu' ) }
aria-label={ __( 'Configure overlay menu' ) }
value={ overlayMenu }
help={ __(
'Collapses the navigation options in a menu icon opening an overlay.'
) }
onChange={ ( value ) =>
setAttributes( { overlayMenu: value } )
}
isBlock
>
<ToggleGroupControlOption
value="never"
label={ __( 'Off' ) }
/>
<ToggleGroupControlOption
value="mobile"
label={ __( 'Mobile' ) }
/>
<ToggleGroupControlOption
value="always"
label={ __( 'Always' ) }
/>
</ToggleGroupControl>
</ToolsPanelItem>

{ hasSubmenus && (
<>
<h3>{ __( 'Submenus' ) }</h3>
<ToggleControl
__nextHasNoMarginBottom
checked={ openSubmenusOnClick }
onChange={ ( value ) => {
setAttributes( {
openSubmenusOnClick: value,
...( value && {
showSubmenuIcon: true,
} ), // Make sure arrows are shown when we toggle this on.
} );
} }
<h3 className="wp-block-navigation__submenu-header">
{ __( 'Submenus' ) }
</h3>
<ToolsPanelItem
hasValue={ () => openSubmenusOnClick }
label={ __( 'Open on click' ) }
/>

<ToggleControl
__nextHasNoMarginBottom
checked={ showSubmenuIcon }
onChange={ ( value ) => {
onDeselect={ () =>
setAttributes( {
showSubmenuIcon: value,
} );
} }
disabled={ attributes.openSubmenusOnClick }
openSubmenusOnClick: false,
showSubmenuIcon: true,
} )
}
isShownByDefault
>
<ToggleControl
__nextHasNoMarginBottom
checked={ openSubmenusOnClick }
onChange={ ( value ) => {
setAttributes( {
openSubmenusOnClick: value,
...( value && {
showSubmenuIcon: true,
} ), // Make sure arrows are shown when we toggle this on.
} );
} }
label={ __( 'Open on click' ) }
/>
</ToolsPanelItem>

<ToolsPanelItem
hasValue={ () => ! showSubmenuIcon }
label={ __( 'Show arrow' ) }
/>
onDeselect={ () =>
setAttributes( {
showSubmenuIcon: true,
} )
}
isDisabled={
attributes.openSubmenusOnClick
}
isShownByDefault
>
<ToggleControl
__nextHasNoMarginBottom
checked={ showSubmenuIcon }
onChange={ ( value ) => {
setAttributes( {
showSubmenuIcon: value,
} );
} }
disabled={
attributes.openSubmenusOnClick
}
label={ __( 'Show arrow' ) }
/>
</ToolsPanelItem>

{ submenuAccessibilityNotice && (
<div>
<div className="wp-block-navigation__submenu-accessibility-notice">
<Notice
spokenMessage={ null }
status="warning"
Expand All @@ -696,7 +756,7 @@ function Navigation( {
) }
</>
) }
</PanelBody>
</ToolsPanel>
) }
</InspectorControls>
<InspectorControls group="color">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ToggleControl,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
__experimentalToolsPanelItem as ToolsPanelItem,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';

Expand All @@ -16,36 +17,52 @@ import OverlayMenuIcon from './overlay-menu-icon';
export default function OverlayMenuPreview( { setAttributes, hasIcon, icon } ) {
return (
<>
<ToggleControl
__nextHasNoMarginBottom
<ToolsPanelItem
label={ __( 'Show icon button' ) }
help={ __(
'Configure the visual appearance of the button that toggles the overlay menu.'
) }
onChange={ ( value ) => setAttributes( { hasIcon: value } ) }
checked={ hasIcon }
/>
isShownByDefault
hasValue={ () => ! hasIcon }
onDeselect={ () => setAttributes( { hasIcon: true } ) }
>
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Show icon button' ) }
help={ __(
'Configure the visual appearance of the button that toggles the overlay menu.'
) }
onChange={ ( value ) =>
setAttributes( { hasIcon: value } )
}
checked={ hasIcon }
/>
</ToolsPanelItem>

<ToggleGroupControl
__next40pxDefaultSize
__nextHasNoMarginBottom
className="wp-block-navigation__overlay-menu-icon-toggle-group"
<ToolsPanelItem
label={ __( 'Icon' ) }
value={ icon }
onChange={ ( value ) => setAttributes( { icon: value } ) }
isBlock
isShownByDefault
hasValue={ () => icon !== 'handle' }
onDeselect={ () => setAttributes( { icon: 'handle' } ) }
>
<ToggleGroupControlOption
value="handle"
aria-label={ __( 'handle' ) }
label={ <OverlayMenuIcon icon="handle" /> }
/>
<ToggleGroupControlOption
value="menu"
aria-label={ __( 'menu' ) }
label={ <OverlayMenuIcon icon="menu" /> }
/>
</ToggleGroupControl>
<ToggleGroupControl
__next40pxDefaultSize
__nextHasNoMarginBottom
className="wp-block-navigation__overlay-menu-icon-toggle-group"
label={ __( 'Icon' ) }
value={ icon }
onChange={ ( value ) => setAttributes( { icon: value } ) }
isBlock
>
<ToggleGroupControlOption
value="handle"
aria-label={ __( 'handle' ) }
label={ <OverlayMenuIcon icon="handle" /> }
/>
<ToggleGroupControlOption
value="menu"
aria-label={ __( 'menu' ) }
label={ <OverlayMenuIcon icon="menu" /> }
/>
</ToggleGroupControl>
</ToolsPanelItem>
</>
);
}
20 changes: 16 additions & 4 deletions packages/block-library/src/navigation/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ body.editor-styles-wrapper .wp-block-navigation__responsive-container.is-menu-op
// Ref - https://github.com/WordPress/gutenberg/pull/65075#discussion_r1746282734
height: $grid-unit-40 * 2 !important;

margin-bottom: $grid-unit-15;
grid-column: span 2;

&.open {
box-shadow: inset 0 0 0 $border-width $gray-200;
Expand Down Expand Up @@ -637,7 +637,19 @@ body.editor-styles-wrapper .wp-block-navigation__responsive-container.is-menu-op
margin-left: 24px;
}

.wp-block-navigation__overlay-menu-icon-toggle-group {
// Counteract the margin added by the block inspector.
margin-bottom: $grid-unit-20;
.editor-sidebar__panel .wp-block-navigation__submenu-header {
margin-top: 0;
margin-bottom: 0;
}

.wp-block-navigation__overlay-menu-preview-controls {
grid-column: span 2;

.components-tools-panel-item:first-child {
margin-bottom: 16px;
}
}

.wp-block-navigation__submenu-accessibility-notice {
grid-column: span 2;
}
Loading