feat(block-theme): add a responsive container block for headers/footer#204
Open
laurelfulford wants to merge 16 commits into
Open
feat(block-theme): add a responsive container block for headers/footer#204laurelfulford wants to merge 16 commits into
laurelfulford wants to merge 16 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <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 “Responsive Container” block pair (container + breakpoint child) to simplify building responsive headers/footers in the block theme, including an editor toggle to switch between Desktop and Mobile views without dirtying the post, plus front-end CSS that swaps visibility at a configurable breakpoint.
Changes:
- Introduces
newspack/responsive-containerandnewspack/responsive-container-breakpointblocks (JS registration, editor UI, and block.json metadata). - Adds PHP registration plus a front-end inline stylesheet driven by a resolved breakpoint (default, theme.json custom setting, and filter override).
- Adds PHPUnit coverage for breakpoint resolution/CSS output and Jest coverage for the editor-only view-state store.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/newspack-plugin/tests/unit-tests/class-test-responsive-container-block.php | Adds PHPUnit tests for breakpoint resolution precedence and generated visibility CSS. |
| plugins/newspack-plugin/src/blocks/responsive-container/view-toggle.js | Adds the shared BlockControls toolbar toggle (Desktop/Mobile) used by container + breakpoints. |
| plugins/newspack-plugin/src/blocks/responsive-container/view-state.test.js | Adds JS tests for the ephemeral editor-only view-state store behavior. |
| plugins/newspack-plugin/src/blocks/responsive-container/view-state.js | Implements the module-global, editor-only view-state store and hook. |
| plugins/newspack-plugin/src/blocks/responsive-container/style.scss | Adds editor-only helper styles for hiding the inactive breakpoint and keeping empties clickable. |
| plugins/newspack-plugin/src/blocks/responsive-container/index.js | Registers the Responsive Container block settings, keywords, and save markup. |
| plugins/newspack-plugin/src/blocks/responsive-container/edit.js | Implements the container edit UI with locked two-breakpoint template + toolbar toggle. |
| plugins/newspack-plugin/src/blocks/responsive-container/class-responsive-container-block.php | Registers the server-side block and enqueues global front-end breakpoint visibility CSS. |
| plugins/newspack-plugin/src/blocks/responsive-container/breakpoint/index.js | Registers the Breakpoint child block, including desktop/mobile variations and save markup. |
| plugins/newspack-plugin/src/blocks/responsive-container/breakpoint/edit.js | Implements breakpoint edit UI: hides inactive view, preserves content, and shifts selection on toggle. |
| plugins/newspack-plugin/src/blocks/responsive-container/breakpoint/class-responsive-container-breakpoint-block.php | Adds server-side registration so supports are recognized for the child block. |
| plugins/newspack-plugin/src/blocks/responsive-container/breakpoint/block.json | Defines breakpoint child block metadata, parent restriction, locking defaults, and styles. |
| plugins/newspack-plugin/src/blocks/responsive-container/block.json | Defines container block metadata and supports (anchor + sticky position). |
| plugins/newspack-plugin/src/blocks/index.js | Registers the new blocks and scopes them to block theme + Site Editor only. |
| plugins/newspack-plugin/includes/class-blocks.php | Bootstraps the new PHP block classes alongside existing block registrations. |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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:
Our publishers often require pretty complex, multi-menu headers and footers. To make this work well on all screen sizes, we've been adding two version of each template part, one that shows on desktop and one that shows on mobile. This has worked well from an execution standpoint -- and essentially mimics what we do in the classic theme -- but it is SUPER messy and confusing in the Site Editor, especially if you're just trying to edit one of these template parts and have no idea what's going on under the hood.
We're currently using WordPress 7.0's block visibility with breakpoints, but that has some shortcomings:
This PR adds a "responsive container" block to help simplify the UX of this header/footer approach. It's essentially one big toggle: you can either view the Desktop or Mobile version of the header, and easily switch between the two. There's a visible UI so it's easy to find both versions of the header, and you don't need to change the browser width to edit either.
I'll spin up a separate PR to add this block to the block theme once things look mostly finalized.
Closes NPPD-1382
How to test the changes in this Pull Request:
position: stickywon't stick if it has any parent elements withoverflowstyles).Theme -specific testing:
settings.custom.newspackResponsiveBreakpoint(e.g. 1024) to the active theme's theme.json, and reload the front-end. Try resizing the window, and confirm the header swaps at the new breakpoint.add_filter( 'newspack_responsive_container_breakpoint', fn() => 600 );; confirm the headers change at 600px, and it wins even if theme.json also has a filter set.Other information: