-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Block Library: Add the Comments Pagination block #36872
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2601c88
Block Library: Add new Comments Pagination block
DAreRodz 3853d34
Block Library: Fix Comments Pagination's index.php
DAreRodz 9f3fa77
Block Library: Add $schema to Comments Pagination
DAreRodz 239904d
Block Library: Add Comments Pagination fixture
DAreRodz 9febfa7
Hide the component until we have the templates ready
f65de17
Block Library: Fix Comments Pagination block's title
DAreRodz d5778b2
Block Library: Remove unnecessary CSS classes
DAreRodz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "core/comments-pagination", | ||
"title": "Comments Pagination", | ||
"category": "design", | ||
"parent": [ "core/comments-query-loop" ], | ||
"description": "Displays a paginated navigation to next/previous set of comments, when applicable.", | ||
"textdomain": "default", | ||
"attributes": { | ||
"paginationArrow": { | ||
"type": "string", | ||
"default": "none" | ||
} | ||
}, | ||
"providesContext": { | ||
"paginationArrow": "paginationArrow" | ||
}, | ||
"supports": { | ||
"align": true, | ||
"reusable": false, | ||
"html": false, | ||
"inserter": false, | ||
"color": { | ||
"gradients": true, | ||
"link": true | ||
}, | ||
"__experimentalLayout": { | ||
"allowSwitching": false, | ||
"allowInheriting": false, | ||
"default": { | ||
"type": "flex" | ||
} | ||
} | ||
}, | ||
"editorStyle": "wp-block-comments-pagination-editor", | ||
"style": "wp-block-comments-pagination" | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/block-library/src/comments-pagination/comments-pagination-arrow-controls.js
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,44 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, _x } from '@wordpress/i18n'; | ||
import { | ||
__experimentalToggleGroupControl as ToggleGroupControl, | ||
__experimentalToggleGroupControlOption as ToggleGroupControlOption, | ||
} from '@wordpress/components'; | ||
|
||
export function CommentsPaginationArrowControls( { value, onChange } ) { | ||
return ( | ||
<ToggleGroupControl | ||
label={ __( 'Arrow' ) } | ||
value={ value } | ||
onChange={ onChange } | ||
help={ __( | ||
'A decorative arrow appended to the next and previous comments link.' | ||
) } | ||
isBlock | ||
> | ||
<ToggleGroupControlOption | ||
value="none" | ||
label={ _x( | ||
'None', | ||
'Arrow option for Comments Pagination Next/Previous blocks' | ||
) } | ||
/> | ||
<ToggleGroupControlOption | ||
value="arrow" | ||
label={ _x( | ||
'Arrow', | ||
'Arrow option for Comments Pagination Next/Previous blocks' | ||
) } | ||
/> | ||
<ToggleGroupControlOption | ||
value="chevron" | ||
label={ _x( | ||
'Chevron', | ||
'Arrow option for Comments Pagination Next/Previous blocks' | ||
) } | ||
/> | ||
</ToggleGroupControl> | ||
); | ||
} |
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,70 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
InspectorControls, | ||
useBlockProps, | ||
useInnerBlocksProps, | ||
store as blockEditorStore, | ||
} from '@wordpress/block-editor'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { getBlockSupport } from '@wordpress/blocks'; | ||
import { PanelBody } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { CommentsPaginationArrowControls } from './comments-pagination-arrow-controls'; | ||
|
||
const getDefaultBlockLayout = ( blockTypeOrName ) => { | ||
const layoutBlockSupportConfig = getBlockSupport( | ||
blockTypeOrName, | ||
'__experimentalLayout' | ||
); | ||
return layoutBlockSupportConfig?.default; | ||
}; | ||
|
||
export default function QueryPaginationEdit( { | ||
attributes: { paginationArrow, layout }, | ||
setAttributes, | ||
clientId, | ||
name, | ||
} ) { | ||
const usedLayout = layout || getDefaultBlockLayout( name ); | ||
const hasNextPreviousBlocks = useSelect( ( select ) => { | ||
const { getBlocks } = select( blockEditorStore ); | ||
const innerBlocks = getBlocks( clientId ); | ||
/** | ||
* Show the `paginationArrow` control only if a | ||
* `QueryPaginationNext/Previous` block exists. | ||
*/ | ||
return innerBlocks?.find( ( innerBlock ) => { | ||
return [ | ||
'core/query-pagination-next', | ||
'core/query-pagination-previous', | ||
].includes( innerBlock.name ); | ||
} ); | ||
}, [] ); | ||
const blockProps = useBlockProps(); | ||
const innerBlocksProps = useInnerBlocksProps( blockProps, { | ||
__experimentalLayout: usedLayout, | ||
} ); | ||
return ( | ||
<> | ||
{ hasNextPreviousBlocks && ( | ||
<InspectorControls> | ||
<PanelBody title={ __( 'Settings' ) }> | ||
<CommentsPaginationArrowControls | ||
value={ paginationArrow } | ||
onChange={ ( value ) => { | ||
setAttributes( { paginationArrow: value } ); | ||
} } | ||
/> | ||
</PanelBody> | ||
</InspectorControls> | ||
) } | ||
<div { ...innerBlocksProps } /> | ||
</> | ||
); | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/block-library/src/comments-pagination/editor.scss
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,34 @@ | ||
$pagination-margin: 0.5em; | ||
|
||
// Center flex items. This has an equivalent in style.scss. | ||
.wp-block[data-align="center"] > .wp-block-comments-pagination { | ||
justify-content: center; | ||
} | ||
|
||
.editor-styles-wrapper { | ||
.wp-block-comments-pagination { | ||
max-width: 100%; | ||
&.block-editor-block-list__layout { | ||
margin: 0; | ||
} | ||
} | ||
} | ||
|
||
.wp-block-comments-pagination { | ||
> .wp-block-comments-pagination-next, | ||
> .wp-block-comments-pagination-previous, | ||
> .wp-block-comments-pagination-numbers { | ||
// Override editor auto block margins. | ||
margin-left: 0; | ||
margin-top: $pagination-margin; | ||
|
||
/*rtl:ignore*/ | ||
margin-right: $pagination-margin; | ||
margin-bottom: $pagination-margin; | ||
|
||
&:last-child { | ||
/*rtl:ignore*/ | ||
margin-right: 0; | ||
} | ||
} | ||
} |
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,20 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { queryPagination as icon } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
import edit from './edit'; | ||
import save from './save'; | ||
|
||
const { name } = metadata; | ||
export { metadata, name }; | ||
|
||
export const settings = { | ||
icon, | ||
edit, | ||
save, | ||
}; |
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,39 @@ | ||
<?php | ||
/** | ||
* Server-side rendering of the `core/comments-pagination` block. | ||
* | ||
* @package WordPress | ||
*/ | ||
|
||
/** | ||
* Renders the `core/comments-pagination` block on the server. | ||
* | ||
* @param array $attributes Block attributes. | ||
* @param string $content Block default content. | ||
* | ||
* @return string Returns the wrapper for the Comments pagination. | ||
*/ | ||
function render_block_core_comments_pagination( $attributes, $content ) { | ||
if ( empty( trim( $content ) ) ) { | ||
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. That’s a bit surprising but I checked the history of the Query Pagination block and it looks like they had an issue with rendering of an empty |
||
return ''; | ||
} | ||
|
||
return sprintf( | ||
'<div %1$s>%2$s</div>', | ||
get_block_wrapper_attributes(), | ||
$content | ||
); | ||
} | ||
|
||
/** | ||
* Registers the `core/comments-pagination` block on the server. | ||
*/ | ||
function register_block_core_comments_pagination() { | ||
register_block_type_from_metadata( | ||
__DIR__ . '/comments-pagination', | ||
array( | ||
'render_callback' => 'render_block_core_comments_pagination', | ||
) | ||
); | ||
} | ||
add_action( 'init', 'register_block_core_comments_pagination' ); |
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,8 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { InnerBlocks } from '@wordpress/block-editor'; | ||
|
||
export default function save() { | ||
return <InnerBlocks.Content />; | ||
} |
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,38 @@ | ||
$pagination-margin: 0.5em; | ||
.wp-block-comments-pagination { | ||
// Increased specificity to override blocks default margin. | ||
> .wp-block-comments-pagination-next, | ||
> .wp-block-comments-pagination-previous, | ||
> .wp-block-comments-pagination-numbers { | ||
/*rtl:ignore*/ | ||
margin-right: $pagination-margin; | ||
margin-bottom: $pagination-margin; | ||
|
||
&:last-child { | ||
/*rtl:ignore*/ | ||
margin-right: 0; | ||
} | ||
} | ||
.wp-block-comments-pagination-previous-arrow { | ||
margin-right: 1ch; | ||
display: inline-block; // Needed so that the transform works. | ||
// chevron(`»`) symbol doesn't need the mirroring by us. | ||
&:not(.is-arrow-chevron) { | ||
// Flip for RTL. | ||
transform: scaleX(1) #{"/*rtl:scaleX(-1);*/"}; // This points the arrow right for LTR and left for RTL. | ||
} | ||
} | ||
.wp-block-comments-pagination-next-arrow { | ||
margin-left: 1ch; | ||
display: inline-block; // Needed so that the transform works. | ||
// chevron(`»`) symbol doesn't need the mirroring by us. | ||
&:not(.is-arrow-chevron) { | ||
// Flip for RTL. | ||
transform: scaleX(1) #{"/*rtl:scaleX(-1);*/"}; // This points the arrow right for LTR and left for RTL. | ||
} | ||
} | ||
|
||
&.aligncenter { | ||
justify-content: center; | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
test/integration/fixtures/blocks/core__comments-pagination.html
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 @@ | ||
<!-- wp:comments-pagination {"paginationArrow":"chevron","textColor":"black","style":{"color":{"gradient":"linear-gradient(135deg,rgb(74,234,220) 0%,rgb(151,120,209) 20%,rgb(207,42,186) 40%,rgb(238,44,130) 60%,rgb(251,105,98) 80%,rgb(254,248,76) 100%)"},"elements":{"link":{"color":{"text":"#ffffff"}}}},"layout":{"type":"flex","orientation":"horizontal","justifyContent":"center"}} --> |
30 changes: 30 additions & 0 deletions
30
test/integration/fixtures/blocks/core__comments-pagination.json
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,30 @@ | ||
[ | ||
{ | ||
"clientId": "_clientId_0", | ||
"name": "core/comments-pagination", | ||
"isValid": true, | ||
"attributes": { | ||
"paginationArrow": "chevron", | ||
"textColor": "black", | ||
"style": { | ||
"color": { | ||
"gradient": "linear-gradient(135deg,rgb(74,234,220) 0%,rgb(151,120,209) 20%,rgb(207,42,186) 40%,rgb(238,44,130) 60%,rgb(251,105,98) 80%,rgb(254,248,76) 100%)" | ||
}, | ||
"elements": { | ||
"link": { | ||
"color": { | ||
"text": "#ffffff" | ||
} | ||
} | ||
} | ||
}, | ||
"layout": { | ||
"type": "flex", | ||
"orientation": "horizontal", | ||
"justifyContent": "center" | ||
} | ||
}, | ||
"innerBlocks": [], | ||
"originalContent": "" | ||
} | ||
] |
29 changes: 29 additions & 0 deletions
29
test/integration/fixtures/blocks/core__comments-pagination.parsed.json
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,29 @@ | ||
[ | ||
{ | ||
"blockName": "core/comments-pagination", | ||
"attrs": { | ||
"paginationArrow": "chevron", | ||
"textColor": "black", | ||
"style": { | ||
"color": { | ||
"gradient": "linear-gradient(135deg,rgb(74,234,220) 0%,rgb(151,120,209) 20%,rgb(207,42,186) 40%,rgb(238,44,130) 60%,rgb(251,105,98) 80%,rgb(254,248,76) 100%)" | ||
}, | ||
"elements": { | ||
"link": { | ||
"color": { | ||
"text": "#ffffff" | ||
} | ||
} | ||
} | ||
}, | ||
"layout": { | ||
"type": "flex", | ||
"orientation": "horizontal", | ||
"justifyContent": "center" | ||
} | ||
}, | ||
"innerBlocks": [], | ||
"innerHTML": "", | ||
"innerContent": [] | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
test/integration/fixtures/blocks/core__comments-pagination.serialized.html
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 @@ | ||
<!-- wp:comments-pagination {"paginationArrow":"chevron","textColor":"black","style":{"color":{"gradient":"linear-gradient(135deg,rgb(74,234,220) 0%,rgb(151,120,209) 20%,rgb(207,42,186) 40%,rgb(238,44,130) 60%,rgb(251,105,98) 80%,rgb(254,248,76) 100%)"},"elements":{"link":{"color":{"text":"#ffffff"}}}},"layout":{"type":"flex","orientation":"horizontal","justifyContent":"center"}} /--> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Names of those blocks need to be updated later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! I guess the best way to address it is to do that in the PRs that implement the inner blocks.