Skip to content

Commit

Permalink
Adds vertical variation to navigation menu (#21296)
Browse files Browse the repository at this point in the history
* adds vertical variation to navigation menu

* Update packages/block-library/src/navigation/editor.scss

Co-Authored-By: Daniel Richards <daniel.richards@automattic.com>

* Update packages/block-library/src/navigation/index.js

Co-Authored-By: Daniel Richards <daniel.richards@automattic.com>

* Update packages/block-library/src/navigation/index.js

Co-Authored-By: Daniel Richards <daniel.richards@automattic.com>

* copy update for variation display name

* removes undefined icon property of variations

* update snapshots to contain orientation attribute for variation

Co-authored-by: Daniel Richards <daniel.richards@automattic.com>
  • Loading branch information
draganescu and talldan authored Apr 2, 2020
1 parent 559655b commit adfc9b9
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
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 @@ -149,6 +149,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 @@ -279,7 +280,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 {
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: [
{
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 -->"
`;

0 comments on commit adfc9b9

Please sign in to comment.