-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add basic pages block #28265
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 basic pages block #28265
Changes from all commits
70d0e6b
d6e8af6
2e4190e
66eb631
1335523
16acfda
109433a
a47670a
f99a55e
1c59e8f
b5bf865
7544616
02ce0c0
15e8a89
a2ee259
014b7c1
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 |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ import * as list from './list'; | |
| import * as missing from './missing'; | ||
| import * as more from './more'; | ||
| import * as nextpage from './nextpage'; | ||
| import * as pageList from './page-list'; | ||
| import * as preformatted from './preformatted'; | ||
| import * as pullquote from './pullquote'; | ||
| import * as reusableBlock from './block'; | ||
|
|
@@ -148,6 +149,7 @@ export const __experimentalGetCoreBlocks = () => [ | |
| missing, | ||
| more, | ||
| nextpage, | ||
| pageList, | ||
|
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. So this block is stable and independent of the navigation block, which means it's going to be included in the next WP major (5.8) regardless of the status of the Navigation block, I just want to make sure this is a conscious decision.
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. @tellthemachines was the block meant to be tweaked with regards to syntax, or is it pretty much baked as is?
Member
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 we should keep this tied to the navigation block (and its child blocks) for a bit
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. In making this an independent block, I was thinking of the Widgets editor, as we don't currently have another block that can reproduce the Pages widget functionality. Assuming we want the Widgets editor to have feature parity with the legacy widgets screen, this block will be needed. I'm happy with its current syntax, and the fact that it gets whatever styling properties from Navigation block context means that when used standalone, it works just like the Categories or the Archives block, that don't have any styling options. Related question: should Categories also work as a child of Navigation? There's definitely a use case for categories in menus. |
||
| preformatted, | ||
| pullquote, | ||
| rss, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "apiVersion": 2, | ||
| "name": "core/page-list", | ||
| "category": "widgets", | ||
| "usesContext": [ | ||
| "textColor", | ||
| "customTextColor", | ||
| "backgroundColor", | ||
| "customBackgroundColor", | ||
| "fontSize", | ||
| "customFontSize", | ||
| "showSubmenuIcon" | ||
|
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 feels like "context" is being abused in the navigation block, what happens if I use this block independently and I want to customize these things?
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.
Member
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. Looked a bit at this. It relates to the block support mechanism and parent/child relationship. Braindump of what we have now:
One thing we could explore would be to allow blocks to automatically expose some block supports via context without having to declare context support explicitely. Was that what you had in mind, Miguel?
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. I added the context in to match the Navigation Link block, so that all the links in the Navigation could be styled equally. When Page List is used as an independent block, those styling options aren't available. This seemed ok as the standalone block reproduces the functionality of the Pages widget, and similar blocks like Latest Posts also have limited styling.
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.
Actually, I'm much less concerned about explicitly including Global Styles / Block Supports keys under
Member
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. In playing with this code I've noticed the block attributes and the block context have the same shape, so we can apply the same transformations on that data to create classes and styles ― it's a matter of finding how. A small step in making both cases more similar could be #32807 (experimented only with colors to see how it feels). |
||
| ], | ||
| "supports": { | ||
| "reusable": false, | ||
| "html": 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,31 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import classnames from 'classnames'; | ||
|
|
||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
|
|
||
| import { useBlockProps } from '@wordpress/block-editor'; | ||
| import ServerSideRender from '@wordpress/server-side-render'; | ||
|
|
||
| export default function PageListEdit( { context } ) { | ||
| const { textColor, backgroundColor, showSubmenuIcon } = context || {}; | ||
|
|
||
| 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, | ||
| } ), | ||
| } ); | ||
|
|
||
| return ( | ||
| <div { ...blockProps }> | ||
| <ServerSideRender block="core/page-list" /> | ||
| </div> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| .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-block-page-list > div, | ||
| .wp-block-page-list { | ||
| background-color: inherit; | ||
| } | ||
| // Make the dropdown background white if there's no background color set. | ||
| &:not(.has-background) { | ||
| .submenu-container { | ||
| color: $gray-900; | ||
| background-color: $white; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Make links unclickable in the editor | ||
| .wp-block-pages-list__item__link { | ||
| pointer-events: none; | ||
| } | ||
|
|
||
| .wp-block-page-list .components-placeholder { | ||
| min-height: 0; | ||
| padding: 0; | ||
| background-color: inherit; | ||
|
|
||
| .components-spinner { | ||
| margin-top: 0; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { pages as icon } from '@wordpress/icons'; | ||
| import { __, _x } from '@wordpress/i18n'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import metadata from './block.json'; | ||
| import edit from './edit.js'; | ||
|
|
||
| const { name } = metadata; | ||
|
|
||
| export { metadata, name }; | ||
|
|
||
| export const settings = { | ||
| title: _x( 'Page List', 'block title' ), | ||
| description: __( 'Display a list of all pages.' ), | ||
| keywords: [ __( 'menu' ), __( 'navigation' ) ], | ||
| icon, | ||
| example: {}, | ||
talldan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| edit, | ||
| }; | ||
talldan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.