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

Add navigation overlay block #55548

Closed
wants to merge 5 commits into from
Closed
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
9 changes: 9 additions & 0 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,15 @@ Add a page, link, or another item to your navigation. ([Source](https://github.c
- **Supports:** typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
- **Attributes:** description, id, isTopLevelLink, kind, label, opensInNewTab, rel, title, type, url

## Navigation Overlay

Display your navigation in an overlay. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/navigation-overlay))

- **Name:** core/navigation-overlay
- **Category:** navigation, theme, design
- **Supports:** align (full, wide), anchor, background (backgroundImage), color (background, button, gradients, heading, link, text), dimensions (minHeight), layout (allowSizingOnChildren), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~, ~~inserter~~
- **Attributes:**

## Submenu

Add a submenu to your navigation. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/navigation-submenu))
Expand Down
1 change: 1 addition & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function gutenberg_reregister_core_block_types() {
'media-text',
'missing',
'more',
'navigation-overlay',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed so that Global Styles outputs the styles

'nextpage',
'paragraph',
'preformatted',
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import * as missing from './missing';
import * as more from './more';
import * as navigation from './navigation';
import * as navigationLink from './navigation-link';
import * as navigationOverlay from './navigation-overlay';
import * as navigationSubmenu from './navigation-submenu';
import * as nextpage from './nextpage';
import * as pattern from './pattern';
Expand Down Expand Up @@ -185,6 +186,7 @@ const getAllBlocks = () => {
// theme blocks
navigation,
navigationLink,
navigationOverlay,
navigationSubmenu,
siteLogo,
siteTitle,
Expand Down
70 changes: 70 additions & 0 deletions packages/block-library/src/navigation-overlay/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "core/navigation-overlay",
"title": "Navigation Overlay",
"category": "navigation, theme, design",
"description": "Display your navigation in an overlay.",
"supports": {
"align": [ "wide", "full" ],
"anchor": true,
"html": false,
"inserter": false,
"background": {
"backgroundImage": true
},
"color": {
"gradients": true,
"heading": true,
"button": true,
"link": true,
"__experimentalDefaultControls": {
"background": true,
"text": true
}
},
"spacing": {
"margin": [ "top", "bottom" ],
"padding": true,
"blockGap": true,
"__experimentalDefaultControls": {
"padding": true,
"blockGap": true
}
},
"dimensions": {
"minHeight": true
},
"__experimentalBorder": {
"color": true,
"radius": true,
"style": true,
"width": true,
"__experimentalDefaultControls": {
"color": true,
"radius": true,
"style": true,
"width": true
}
},
"typography": {
"fontSize": true,
"lineHeight": true,
"__experimentalFontFamily": true,
"__experimentalFontWeight": true,
"__experimentalFontStyle": true,
"__experimentalTextTransform": true,
"__experimentalTextDecoration": true,
"__experimentalLetterSpacing": true,
"__experimentalDefaultControls": {
"fontSize": true
}
},
"layout": {
"allowSizingOnChildren": true
}
},
"textdomain": "default",
"attributes": {},
"style": "wp-block-navigation-overlay"
}
64 changes: 64 additions & 0 deletions packages/block-library/src/navigation-overlay/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import {
InnerBlocks,
useBlockProps,
useInnerBlocksProps,
store as blockEditorStore,
} from '@wordpress/block-editor';

const NavigationOverlayEdit = ( {
attributes,
clientId,
__unstableLayoutClassNames: layoutClassNames,
} ) => {
const { hasInnerBlocks, themeSupportsLayout } = useSelect(
( select ) => {
const { getBlock, getSettings } = select( blockEditorStore );
const block = getBlock( clientId );
return {
hasInnerBlocks: !! ( block && block.innerBlocks.length ),
themeSupportsLayout: getSettings()?.supportsLayout,
};
},
[ clientId ]
);

const { templateLock, allowedBlocks, layout = {} } = attributes;

// Layout settings.
const { type = 'default' } = layout;
const layoutSupportEnabled =
themeSupportsLayout || type === 'flex' || type === 'grid';

// Hooks.
const blockProps = useBlockProps( {
className: ! layoutSupportEnabled ? layoutClassNames : null,
} );

// Default to the regular appender being rendered.
let renderAppender;
if ( ! hasInnerBlocks ) {
// When there is no placeholder, but the block is also empty,
// use the larger button appender.
renderAppender = InnerBlocks.ButtonBlockAppender;
}

const innerBlocksProps = useInnerBlocksProps(
layoutSupportEnabled
? blockProps
: { className: 'wp-block-navigation-overlay' },
{
templateLock,
allowedBlocks,
renderAppender,
__unstableDisableLayoutClassNames: ! layoutSupportEnabled,
}
);

return <div { ...innerBlocksProps } />;
};

export default NavigationOverlayEdit;
23 changes: 23 additions & 0 deletions packages/block-library/src/navigation-overlay/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* WordPress dependencies
*/
import { fullscreen } from '@wordpress/icons';

/**
* Internal dependencies
*/
import initBlock from '../utils/init-block';
import metadata from './block.json';
import NavigationOverlayEdit from './edit';
import save from './save';

const { name } = metadata;
export { metadata, name };

export const settings = {
edit: NavigationOverlayEdit,
save,
icon: fullscreen,
};

export const init = () => initBlock( { name, metadata, settings } );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Empty file.
6 changes: 6 additions & 0 deletions packages/block-library/src/navigation-overlay/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Internal dependencies
*/
import { init } from '.';

export default init();
10 changes: 10 additions & 0 deletions packages/block-library/src/navigation-overlay/save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* WordPress dependencies
*/
import { useInnerBlocksProps, useBlockProps } from '@wordpress/block-editor';

export default function save() {
const blockProps = useBlockProps.save();
const innerBlocksProps = useInnerBlocksProps.save( blockProps );
return <div { ...innerBlocksProps } />;
}
1 change: 1 addition & 0 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {

$responsive_container_classes = array(
'wp-block-navigation__responsive-container',
'wp-block-navigation-overlay',
$is_hidden_by_default ? 'hidden-by-default' : '',
implode( ' ', $colors['overlay_css_classes'] ),
);
Expand Down
13 changes: 8 additions & 5 deletions packages/block-library/src/navigation/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ button.wp-block-navigation-item__content {
transform: translateY(0);
}
}

:where(.wp-block-navigation__responsive-container.is-menu-open) {
background-color: inherit;
}
.wp-block-navigation__responsive-container {
display: none;
position: fixed;
Expand Down Expand Up @@ -498,7 +502,6 @@ button.wp-block-navigation-item__content {
&.is-menu-open {
display: flex; // Needs to be set to override "none".
flex-direction: column;
background-color: inherit;

// Animation.
animation: overlay-menu__fade-in-animation 0.1s ease-out;
Expand Down Expand Up @@ -631,13 +634,13 @@ button.wp-block-navigation-item__content {
}

// Default menu background and font color.
.wp-block-navigation:not(.has-background)
.wp-block-navigation__responsive-container.is-menu-open {
:where(.wp-block-navigation:not(.has-background)
.wp-block-navigation__responsive-container.is-menu-open) {
background-color: #fff;
}

.wp-block-navigation:not(.has-text-color)
.wp-block-navigation__responsive-container.is-menu-open {
:where(.wp-block-navigation:not(.has-text-color)
.wp-block-navigation__responsive-container.is-menu-open) {
color: #000;
}

Expand Down
Loading