Skip to content
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
191 changes: 127 additions & 64 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ import { EntityProvider, store as coreStore } from '@wordpress/core-data';

import { useDispatch, useSelect } from '@wordpress/data';
import {
PanelBody,
ToggleControl,
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
__experimentalVStack as VStack,
ToggleControl,
Button,
Spinner,
Notice,
Expand Down Expand Up @@ -72,6 +74,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 +586,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,88 +632,134 @@ function Navigation( {
</>
) }
</Button>
<div id={ overlayMenuPreviewId }>
{ overlayMenuPreview && (
{ overlayMenuPreview && (
<VStack
id={ overlayMenuPreviewId }
spacing={ 4 }
style={ {
gridColumn: 'span 2',
} }
>
<OverlayMenuPreview
setAttributes={ setAttributes }
hasIcon={ hasIcon }
icon={ icon }
hidden={ ! overlayMenuPreview }
/>
) }
</div>
</VStack>
) }
</>
) }
<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>
<Notice
spokenMessage={ null }
status="warning"
isDismissible={ false }
>
{ submenuAccessibilityNotice }
</Notice>
</div>
<Notice
spokenMessage={ null }
status="warning"
isDismissible={ false }
className="wp-block-navigation__submenu-accessibility-notice"
>
{ submenuAccessibilityNotice }
</Notice>
) }
</>
) }
</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>
</>
);
}
12 changes: 8 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,11 @@ 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__submenu-accessibility-notice {
grid-column: span 2;
}
Loading