From 0ac7634f7a30513dd493a87d44cd3a1fed244fe8 Mon Sep 17 00:00:00 2001 From: Vicente Canales Date: Tue, 9 Nov 2021 15:40:35 -0300 Subject: [PATCH] enable selection between icon and label --- .../block-library/src/navigation/block.json | 4 ++ .../src/navigation/edit/index.js | 47 ++++++++++++++++++- .../src/navigation/edit/overlay-menu-icon.js | 21 +++++++++ .../src/navigation/edit/responsive-wrapper.js | 26 +++++----- .../block-library/src/navigation/editor.scss | 12 +++++ .../block-library/src/navigation/index.php | 11 +++-- .../block-library/src/navigation/style.scss | 6 +++ .../fixtures/blocks/core__navigation.json | 3 +- 8 files changed, 111 insertions(+), 19 deletions(-) create mode 100644 packages/block-library/src/navigation/edit/overlay-menu-icon.js diff --git a/packages/block-library/src/navigation/block.json b/packages/block-library/src/navigation/block.json index 95e73d6eefcbe..f22cf73cfce3b 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" }, + "useIcon": { + "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 cea0281d33e91..1a0a89b064ae8 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -34,6 +34,7 @@ import { __experimentalToggleGroupControlOption as ToggleGroupControlOption, ToolbarGroup, ToolbarDropdownMenu, + Button, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; @@ -51,6 +52,7 @@ import NavigationMenuNameControl from './navigation-menu-name-control'; import NavigationMenuPublishButton from './navigation-menu-publish-button'; import UnsavedInnerBlocks from './unsaved-inner-blocks'; import NavigationMenuDeleteControl from './navigation-menu-delete-control'; +import OverlayMenuIcon from './overlay-menu-icon'; function getComputedStyle( node ) { return node.ownerDocument.defaultView.getComputedStyle( node ); @@ -104,10 +106,12 @@ function Navigation( { } ) { const { itemsJustification, + label, openSubmenusOnClick, orientation, overlayMenu, showSubmenuIcon, + useIcon, } = attributes; const [ areaMenu, setAreaMenu ] = useEntityProp( @@ -167,6 +171,8 @@ function Navigation( { false ); + const [ overlayMenuPreview, setOverlayMenuPreview ] = useState( false ); + const { isNavigationMenuResolved, isNavigationMenuMissing, @@ -299,6 +305,13 @@ function Navigation( { ? CustomPlaceholder : Placeholder; + const isResponsive = 'never' !== overlayMenu; + + const overlayMenuPreviewClasses = classnames( + 'wp-block-navigation__overlay-menu-preview', + { open: overlayMenuPreview } + ); + return (

{ __( 'Overlay Menu' ) }

+ { isResponsive && ( + + ) } + { overlayMenuPreview && ( + + setAttributes( { useIcon: value } ) + } + checked={ useIcon } + /> + ) } + setAttributes( { label: value } ) + } + label={ label } + useIcon={ useIcon } isOpen={ isResponsiveMenuOpen } - isResponsive={ 'never' !== overlayMenu } + isResponsive={ isResponsive } isHiddenByDefault={ 'always' === overlayMenu } > { isEntityAvailable && ( diff --git a/packages/block-library/src/navigation/edit/overlay-menu-icon.js b/packages/block-library/src/navigation/edit/overlay-menu-icon.js new file mode 100644 index 0000000000000..bec698763e521 --- /dev/null +++ b/packages/block-library/src/navigation/edit/overlay-menu-icon.js @@ -0,0 +1,21 @@ +/** + * WordPress dependencies + */ +import { SVG, Rect } from '@wordpress/primitives'; + +export default function OverlayMenuIcon() { + return ( + + ); +} diff --git a/packages/block-library/src/navigation/edit/responsive-wrapper.js b/packages/block-library/src/navigation/edit/responsive-wrapper.js index 7030e8e7914ab..494a54f356041 100644 --- a/packages/block-library/src/navigation/edit/responsive-wrapper.js +++ b/packages/block-library/src/navigation/edit/responsive-wrapper.js @@ -8,9 +8,13 @@ import classnames from 'classnames'; */ import { close, Icon } from '@wordpress/icons'; import { Button } from '@wordpress/components'; -import { SVG, Rect } from '@wordpress/primitives'; import { __ } from '@wordpress/i18n'; +/** + * Internal dependencies + */ +import OverlayMenuIcon from './overlay-menu-icon'; + export default function ResponsiveWrapper( { children, id, @@ -18,6 +22,7 @@ export default function ResponsiveWrapper( { isResponsive, onToggle, isHiddenByDefault, + useIcon, } ) { if ( ! isResponsive ) { return children; @@ -46,21 +51,14 @@ export default function ResponsiveWrapper( { className={ openButtonClasses } onClick={ () => onToggle( true ) } > - + { useIcon && } + { ! useIcon && ( + + { __( 'Menu' ) } + + ) } ) } -