-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Closed
Add navigation overlay block #55548
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d6e3464
Add navigation overlay block
scruffian 748c653
remove dynamic block
scruffian 4a20db4
Add supports
scruffian 2ddd30a
add support for theme.json
scruffian 1e609fb
reduce CSS specificity so that we can customize the overlay using the…
scruffian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } ); |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this? |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { init } from '.'; | ||
|
||
export default init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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