-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
74 additions
and
9 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,64 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { | ||
InnerBlocks, | ||
useBlockProps, | ||
useInnerBlocksProps, | ||
store as blockEditorStore, | ||
} from '@wordpress/block-editor'; | ||
|
||
const NavigationOverlayEdit = () => { | ||
const props = useBlockProps(); | ||
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'; | ||
|
||
return ( | ||
<> | ||
<div { ...props }>hello</div> | ||
</> | ||
// 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 |
---|---|---|
@@ -1,15 +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 } ); |
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 } />; | ||
} |