diff --git a/packages/block-library/src/navigation/edit.js b/packages/block-library/src/navigation/edit.js index ab5f40cc040fa..9d4f0b622f4fc 100644 --- a/packages/block-library/src/navigation/edit.js +++ b/packages/block-library/src/navigation/edit.js @@ -1,7 +1,8 @@ /** * External dependencies */ -import { escape } from 'lodash'; +import { escape, upperFirst } from 'lodash'; +import classnames from 'classnames'; /** * WordPress dependencies @@ -25,6 +26,7 @@ import { PanelBody, Placeholder, Spinner, + Toolbar, ToolbarGroup, } from '@wordpress/components'; import { compose } from '@wordpress/compose'; @@ -37,6 +39,7 @@ import { __ } from '@wordpress/i18n'; import useBlockNavigator from './use-block-navigator'; import BlockNavigationList from './block-navigation-list'; import BlockColorsStyleSelector from './block-colors-selector'; +import * as navIcons from './icons'; function Navigation( { attributes, @@ -84,18 +87,30 @@ function Navigation( { // // HANDLERS // + function handleItemsAlignment( align ) { + return () => { + const itemsJustification = attributes.itemsJustification === align ? undefined : align; + setAttributes( { + itemsJustification, + } ); + }; + } - const handleCreateEmpty = () => { + function handleCreateEmpty() { const emptyNavLinkBlock = createBlock( 'core/navigation-link' ); updateNavItemBlocks( [ emptyNavLinkBlock ] ); - }; + } - const handleCreateFromExistingPages = () => { + function handleCreateFromExistingPages() { updateNavItemBlocks( defaultPagesNavigationItems ); - }; + } const hasPages = hasResolvedPages && pages && pages.length; + const blockClassNames = classnames( 'wp-block-navigation', { + [ `items-justification-${ attributes.itemsJustification }` ]: attributes.itemsJustification, + } ); + // If we don't have existing items or the User hasn't // indicated they want to automatically add top level Pages // then show the Placeholder @@ -152,6 +167,16 @@ function Navigation( { return ( + { navigatorToolbarButton } @@ -159,6 +184,7 @@ function Navigation( { value={ TextColor.color } onChange={ TextColor.setColor } /> + { navigatorModal } @@ -181,7 +207,7 @@ function Navigation( { -
+
{ ! hasExistingNavItems && isRequestingPages && <> { __( 'Loading Navigation…' ) } } .block-editor-block-list__layout { margin-left: 0; margin-right: 0; + } + + .wp-block-navigation.items-justification-left .block-editor-inner-blocks > .block-editor-block-list__layout { + justify-content: flex-start; + } + + .wp-block-navigation.items-justification-center .block-editor-inner-blocks > .block-editor-block-list__layout { + justify-content: center; + } + .wp-block-navigation.items-justification-right .block-editor-inner-blocks > .block-editor-block-list__layout { + justify-content: flex-end; } // 2. Remove paddings on subsequent immediate children. diff --git a/packages/block-library/src/navigation/icons.js b/packages/block-library/src/navigation/icons.js new file mode 100644 index 0000000000000..fbfd742bd712f --- /dev/null +++ b/packages/block-library/src/navigation/icons.js @@ -0,0 +1,20 @@ +/** + * WordPress dependencies + */ +import { Path, SVG } from '@wordpress/components'; + +export const justifyLeftIcon = ( + + + +); + +export const justifyCenterIcon = ( + + + +); + +export const justifyRightIcon = ( + +); diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 68a395a9625f5..22294da8b0e34 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -15,7 +15,7 @@ function build_css_colors( $attributes ) { // CSS classes. $colors = array( - 'css_classes' => [], + 'css_classes' => array(), 'inline_styles' => '', ); @@ -52,8 +52,10 @@ function render_block_navigation( $attributes, $content, $block ) { $colors = build_css_colors( $attributes ); $classes = array_merge( $colors['css_classes'], - [ 'wp-block-navigation' ], - isset( $attributes['className'] ) ? [ $attributes['className'] ] : [] + array( 'wp-block-navigation' ), + isset( $attributes['className'] ) ? array( $attributes['className'] ) : array(), + isset( $attributes['itemsJustification'] ) ? array( 'items-justified-' . $attributes['itemsJustification'] ) : array(), + isset( $attributes['align'] ) ? array( 'align' . $attributes['align'] ) : array() ); $class_attribute = sprintf( ' class="%s"', esc_attr( implode( ' ', $classes ) ) ); $style_attribute = $colors['inline_styles'] ? sprintf( ' style="%s"', esc_attr( $colors['inline_styles'] ) ) : ''; @@ -127,17 +129,20 @@ function register_block_core_navigation() { 'core/navigation', array( 'attributes' => array( - 'className' => array( + 'className' => array( 'type' => 'string', ), - 'automaticallyAdd' => array( + 'automaticallyAdd' => array( 'type' => 'boolean', 'default' => false, ), - 'textColor' => array( + 'textColor' => array( 'type' => 'string', ), - 'customTextColor' => array( + 'customTextColor' => array( + 'type' => 'string', + ), + 'itemsJustification' => array( 'type' => 'string', ), ), diff --git a/packages/block-library/src/navigation/style.scss b/packages/block-library/src/navigation/style.scss index e6309dd048e65..b309aa2c16599 100644 --- a/packages/block-library/src/navigation/style.scss +++ b/packages/block-library/src/navigation/style.scss @@ -142,6 +142,17 @@ } } + &.items-justified-left > ul { + justify-content: flex-start; + } + + &.items-justified-center > ul { + justify-content: center; + } + + &.items-justified-right > ul { + justify-content: flex-end; + } } .is-style-dark > ul > li > ul {