-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 Editor: Implement a responsive grid mode for InnerBlocks
and a basic grid block that leverages it.
#18600
Conversation
Amazing... I started working on the exact same thing last week 'cause I needed it, it's great to see this in core ❤️ ❤️ The only thing missing from that implementation is the ability to edit the width of columns and height of rows. If that gets implemented too, then this block could be used as a super-block for the site-layout in templates |
Thanks! 😄 Yeah, that's the idea.
|
A note in passing, as I was testing this very briefly: I see horizontal scroll in a newly added block: (Aside: Might help to test with Show scroll bars: Always) |
I've been thinking a lot about this one lately...
STRML is probably the best script I've found so far that can help us achieve these goals, it is used by several large projects and is well-maintained. We could build something custom, but I really can't think of a good reason why we would do something like that instead of using a well-established library. The only thing I question in this implementation is the "responsive" part. "Responsive" doesn't necessarily mean "multiple breakpoints"... Multiple breakpoints will only make it harder for people to build something if they have to do multiple steps. It could be as simple as a single breakpoint (big screen/small screen), switching from |
That could be a sensible default, but there are too many screen sizes to
limit responsiveness to just that.
What if you just want your sidebar to collapse on smaller tablets for
example.
|
There are too many variables for mobile/tablet/desktop... For example my theme may have a native-looking mobile menu on the bottom where the home/menu/search buttons go. That would require a "hide on mobile" switch on each block... adding a switch like that however on blocks because "what if my theme has feature X" would lead to an extremely cluttered UI making things more difficult to edit. |
I like that idea. It does simplify things a lot.
We would also need an option to completely hide a grid at the breakpoint.
For cases where you want to not display sections instead of collapsing them.
What do you think?
|
Makes perfect sense 👍 |
The only thing that troubles me is the technical aspect of this: In order to make breakpoints work like this, all grids should have an ID so they can be targeted by our styles. So in case the user hasn't defined an ID manually, perhaps a unique ID should be generated? <style>
/* 600px is the user-defined breakpoint - or default */
@media screen and (max-width: 600px) {
/* user chose to hide the grid on mobile */
#foo { display: none; }
}
</style> Without an ID or some other unique selector we won't be able to target a specific grid to apply our styles |
We can generate an ID by hashing the grid’s attributes and its position. I
did something similar in this PR.
|
I just checked out the branch and yeah, you're right, it's all already implemented 👍 |
I think the grid lines should be draggable and maybe show an input on hover
for more granularity or for changing units for a specific grid line.
The toolbar should also expose a way of setting global options for all
row/column grid lines.
The placeholder should offer a set of presets to pick from.
|
If this becomes a way for users to create new templates, as noted as a possibility here: #19254, I'd love to be able to do something like this with it. I begin laying out the basic structure of the page while planning for template-parts; Header, Content, Footer. I then try adding Sidebars, etc. These features become a necessity:
The example is from: https://strml.github.io/react-grid-layout/examples/6-dynamic-add-remove.html |
That can all be done in this implementation. |
Closing in favor of #20000. |
Closing for real, since #18600 (comment) doesn't seem to have done the trick 🙂 |
Description
This PR seeks to introduce an experimental responsive grid mode for
InnerBlocks
. This mode could be used to power a myriad of grid based blocks, where each one tunes the UI to what is most appropriate for each context.It can be enabled using a new
__experimentalGridMode
boolean prop onInnerBlocks
andInnerBlocks.Content
. When enabled, it will render the inner blocks in a responsive,min-width
breakpoint based grid layout.In the editor you can toggle between breakpoints, add, remove, move, and resize blocks, etc. The layouts will be persisted as an attribute of the parent block. In the front end, the saved layouts are rendered using a combination of media queries and CSS grid.
There is a lot more potential for customization that I felt would have made this PR too expansive, but I imagine that in the future we could even support customizing things like the number of columns and the row height, per breakpoint, and even the breakpoints themselves.
It's also worth noting that the interactions are far from perfect, but I think it's usable enough to share now.
The main library used for the editor portion of this PR is a somewhat low level grid editing library used by lots of large projects, like AWS, HubSpot, Monday, etc.
https://github.com/STRML/react-grid-layout#projects-using-react-grid-layout
How has this been tested?
It hasn't been thoroughly tested yet.
Screenshots
https://youtu.be/1CacV2MYF_A
Types of Changes
New Feature:
InnerBlocks
now supports a grid mode for building grid based layouts and there is a new basic grid block that leverages it.Checklist: