feat(block-theme): comments panel block#263
Draft
laurelfulford wants to merge 6 commits into
Draft
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new “Comments Panel” block set to the Newspack plugin for block-theme sites, providing a slide-in comments drawer with an accompanying trigger button and editable (restricted) comments template, plus frontend behavior for opening/closing and AJAX-like pagination/submission.
Changes:
- Registers three new blocks:
newspack/comments-panel,newspack/comments-panel-trigger, andnewspack/comments-panel-content(JS + PHP render callbacks + block.json). - Adds a frontend
view.jscontroller to manage panel open/close, scrim, focus trapping, inline comment pagination, and inline comment form submission. - Introduces a new “comments” icon in both the PHP UI icon set and the JS icon package, plus a small PHPUnit test asserting the icon is registered.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/newspack-plugin/webpack.config.js | Adds a new webpack entry to build the comments panel frontend view script. |
| plugins/newspack-plugin/tests/unit-tests/newspack-ui-icons.php | Adds a unit test verifying the new comments SVG icon is registered. |
| plugins/newspack-plugin/src/blocks/index.js | Registers the new comments panel blocks in the plugin’s block registry and block-theme allowlist. |
| plugins/newspack-plugin/src/blocks/comments-panel/view.js | Implements frontend panel behavior (open/close, scrim, focus trap, inline pagination, inline form submission). |
| plugins/newspack-plugin/src/blocks/comments-panel/trigger/index.js | Registers the trigger block’s editor settings (icon, edit, dynamic save). |
| plugins/newspack-plugin/src/blocks/comments-panel/trigger/edit.js | Implements the trigger block editor UI (label, styles, preview toggle integration). |
| plugins/newspack-plugin/src/blocks/comments-panel/trigger/class-comments-panel-trigger-block.php | Server-rendered trigger button markup (dynamic block). |
| plugins/newspack-plugin/src/blocks/comments-panel/trigger/block.json | Defines trigger block metadata, attributes, and supports (color/typography/spacing/border). |
| plugins/newspack-plugin/src/blocks/comments-panel/style.scss | Adds shared styling for the panel, scrim, close button, and body scroll lock. |
| plugins/newspack-plugin/src/blocks/comments-panel/preview-refs.js | Adds shared editor-only state (toggle refs + subscribers) for preview open/close. |
| plugins/newspack-plugin/src/blocks/comments-panel/panel-preview-toggle.js | Adds a shared toolbar button component to toggle panel preview in the editor. |
| plugins/newspack-plugin/src/blocks/comments-panel/index.js | Registers the parent “Comments Panel” block (editor + styles import). |
| plugins/newspack-plugin/src/blocks/comments-panel/edit.js | Implements the parent block editor template (locked trigger + content). |
| plugins/newspack-plugin/src/blocks/comments-panel/content/index.js | Registers the content block settings (dynamic wrapper; saves InnerBlocks wrapper). |
| plugins/newspack-plugin/src/blocks/comments-panel/content/edit.js | Implements the content block editor UI (template + overlay color setting + preview rendering/notice). |
| plugins/newspack-plugin/src/blocks/comments-panel/content/class-comments-panel-content-block.php | Server-renders the panel (one per request) with dialog semantics and overlay color data attribute. |
| plugins/newspack-plugin/src/blocks/comments-panel/content/block.json | Defines content block metadata/attributes (including overlayColor) and supports. |
| plugins/newspack-plugin/src/blocks/comments-panel/class-comments-panel-block.php | Server-renders the outer wrapper and ensures common assets are loaded. |
| plugins/newspack-plugin/src/blocks/comments-panel/block.json | Defines parent block metadata and hooks up the built frontend view script. |
| plugins/newspack-plugin/includes/class-newspack-ui-icons.php | Adds a new comments SVG to the PHP icon registry. |
| plugins/newspack-plugin/includes/class-blocks.php | Loads the new comments panel PHP block classes when block-theme blocks are enabled. |
| packages/icons/src/comments.js | Adds a new React comments icon for use in editor UI. |
| packages/icons/index.js | Exports the new comments icon from the icons package entrypoint. |
Comment on lines
+28
to
+34
| export function subscribeToPanel( parentClientId, setter ) { | ||
| if ( ! subscribers.has( parentClientId ) ) { | ||
| subscribers.set( parentClientId, new Set() ); | ||
| } | ||
| subscribers.get( parentClientId ).add( setter ); | ||
| return () => subscribers.get( parentClientId )?.delete( setter ); | ||
| } |
Comment on lines
+57
to
+61
| public static function render_block( array $attributes, string $content ) { | ||
| if ( self::$rendered ) { | ||
| return ''; | ||
| } | ||
| self::$rendered = true; |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
All Submissions:
Changes proposed in this Pull Request:
This PR adds a comments panel block set consisting of:
It also includes some JS to open and close the panel, and to handle comments pagination within the panel so the comments are reloaded via AJAX rather than refreshing the whole page.
This block replicates the comments template parts that current live in the block theme; some of the testing steps are copied directly from this block theme PR.
Closes NPPD-1396
How to test the changes in this Pull Request:
Update comments settings:
Add the new block:
Test on the front-end
Make a mess
Other information: