From 0b106694d9417eb7964d672cc042c279defbbdd0 Mon Sep 17 00:00:00 2001 From: Vicente Canales Date: Tue, 9 Nov 2021 15:40:35 -0300 Subject: [PATCH] allow using a text label toggle instead of icon --- docs/reference-guides/core-blocks.md | 2 +- .../block-library/src/navigation/block.json | 4 ++ .../src/navigation/edit/index.js | 42 ++++++++++++++++++- .../src/navigation/edit/overlay-menu-icon.js | 21 ++++++++++ .../src/navigation/edit/responsive-wrapper.js | 25 ++++++----- .../block-library/src/navigation/editor.scss | 16 +++++++ .../block-library/src/navigation/index.php | 9 +++- .../block-library/src/navigation/style.scss | 6 +++ .../fixtures/blocks/core__navigation.json | 3 +- 9 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 packages/block-library/src/navigation/edit/overlay-menu-icon.js diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index 7909e92891194..1fb83ef0652ed 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -366,7 +366,7 @@ A collection of blocks that allow visitors to get around your site. ([Source](ht - **Name:** core/navigation - **Category:** theme - **Supports:** align (full, wide), anchor, inserter, spacing (blockGap, units), typography (fontSize, lineHeight), ~~html~~ -- **Attributes:** __unstableLocation, backgroundColor, customBackgroundColor, customOverlayBackgroundColor, customOverlayTextColor, customTextColor, openSubmenusOnClick, overlayBackgroundColor, overlayMenu, overlayTextColor, ref, rgbBackgroundColor, rgbTextColor, showSubmenuIcon, textColor +- **Attributes:** __unstableLocation, backgroundColor, customBackgroundColor, customOverlayBackgroundColor, customOverlayTextColor, customTextColor, hasIcon, openSubmenusOnClick, overlayBackgroundColor, overlayMenu, overlayTextColor, ref, rgbBackgroundColor, rgbTextColor, showSubmenuIcon, textColor ## Navigation Area diff --git a/packages/block-library/src/navigation/block.json b/packages/block-library/src/navigation/block.json index b2346bad70267..af877a768c1b1 100644 --- a/packages/block-library/src/navigation/block.json +++ b/packages/block-library/src/navigation/block.json @@ -41,6 +41,10 @@ "type": "string", "default": "mobile" }, + "hasIcon": { + "type": "boolean", + "default": true + }, "__unstableLocation": { "type": "string" }, diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index d5e4c5d168c6e..261176369d960 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -54,6 +54,7 @@ import NavigationMenuNameControl from './navigation-menu-name-control'; import UnsavedInnerBlocks from './unsaved-inner-blocks'; import NavigationMenuDeleteControl from './navigation-menu-delete-control'; import useNavigationNotice from './use-navigation-notice'; +import OverlayMenuIcon from './overlay-menu-icon'; const EMPTY_ARRAY = []; @@ -116,6 +117,7 @@ function Navigation( { orientation = 'horizontal', flexWrap = 'wrap', } = {}, + hasIcon, } = attributes; let areaMenu, @@ -208,6 +210,8 @@ function Navigation( { false ); + const [ overlayMenuPreview, setOverlayMenuPreview ] = useState( false ); + const { isNavigationMenuResolved, isNavigationMenuMissing, @@ -462,6 +466,13 @@ function Navigation( { ? CustomPlaceholder : Placeholder; + const isResponsive = 'never' !== overlayMenu; + + const overlayMenuPreviewClasses = classnames( + 'wp-block-navigation__overlay-menu-preview', + { open: overlayMenuPreview } + ); + return ( @@ -492,6 +503,33 @@ function Navigation( { { hasSubmenuIndicatorSetting && ( + { isResponsive && ( + + ) } + { overlayMenuPreview && ( + + setAttributes( { hasIcon: value } ) + } + checked={ hasIcon } + /> + ) }

{ __( 'Overlay Menu' ) }