diff --git a/packages/block-library/src/navigation/block.json b/packages/block-library/src/navigation/block.json index 273ac75dd65f3e..2822b03081f024 100644 --- a/packages/block-library/src/navigation/block.json +++ b/packages/block-library/src/navigation/block.json @@ -4,7 +4,11 @@ "title": "Navigation", "category": "theme", "description": "A collection of blocks that allow visitors to get around your site.", - "keywords": [ "menu", "navigation", "links" ], + "keywords": [ + "menu", + "navigation", + "links" + ], "textdomain": "default", "attributes": { "orientation": { @@ -36,13 +40,13 @@ "type": "boolean", "default": true }, - "openSubmenusOnClick":{ + "openSubmenusOnClick": { "type": "boolean", "default": false }, - "isResponsive": { - "type": "boolean", - "default": false + "overlayMenu": { + "type": "string", + "default": "never" }, "__unstableLocation": { "type": "string" @@ -77,7 +81,10 @@ "orientation": "orientation" }, "supports": { - "align": [ "wide", "full" ], + "align": [ + "wide", + "full" + ], "anchor": true, "html": false, "inserter": true, diff --git a/packages/block-library/src/navigation/deprecated.js b/packages/block-library/src/navigation/deprecated.js index 0ee64c0a44da89..f41acc381bda65 100644 --- a/packages/block-library/src/navigation/deprecated.js +++ b/packages/block-library/src/navigation/deprecated.js @@ -15,7 +15,92 @@ const TYPOGRAPHY_PRESET_DEPRECATION_MAP = { textTransform: 'var:preset|text-transform|', }; -export default [ +const deprecated = [ + // Remove `isResponsive` attribute. + { + attributes: { + orientation: { + type: 'string', + default: 'horizontal', + }, + textColor: { + type: 'string', + }, + customTextColor: { + type: 'string', + }, + rgbTextColor: { + type: 'string', + }, + backgroundColor: { + type: 'string', + }, + customBackgroundColor: { + type: 'string', + }, + rgbBackgroundColor: { + type: 'string', + }, + itemsJustification: { + type: 'string', + }, + showSubmenuIcon: { + type: 'boolean', + default: true, + }, + openSubmenusOnClick: { + type: 'boolean', + default: false, + }, + isResponsive: { + type: 'boolean', + default: 'false', + }, + __unstableLocation: { + type: 'string', + }, + overlayBackgroundColor: { + type: 'string', + }, + customOverlayBackgroundColor: { + type: 'string', + }, + overlayTextColor: { + type: 'string', + }, + customOverlayTextColor: { + type: 'string', + }, + }, + supports: { + align: [ 'wide', 'full' ], + anchor: true, + html: false, + inserter: true, + typography: { + fontSize: true, + lineHeight: true, + __experimentalFontStyle: true, + __experimentalFontWeight: true, + __experimentalTextTransform: true, + __experimentalFontFamily: true, + __experimentalTextDecoration: true, + }, + }, + isEligible( attributes ) { + return attributes.isResponsive; + }, + migrate( attributes ) { + delete attributes.isResponsive; + return { + ...attributes, + overlayMenu: 'mobile', + }; + }, + save() { + return ; + }, + }, { attributes: { orientation: { @@ -163,3 +248,5 @@ export default [ }, }, ]; + +export default deprecated; diff --git a/packages/block-library/src/navigation/edit.js b/packages/block-library/src/navigation/edit.js index d5ef92a4c894f2..77740d91a619d7 100644 --- a/packages/block-library/src/navigation/edit.js +++ b/packages/block-library/src/navigation/edit.js @@ -26,7 +26,13 @@ import { getColorClassName, } from '@wordpress/block-editor'; import { useDispatch, withSelect, withDispatch } from '@wordpress/data'; -import { PanelBody, ToggleControl, ToolbarGroup } from '@wordpress/components'; +import { + PanelBody, + ToggleControl, + __experimentalToggleGroupControl as ToggleGroupControl, + __experimentalToggleGroupControlOption as ToggleGroupControlOption, + ToolbarGroup, +} from '@wordpress/components'; import { compose } from '@wordpress/compose'; import { __ } from '@wordpress/i18n'; @@ -135,7 +141,7 @@ function Navigation( { className: classnames( className, { [ `items-justified-${ attributes.itemsJustification }` ]: attributes.itemsJustification, 'is-vertical': attributes.orientation === 'vertical', - 'is-responsive': attributes.isResponsive, + 'is-responsive': 'never' !== attributes.overlayMenu, 'has-text-color': !! textColor.color || !! textColor?.class, [ getColorClassName( 'color', @@ -271,16 +277,34 @@ function Navigation( { { navigatorModal } { hasSubmenuIndicatorSetting && ( - - { - setAttributes( { - isResponsive: value, - } ); - } } - label={ __( 'Enable responsive menu' ) } - /> + +

{ __( 'Overlay Menu' ) }

+ + setAttributes( { overlayMenu: value } ) + } + isBlock + hideLabelFromVision + > + + + + +

{ __( 'Submenus' ) }

{ @@ -288,7 +312,7 @@ function Navigation( { openSubmenusOnClick: value, } ); } } - label={ __( 'Open submenus on click' ) } + label={ __( 'Open on click' ) } /> { ! attributes.openSubmenusOnClick && ( ) }
@@ -352,7 +376,8 @@ function Navigation( { id={ clientId } onToggle={ setResponsiveMenuVisibility } isOpen={ isResponsiveMenuOpen } - isResponsive={ attributes.isResponsive } + isResponsive={ 'never' !== attributes.overlayMenu } + isHiddenByDefault={ 'always' === attributes.overlayMenu } >
diff --git a/packages/block-library/src/navigation/editor.scss b/packages/block-library/src/navigation/editor.scss index 07afc4ceb4394e..5906cbe7993226 100644 --- a/packages/block-library/src/navigation/editor.scss +++ b/packages/block-library/src/navigation/editor.scss @@ -397,12 +397,6 @@ $color-control-label-height: 20px; } } } -.components-button.wp-block-navigation__responsive-container-open { - @include break-small { - display: none; - } -} - // Emulate the fullscreen editing inside the editor. // Most of this can be removed when the iframe lands. diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 5b4b03f3a420d9..32c3fbea0ef462 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -218,7 +218,12 @@ function render_block_core_navigation( $attributes, $content, $block ) { unset( $attributes['rgbTextColor'], $attributes['rgbBackgroundColor'] ); - $should_load_view_script = ! wp_script_is( 'wp-block-navigation-view' ) && ( ! empty( $attributes['isResponsive'] ) || $attributes['openSubmenusOnClick'] || $attributes['showSubmenuIcon'] ); + /** + * This is for backwards compatibility after `isResponsive` attribute has been removed. + */ + $has_old_responsive_attribute = ! empty( $attributes['isResponsive'] ) && $attributes['isResponsive']; + $is_responsive_menu = isset( $attributes['overlayMenu'] ) && 'never' !== $attributes['overlayMenu'] || $has_old_responsive_attribute; + $should_load_view_script = ! wp_script_is( 'wp-block-navigation-view' ) && ( $is_responsive_menu || $attributes['openSubmenusOnClick'] || $attributes['showSubmenuIcon'] ); if ( $should_load_view_script ) { wp_enqueue_script( 'wp-block-navigation-view' ); } @@ -250,7 +255,7 @@ function render_block_core_navigation( $attributes, $content, $block ) { $font_sizes['css_classes'], ( isset( $attributes['orientation'] ) && 'vertical' === $attributes['orientation'] ) ? array( 'is-vertical' ) : array(), isset( $attributes['itemsJustification'] ) ? array( 'items-justified-' . $attributes['itemsJustification'] ) : array(), - isset( $attributes['isResponsive'] ) && true === $attributes['isResponsive'] ? array( 'is-responsive' ) : array() + $is_responsive_menu ? array( 'is-responsive' ) : array() ); $inner_blocks_html = ''; @@ -288,7 +293,7 @@ function render_block_core_navigation( $attributes, $content, $block ) { // Determine whether or not navigation elements should be wrapped in the markup required to make it responsive, // return early if they don't. - if ( ! isset( $attributes['isResponsive'] ) || false === $attributes['isResponsive'] ) { + if ( ! $is_responsive_menu ) { return sprintf( '', $wrapper_attributes, @@ -296,9 +301,20 @@ function render_block_core_navigation( $attributes, $content, $block ) { ); } + $is_hidden_by_default = isset( $attributes['overlayMenu'] ) && 'always' === $attributes['overlayMenu']; + + $responsive_container_classes = array( + 'wp-block-navigation__responsive-container', + $is_hidden_by_default ? 'hidden-by-default' : '', + ); + $open_button_classes = array( + 'wp-block-navigation__responsive-container-open', + $is_hidden_by_default ? 'always-shown' : '', + ); + $responsive_container_markup = sprintf( - ' -