-
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.
Enable page list to expand in list view (#45776)
* adds page list item to enable expansion in list view * fixes the readme of the page list item block * disable locking UI for page list item * memoize the template and remove useless markup in page list * page list item fixtures * Removed copied over CSS, added better configuration to page list item json configuration. Co-authored-by: Ben Dwyer <[email protected]> * removed manual editing of core blocks docs Co-authored-by: Ben Dwyer <[email protected]>
- Loading branch information
1 parent
9a4146f
commit 9f2fe7d
Showing
11 changed files
with
250 additions
and
117 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "core/page-list-item", | ||
"title": "Page List Item", | ||
"category": "widgets", | ||
"parent": [ "core/page-list" ], | ||
"description": "Displays a page inside a list of all pages.", | ||
"keywords": [ "page", "menu", "navigation" ], | ||
"textdomain": "default", | ||
"attributes": { | ||
"id": { | ||
"type": "number" | ||
}, | ||
"label": { | ||
"type": "string" | ||
}, | ||
"title": { | ||
"type": "string" | ||
}, | ||
"link": { | ||
"type": "string" | ||
}, | ||
"hasChildren": { | ||
"type": "boolean" | ||
} | ||
}, | ||
"usesContext": [ | ||
"textColor", | ||
"customTextColor", | ||
"backgroundColor", | ||
"customBackgroundColor", | ||
"overlayTextColor", | ||
"customOverlayTextColor", | ||
"overlayBackgroundColor", | ||
"customOverlayBackgroundColor", | ||
"fontSize", | ||
"customFontSize", | ||
"showSubmenuIcon", | ||
"style", | ||
"openSubmenusOnClick" | ||
], | ||
"supports": { | ||
"reusable": false, | ||
"html": false, | ||
"lock": false, | ||
"inserter": false | ||
}, | ||
"editorStyle": "wp-block-page-list-editor", | ||
"style": "wp-block-page-list" | ||
} |
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,94 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { InnerBlocks } from '@wordpress/block-editor'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { ItemSubmenuIcon } from '../navigation-link/icons'; | ||
|
||
function useFrontPageId() { | ||
return useSelect( ( select ) => { | ||
const canReadSettings = select( coreStore ).canUser( | ||
'read', | ||
'settings' | ||
); | ||
if ( ! canReadSettings ) { | ||
return undefined; | ||
} | ||
|
||
const site = select( coreStore ).getEntityRecord( 'root', 'site' ); | ||
return site?.show_on_front === 'page' && site?.page_on_front; | ||
}, [] ); | ||
} | ||
|
||
export default function PageListItemEdit( { context, attributes } ) { | ||
const { id, label, link, hasChildren } = attributes; | ||
const isNavigationChild = 'showSubmenuIcon' in context; | ||
const frontPageId = useFrontPageId(); | ||
return ( | ||
<li | ||
key={ id } | ||
className={ classnames( 'wp-block-pages-list__item', { | ||
'has-child': hasChildren, | ||
'wp-block-navigation-item': isNavigationChild, | ||
'open-on-click': context.openSubmenusOnClick, | ||
'open-on-hover-click': | ||
! context.openSubmenusOnClick && context.showSubmenuIcon, | ||
'menu-item-home': id === frontPageId, | ||
} ) } | ||
> | ||
{ hasChildren && context.openSubmenusOnClick ? ( | ||
<> | ||
<button | ||
className="wp-block-navigation-item__content wp-block-navigation-submenu__toggle" | ||
aria-expanded="false" | ||
> | ||
{ label } | ||
</button> | ||
<span className="wp-block-page-list__submenu-icon wp-block-navigation__submenu-icon"> | ||
<ItemSubmenuIcon /> | ||
</span> | ||
</> | ||
) : ( | ||
<a | ||
className={ classnames( 'wp-block-pages-list__item__link', { | ||
'wp-block-navigation-item__content': isNavigationChild, | ||
} ) } | ||
href={ link } | ||
> | ||
{ label } | ||
</a> | ||
) } | ||
{ hasChildren && ( | ||
<> | ||
{ ! context.openSubmenusOnClick && | ||
context.showSubmenuIcon && ( | ||
<button | ||
className="wp-block-navigation-item__content wp-block-navigation-submenu__toggle wp-block-page-list__submenu-icon wp-block-navigation__submenu-icon" | ||
aria-expanded="false" | ||
> | ||
<ItemSubmenuIcon /> | ||
</button> | ||
) } | ||
<ul | ||
className={ classnames( 'submenu-container', { | ||
'wp-block-navigation__submenu-container': | ||
isNavigationChild, | ||
} ) } | ||
> | ||
<InnerBlocks /> | ||
</ul> | ||
</> | ||
) } | ||
</li> | ||
); | ||
} |
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,24 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { pages as icon } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import initBlock from '../utils/init-block'; | ||
import metadata from './block.json'; | ||
import edit from './edit.js'; | ||
|
||
const { name } = metadata; | ||
|
||
export { metadata, name }; | ||
|
||
export const settings = { | ||
__experimentalLabel: ( { label } ) => label, | ||
icon, | ||
example: {}, | ||
edit, | ||
}; | ||
|
||
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,6 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { init } from './'; | ||
|
||
export default init(); |
Oops, something went wrong.