-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Enable page list to expand in list view #45776
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
Changes from all commits
cbb720e
f8b919b
ea7cf5d
725691c
4f22049
86d80e0
f82d6d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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, | ||
|
draganescu marked this conversation as resolved.
|
||
| "html": false, | ||
| "lock": false, | ||
| "inserter": false | ||
| }, | ||
| "editorStyle": "wp-block-page-list-editor", | ||
| "style": "wp-block-page-list" | ||
| } | ||
| 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, | ||
|
Contributor
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. It seems like there is quite a lot of overlap between this file and the navigation link - they need to share the same layout. Is there anything we can do to ensure they stay in sync?
Contributor
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. I think this has been an issue in
Contributor
Author
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. Yes. Page list item is mostly a copy of the old PageItems component used inside the page list block.
Contributor
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. I created a follow up issue for this here: #46050 |
||
| '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> | ||
| ); | ||
| } | ||
| 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 } ); | ||
|
draganescu marked this conversation as resolved.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { init } from './'; | ||
|
|
||
| export default init(); |
Uh oh!
There was an error while loading. Please reload this page.