Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename "Navigation Menu Item" to "Link". #18422

Merged
merged 7 commits into from
Nov 15, 2019
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
2 changes: 1 addition & 1 deletion packages/block-library/src/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
@import "./legacy-widget/editor.scss";
@import "./media-text/editor.scss";
@import "./more/editor.scss";
@import "./navigation-link/editor.scss";
@import "./navigation-menu/editor.scss";
@import "./navigation-menu-item/editor.scss";
@import "./nextpage/editor.scss";
@import "./paragraph/editor.scss";
@import "./pullquote/editor.scss";
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import * as embed from './embed';
import * as file from './file';
import * as html from './html';
import * as mediaText from './media-text';
import * as navigationLink from './navigation-link';
import * as navigationMenu from './navigation-menu';
import * as navigationMenuItem from './navigation-menu-item';
import * as latestComments from './latest-comments';
import * as latestPosts from './latest-posts';
import * as legacyWidget from './legacy-widget';
Expand Down Expand Up @@ -179,7 +179,7 @@ export const __experimentalRegisterExperimentalCoreBlocks =
;[
__experimentalEnableLegacyWidgetBlock ? legacyWidget : null,
__experimentalEnableMenuBlock ? navigationMenu : null,
__experimentalEnableMenuBlock ? navigationMenuItem : null,
__experimentalEnableMenuBlock ? navigationLink : null,
socialLinks,
...socialLink.sites,

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "core/navigation-menu-item",
"name": "core/navigation-link",
"category": "layout",
"attributes": {
"label": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const updateLinkSetting = ( setter ) => ( setting, value ) => {
* through of the `onLinkChange` LinkControl callback.
*
* @param {Function} setter Setter attribute function.
* @param {string} label ItemMenu link label.
* @param {string} label Link label.
*/
const updateLink = ( setter, label ) => ( { title: newTitle = '', url: newURL = '' } = {} ) => {
setter( {
Expand All @@ -70,13 +70,13 @@ const updateLink = ( setter, label ) => ( { title: newTitle = '', url: newURL =
}
};

function NavigationMenuItemEdit( {
function NavigationLinkEdit( {
attributes,
hasDescendants,
isSelected,
isParentOfSelectedBlock,
setAttributes,
insertMenuItemBlock,
insertLinkBlock,
} ) {
const { label, opensInNewTab, title, url } = attributes;
const link = title ? { title, url } : null;
Expand Down Expand Up @@ -116,7 +116,7 @@ function NavigationMenuItemEdit( {
* `onKeyDown` LinkControl handler.
* It takes over to stop the event propagation to make the
* navigation work, avoiding undesired behaviors.
* For instance, it will block to move between menu items
* For instance, it will block to move between link blocks
* when the LinkControl is focused.
*
* @param {Event} event
Expand All @@ -130,7 +130,7 @@ function NavigationMenuItemEdit( {
}
};

const itemLabelPlaceholder = __( 'Add item…' );
const itemLabelPlaceholder = __( 'Add link…' );

return (
<Fragment>
Expand All @@ -152,14 +152,14 @@ function NavigationMenuItemEdit( {
<ToolbarButton
name="submenu"
icon={ <SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24"><Path d="M14 5h8v2h-8zm0 5.5h8v2h-8zm0 5.5h8v2h-8zM2 11.5C2 15.08 4.92 18 8.5 18H9v2l3-3-3-3v2h-.5C6.02 16 4 13.98 4 11.5S6.02 7 8.5 7H12V5H8.5C4.92 5 2 7.92 2 11.5z" /><Path fill="none" d="M0 0h24v24H0z" /></SVG> }
title={ __( 'Add submenu item' ) }
onClick={ insertMenuItemBlock }
title={ __( 'Add Submenu' ) }
onClick={ insertLinkBlock }
/>
</Toolbar>
</BlockControls>
<InspectorControls>
<PanelBody
title={ __( 'Menu Settings' ) }
title={ __( 'Link Settings' ) }
>
<ToggleControl
checked={ attributes.opensInNewTab }
Expand Down Expand Up @@ -192,12 +192,12 @@ function NavigationMenuItemEdit( {
onChange={ ( nofollow ) => {
setAttributes( { nofollow } );
} }
label={ __( 'Add nofollow to menu item' ) }
label={ __( 'Add nofollow to link' ) }
help={ (
<Fragment>
{ __( 'Don\'t let search engines follow this link.' ) }
<ExternalLink
className="wp-block-navigation-menu-item__nofollow-external-link"
className="wp-block-navigation-link__nofollow-external-link"
href={ __( 'https://codex.wordpress.org/Nofollow' ) }
>
{ __( 'What\'s this?' ) }
Expand All @@ -208,23 +208,23 @@ function NavigationMenuItemEdit( {
</PanelBody>
</InspectorControls>
<div className={ classnames(
'wp-block-navigation-menu-item', {
'wp-block-navigation-link', {
'is-editing': isSelected || isParentOfSelectedBlock,
'is-selected': isSelected,
'has-link': !! url,
} ) }
>
<div className="wp-block-navigation-menu-item__inner">
<div className="wp-block-navigation-link__inner">
<RichText
className="wp-block-navigation-menu-item__content"
className="wp-block-navigation-link__content"
value={ label }
onChange={ ( labelValue ) => setAttributes( { label: labelValue } ) }
placeholder={ itemLabelPlaceholder }
withoutInteractiveFormatting
/>
{ isLinkOpen && (
<LinkControl
className="wp-block-navigation-menu-item__inline-link-input"
className="wp-block-navigation-link__inline-link-input"
onKeyDown={ handleLinkControlOnKeyDown }
onKeyPress={ ( event ) => event.stopPropagation() }
currentLink={ link }
Expand All @@ -244,7 +244,7 @@ function NavigationMenuItemEdit( {
) }
</div>
<InnerBlocks
allowedBlocks={ [ 'core/navigation-menu-item' ] }
allowedBlocks={ [ 'core/navigation-link' ] }
renderAppender={ hasDescendants ? InnerBlocks.ButtonBlockAppender : false }
/>
</div>
Expand All @@ -264,7 +264,7 @@ export default compose( [
} ),
withDispatch( ( dispatch, ownProps, registry ) => {
return {
insertMenuItemBlock() {
insertLinkBlock() {
const { clientId } = ownProps;

const {
Expand All @@ -275,7 +275,7 @@ export default compose( [
const navItems = getClientIdsOfDescendants( [ clientId ] );
const insertionPoint = navItems.length ? navItems.length : 0;

const blockToInsert = createBlock( 'core/navigation-menu-item' );
const blockToInsert = createBlock( 'core/navigation-link' );

insertBlock(
blockToInsert,
Expand All @@ -285,4 +285,4 @@ export default compose( [
},
};
} ),
] )( NavigationMenuItemEdit );
] )( NavigationLinkEdit );
Original file line number Diff line number Diff line change
@@ -1,45 +1,21 @@

// Normalize menu items and edit containers, to look mostly the same.
.wp-block-navigation-menu-item__field .components-text-control__input.components-text-control__input,
.wp-block-navigation-menu-item__container {
.wp-block-navigation-link__field .components-text-control__input.components-text-control__input,
.wp-block-navigation-link__container {
border-radius: 0;
// Make it the same height as the appender to prevent a jump. Maybe revisit this.
line-height: $icon-button-size;
min-height: $icon-button-size;
}

.wp-block-navigation-menu-item {
margin-right: $grid-size;

.block-editor-block-list__layout {
display: block;
margin: $grid-size;
}

// Provide a base menu item margin.
// This should be the same inside the field,
// and the edit container should compensate.
// This is to make sure the edit and view are the same.
padding: 0 $grid-size;

// Only display inner blocks when the block is being edited.
.block-editor-inner-blocks {
display: none;
}

&.is-editing .block-editor-inner-blocks {
display: block;
}
}

.wp-block-navigation-menu-item__edit-container {
.wp-block-navigation-link__edit-container {
display: flex;
white-space: nowrap;

// Compensate for menu item base padding.
margin-left: -$grid-size;

.wp-block-navigation-menu-item__content {
.wp-block-navigation-link__content {
margin-right: $grid-size;

// This should match the padding of the menu item.
Expand All @@ -63,13 +39,13 @@
}
}

.wp-block-navigation-menu-item {
.wp-block-navigation-link {
&.is-editing,
&.is-selected {
min-width: 20px;
}

&.has-link .wp-block-navigation-menu-item__content {
&.has-link .wp-block-navigation-link__content {
border-bottom-style: solid;
border-bottom-width: 1px;
}
Expand All @@ -79,27 +55,27 @@
}
}

.wp-block-navigation-menu-item__nofollow-external-link {
.wp-block-navigation-link__nofollow-external-link {
display: block;
}

// Separator
.wp-block-navigation-menu-item__separator {
.wp-block-navigation-link__separator {
margin: $grid-size 0 $grid-size;
border-top: $border-width solid $light-gray-500;
}

// Popover styles
.components-popover:not(.is-mobile).wp-block-navigation-menu-item__dropdown-content {
.components-popover:not(.is-mobile).wp-block-navigation-link__dropdown-content {
margin-top: -1px;
margin-left: -4px;
}

.wp-block-navigation-menu-item__dropdown-content .components-popover__content {
.wp-block-navigation-link__dropdown-content .components-popover__content {
padding: $grid-size 0;
}

.wp-block-navigation-menu .block-editor-block-list__block[data-type="core/navigation-menu-item"] {
.wp-block-navigation-menu .block-editor-block-list__block[data-type="core/navigation-link"] {
& > .block-editor-block-list__insertion-point {
display: none;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ const { name } = metadata;
export { metadata, name };

export const settings = {
title: __( 'Menu Item' ),
title: __( 'Navigation Link' ),

parent: [ 'core/navigation-menu' ],

icon: <SVG xmlns="http://www.w3.org/2000/svg" width="24" height="24"><Path d="M12 7.27l4.28 10.43-3.47-1.53-.81-.36-.81.36-3.47 1.53L12 7.27M12 2L4.5 20.29l.71.71L12 18l6.79 3 .71-.71L12 2z" /></SVG>,

description: __( 'Add a page, link, or other item to your Navigation Menu.' ),
description: __( 'Add a page, link, or other item to your navigation.' ),

__experimentalDisplayName: 'label',

Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/navigation-menu/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function NavigationMenu( {
}

return pages.map( ( { title, type, link: url, id } ) => (
createBlock( 'core/navigation-menu-item',
createBlock( 'core/navigation-link',
{
type,
id,
Expand All @@ -91,7 +91,7 @@ function NavigationMenu( {
//

const handleCreateEmpty = () => {
const emptyNavItemBlock = createBlock( 'core/navigation-menu-item' );
const emptyNavItemBlock = createBlock( 'core/navigation-link' );
updateNavItemBlocks( [ emptyNavItemBlock ] );
};

Expand Down Expand Up @@ -210,7 +210,7 @@ function NavigationMenu( {
{ ! hasExistingNavItems && isRequestingPages && <><Spinner /> { __( 'Loading Navigation…' ) } </> }

<InnerBlocks
allowedBlocks={ [ 'core/navigation-menu-item' ] }
allowedBlocks={ [ 'core/navigation-link' ] }
templateInsertUpdatesSelection={ false }
__experimentalMoverDirection={ 'horizontal' }
/>
Expand Down
27 changes: 24 additions & 3 deletions packages/block-library/src/navigation-menu/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,31 @@
padding: $grid-size-large;
}

.wp-block-navigation-menu-item {
/*
* Adjust Navigation Item with Menu.
*/
.wp-block-navigation-menu .wp-block-navigation-link {
margin-right: $grid-size;
margin-left: $grid-size;
.wp-block-navigation-menu-item__link {
margin-left: $grid-size-large;

.block-editor-block-list__layout {
display: block;
margin: $grid-size;
}

// Provide a base menu item margin.
// This should be the same inside the field,
// and the edit container should compensate.
// This is to make sure the edit and view are the same.
padding: 0 $grid-size;

// Only display inner blocks when the block is being edited.
.block-editor-inner-blocks {
display: none;
}

&.is-editing .block-editor-inner-blocks {
display: block;
}
}

Expand Down
20 changes: 10 additions & 10 deletions packages/block-library/src/navigation-menu/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,36 @@ function render_block_navigation_menu( $attributes, $content, $block ) {
*/
function build_navigation_menu_html( $block, $colors ) {
$html = '';
foreach ( (array) $block['innerBlocks'] as $key => $menu_item ) {
foreach ( (array) $block['innerBlocks'] as $key => $block ) {

$html .= '<li class="wp-block-navigation-menu-item">' .
'<a
class="wp-block-navigation-menu-item__link ' . $colors['text_css_classes'] . '"
' . $colors['text_inline_styles'];

// Start appending HTML attributes to anchor tag.
if ( isset( $menu_item['attrs']['url'] ) ) {
$html .= ' href="' . $menu_item['attrs']['url'] . '"';
if ( isset( $block['attrs']['url'] ) ) {
$html .= ' href="' . $block['attrs']['url'] . '"';
}
if ( isset( $menu_item['attrs']['title'] ) ) {
$html .= ' title="' . $menu_item['attrs']['title'] . '"';
if ( isset( $block['attrs']['title'] ) ) {
$html .= ' title="' . $block['attrs']['title'] . '"';
}

if ( isset( $menu_item['attrs']['opensInNewTab'] ) && true === $menu_item['attrs']['opensInNewTab'] ) {
if ( isset( $block['attrs']['opensInNewTab'] ) && true === $block['attrs']['opensInNewTab'] ) {
$html .= ' target="_blank" ';
}
// End appending HTML attributes to anchor tag.

// Start anchor tag content.
$html .= '>';
if ( isset( $menu_item['attrs']['label'] ) ) {
$html .= $menu_item['attrs']['label'];
if ( isset( $block['attrs']['label'] ) ) {
$html .= $block['attrs']['label'];
}
$html .= '</a>';
// End anchor tag content.

if ( count( (array) $menu_item['innerBlocks'] ) > 0 ) {
$html .= build_navigation_menu_html( $menu_item, $colors );
if ( count( (array) $block['innerBlocks'] ) > 0 ) {
$html .= build_navigation_menu_html( $block, $colors );
}

$html .= '</li>';
Expand Down
Loading