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

Adds vertical variation to navigation menu #21296

Merged
merged 7 commits into from
Apr 2, 2020
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
5 changes: 4 additions & 1 deletion packages/block-library/src/navigation/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function Navigation( {
const blockClassNames = classnames( className, {
[ `items-justified-${ attributes.itemsJustification }` ]: attributes.itemsJustification,
[ fontSize.class ]: fontSize.class,
'is-vertical': attributes.orientation === 'vertical',
} );
const blockInlineStyles = {
fontSize: fontSize.size ? fontSize.size + 'px' : undefined,
Expand Down Expand Up @@ -270,7 +271,9 @@ function Navigation( {
ref={ ref }
allowedBlocks={ [ 'core/navigation-link' ] }
templateInsertUpdatesSelection={ false }
__experimentalMoverDirection={ 'horizontal' }
__experimentalMoverDirection={
attributes.orientation
}
__experimentalTagName="ul"
__experimentalAppenderTagName="li"
__experimentalPassedProps={ {
Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/navigation/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ $navigation-item-height: 46px;
align-items: center;
}

.wp-block-navigation.is-vertical .block-list-appender {
draganescu marked this conversation as resolved.
Show resolved Hide resolved
margin: $grid-unit-10;
}

.wp-block-navigation__inserter-content {
padding: $grid-unit-20;
}
Expand Down
16 changes: 16 additions & 0 deletions packages/block-library/src/navigation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ export const settings = {
lightBlockWrapper: true,
},

variations: [
draganescu marked this conversation as resolved.
Show resolved Hide resolved
{
name: 'horizontal',
isDefault: true,
title: __( 'Navigation (horizontal)' ),
description: __( 'Links shown in a row.' ),
attributes: { orientation: 'horizontal' },
},
{
name: 'vertical',
title: __( 'Navigation (vertical)' ),
description: __( 'Links shown in a column.' ),
attributes: { orientation: 'vertical' },
},
],

example: {
innerBlocks: [
{
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ function register_block_core_navigation() {
'core/navigation',
array(
'attributes' => array(
'orientation' => array(
'type' => 'string',
),
'className' => array(
'type' => 'string',
),
Expand Down
12 changes: 12 additions & 0 deletions packages/block-library/src/navigation/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ $navigation-sub-menu-width: $grid-unit-10 * 25;
}
}

&.is-vertical ul {
display: flex;
flex-direction: column;
li {
text-align: left;
}
}

&.is-vertical > .wp-block-navigation__container {
align-items: flex-start;
}

// Main menu
.wp-block-navigation-link {
position: relative;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Navigation allows a navigation menu to be created from an empty menu using a mixture of internal and external links 1`] = `
"<!-- wp:navigation -->
"<!-- wp:navigation {\\"orientation\\":\\"horizontal\\"} -->
<!-- wp:navigation-link {\\"label\\":\\"WP\\",\\"id\\":\\"https://wordpress.org\\",\\"url\\":\\"https://wordpress.org\\"} /-->

<!-- wp:navigation-link {\\"label\\":\\"Contact\\",\\"id\\":1,\\"url\\":\\"https://this/is/a/test/search/get-in-touch\\"} /-->
<!-- /wp:navigation -->"
`;

exports[`Navigation allows a navigation menu to be created using existing pages 1`] = `
"<!-- wp:navigation -->
"<!-- wp:navigation {\\"orientation\\":\\"horizontal\\"} -->
<!-- wp:navigation-link {\\"label\\":\\"Home\\",\\"type\\":\\"page\\",\\"id\\":1,\\"url\\":\\"https://this/is/a/test/page/home\\"} /-->

<!-- wp:navigation-link {\\"label\\":\\"About\\",\\"type\\":\\"page\\",\\"id\\":2,\\"url\\":\\"https://this/is/a/test/page/about\\"} /-->
Expand All @@ -19,7 +19,7 @@ exports[`Navigation allows a navigation menu to be created using existing pages
`;

exports[`Navigation allows pages to be created from the navigation block and their links added to menu 1`] = `
"<!-- wp:navigation -->
"<!-- wp:navigation {\\"orientation\\":\\"horizontal\\"} -->
<!-- wp:navigation-link {\\"label\\":\\"A really long page name that will not exist\\",\\"id\\":1,\\"url\\":\\"https://this/is/a/test/create/page/my-new-page\\"} /-->
<!-- /wp:navigation -->"
`;