-
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.
Inherit settings from parent Nav block
- Loading branch information
1 parent
5259eb0
commit 10e32af
Showing
6 changed files
with
161 additions
and
42 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,34 +1,43 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { PanelBody, ToggleControl } from '@wordpress/components'; | ||
import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
import { useBlockProps } from '@wordpress/block-editor'; | ||
import ServerSideRender from '@wordpress/server-side-render'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
export default function PagesEdit( { clientId } ) { | ||
const navigationBlockAttributes = useSelect( ( select ) => { | ||
const { getBlockAttributes, getBlockParentsByBlockName } = select( | ||
'core/block-editor' | ||
); | ||
const parentBlock = getBlockParentsByBlockName( | ||
clientId, | ||
'core/navigation' | ||
)[ 0 ]; | ||
return getBlockAttributes( parentBlock ); | ||
} ); | ||
const showSubmenuIcon = !! navigationBlockAttributes?.showSubmenuIcon; | ||
const { textColor, backgroundColor } = navigationBlockAttributes || {}; | ||
|
||
const blockProps = useBlockProps( { | ||
className: classnames( { | ||
'has-text-color': !! textColor, | ||
[ `has-${ textColor }-color` ]: !! textColor, | ||
'has-background': !! backgroundColor, | ||
[ `has-${ backgroundColor }-background-color` ]: !! backgroundColor, | ||
'show-submenu-icons': showSubmenuIcon, | ||
} ), | ||
} ); | ||
|
||
export default function PagesEdit( { | ||
attributes, | ||
setAttributes, | ||
hasSubmenuIndicatorSetting = true, | ||
} ) { | ||
return ( | ||
<div { ...useBlockProps() }> | ||
<InspectorControls> | ||
{ hasSubmenuIndicatorSetting && ( | ||
<PanelBody title={ __( 'Display settings' ) }> | ||
<ToggleControl | ||
checked={ attributes.showSubmenuIcon } | ||
onChange={ ( value ) => { | ||
setAttributes( { | ||
showSubmenuIcon: value, | ||
} ); | ||
} } | ||
label={ __( 'Show submenu indicator icons' ) } | ||
/> | ||
</PanelBody> | ||
) } | ||
</InspectorControls> | ||
<ServerSideRender block="core/pages" attributes={ attributes } /> | ||
<div { ...blockProps }> | ||
<ServerSideRender block="core/pages" /> | ||
</div> | ||
); | ||
} |
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,7 @@ | ||
.wp-block-navigation { | ||
// Block wrapper gets the classes in the editor, and there's an extra div wrapper for now, so background styles need to be inherited. | ||
.wp-blokc-pages > div, | ||
.wp-block-page-list { | ||
background-color: inherit; | ||
} | ||
} |
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