Skip to content
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

Spacer: add custom units for height and width #36186

Merged
merged 16 commits into from Dec 23, 2021

Conversation

stacimc
Copy link
Contributor

@stacimc stacimc commented Nov 3, 2021

#22956

Description

This PR adds custom unit support to the height and width controls of the Spacer block. It pulls in much of the logic for the same from the Cover block's minHeight support.

Notes

  • I added default values for each unit, to make the experience of switching units more smooth. These might need to be tweaked, especially for horizontal spacers.
  • There was a min/max specified for px width spacers. These are still respected, but not for other units. This feels reasonable to me in the absence of the RangeControl.

How has this been tested?

Vertical spacers
Insert a Spacer block into a post.

  • Try resizing the spacer in the canvas by dragging the handle.
  • Try changing the height in the inspector controls. Click through several different units.
  • Set the unit to something other than px, and then resize the spacer in the canvas. It should automatically reset the unit to px

Horizontal spacers
To test a horizontal spacer, insert the Navigation block and add a Spacer block to it.

  • Repeat tests with the width in the horizontal spacer

Mobile
Test on mobile simulators with npm run native start:reset to start the packager in dev mode, and npm run native ios/npm run native android. See screenshots.

Screenshots

spacer.mov
mobile-spacer.mp4

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@stacimc stacimc added [Status] In Progress Tracking issues with work in progress [Block] Spacer Affects the Spacer Block labels Nov 3, 2021
@stacimc stacimc self-assigned this Nov 3, 2021
@github-actions
Copy link

github-actions bot commented Nov 3, 2021

Size Change: +583 B (0%)

Total Size: 1.13 MB

Filename Size Change
build/block-library/blocks/spacer/editor-rtl.css 332 B +25 B (+8%) 🔍
build/block-library/blocks/spacer/editor.css 332 B +25 B (+8%) 🔍
build/block-library/editor-rtl.css 10 kB +16 B (0%)
build/block-library/editor.css 10 kB +15 B (0%)
build/block-library/index.min.js 165 kB +503 B (0%)
build/components/index.min.js 215 kB -1 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 960 B
build/admin-manifest/index.min.js 1.1 kB
build/annotations/index.min.js 2.75 kB
build/api-fetch/index.min.js 2.21 kB
build/autop/index.min.js 2.12 kB
build/blob/index.min.js 459 B
build/block-directory/index.min.js 6.28 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/index.min.js 140 kB
build/block-editor/style-rtl.css 14.6 kB
build/block-editor/style.css 14.6 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 58 B
build/block-library/blocks/audio/editor.css 58 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 470 B
build/block-library/blocks/button/editor.css 470 B
build/block-library/blocks/button/style-rtl.css 560 B
build/block-library/blocks/button/style.css 560 B
build/block-library/blocks/buttons/editor-rtl.css 291 B
build/block-library/blocks/buttons/editor.css 291 B
build/block-library/blocks/buttons/style-rtl.css 275 B
build/block-library/blocks/buttons/style.css 275 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 90 B
build/block-library/blocks/code/style.css 90 B
build/block-library/blocks/code/theme-rtl.css 134 B
build/block-library/blocks/code/theme.css 134 B
build/block-library/blocks/columns/editor-rtl.css 210 B
build/block-library/blocks/columns/editor.css 208 B
build/block-library/blocks/columns/style-rtl.css 502 B
build/block-library/blocks/columns/style.css 501 B
build/block-library/blocks/comment-template/style-rtl.css 127 B
build/block-library/blocks/comment-template/style.css 127 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/cover/editor-rtl.css 546 B
build/block-library/blocks/cover/editor.css 547 B
build/block-library/blocks/cover/style-rtl.css 1.22 kB
build/block-library/blocks/cover/style.css 1.22 kB
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 B
build/block-library/blocks/embed/style-rtl.css 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 322 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 966 B
build/block-library/blocks/gallery/editor.css 970 B
build/block-library/blocks/gallery/style-rtl.css 1.63 kB
build/block-library/blocks/gallery/style.css 1.62 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 159 B
build/block-library/blocks/group/editor.css 159 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 114 B
build/block-library/blocks/heading/style.css 114 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 810 B
build/block-library/blocks/image/editor.css 809 B
build/block-library/blocks/image/style-rtl.css 507 B
build/block-library/blocks/image/style.css 511 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B
build/block-library/blocks/latest-posts/editor.css 137 B
build/block-library/blocks/latest-posts/style-rtl.css 528 B
build/block-library/blocks/latest-posts/style.css 527 B
build/block-library/blocks/list/style-rtl.css 94 B
build/block-library/blocks/list/style.css 94 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 493 B
build/block-library/blocks/media-text/style.css 490 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 649 B
build/block-library/blocks/navigation-link/editor.css 650 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/view.min.js 343 B
build/block-library/blocks/navigation/editor-rtl.css 1.91 kB
build/block-library/blocks/navigation/editor.css 1.92 kB
build/block-library/blocks/navigation/style-rtl.css 1.8 kB
build/block-library/blocks/navigation/style.css 1.8 kB
build/block-library/blocks/navigation/view.min.js 2.82 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 377 B
build/block-library/blocks/page-list/editor.css 377 B
build/block-library/blocks/page-list/style-rtl.css 172 B
build/block-library/blocks/page-list/style.css 172 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 273 B
build/block-library/blocks/paragraph/style.css 273 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/style-rtl.css 446 B
build/block-library/blocks/post-comments-form/style.css 446 B
build/block-library/blocks/post-comments/style-rtl.css 509 B
build/block-library/blocks/post-comments/style.css 509 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 721 B
build/block-library/blocks/post-featured-image/editor.css 721 B
build/block-library/blocks/post-featured-image/style-rtl.css 153 B
build/block-library/blocks/post-featured-image/style.css 153 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 391 B
build/block-library/blocks/post-template/style.css 392 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 80 B
build/block-library/blocks/post-title/style.css 80 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 389 B
build/block-library/blocks/pullquote/style.css 388 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 234 B
build/block-library/blocks/query-pagination/style.css 231 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 187 B
build/block-library/blocks/quote/style.css 187 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 397 B
build/block-library/blocks/search/style.css 398 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 99 B
build/block-library/blocks/separator/editor.css 99 B
build/block-library/blocks/separator/style-rtl.css 245 B
build/block-library/blocks/separator/style.css 245 B
build/block-library/blocks/separator/theme-rtl.css 172 B
build/block-library/blocks/separator/theme.css 172 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 744 B
build/block-library/blocks/site-logo/editor.css 744 B
build/block-library/blocks/site-logo/style-rtl.css 181 B
build/block-library/blocks/site-logo/style.css 181 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 177 B
build/block-library/blocks/social-link/editor.css 177 B
build/block-library/blocks/social-links/editor-rtl.css 670 B
build/block-library/blocks/social-links/editor.css 669 B
build/block-library/blocks/social-links/style-rtl.css 1.32 kB
build/block-library/blocks/social-links/style.css 1.32 kB
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 146 B
build/block-library/blocks/tag-cloud/style.css 146 B
build/block-library/blocks/template-part/editor-rtl.css 560 B
build/block-library/blocks/template-part/editor.css 559 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 569 B
build/block-library/blocks/video/editor.css 570 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 910 B
build/block-library/common.css 908 B
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/style-rtl.css 10.9 kB
build/block-library/style.css 10.9 kB
build/block-library/theme-rtl.css 675 B
build/block-library/theme.css 679 B
build/block-serialization-default-parser/index.min.js 1.09 kB
build/block-serialization-spec-parser/index.min.js 2.79 kB
build/blocks/index.min.js 46.3 kB
build/components/style-rtl.css 15.5 kB
build/components/style.css 15.5 kB
build/compose/index.min.js 11.2 kB
build/core-data/index.min.js 13.2 kB
build/customize-widgets/index.min.js 11.4 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 631 B
build/data/index.min.js 7.49 kB
build/date/index.min.js 31.9 kB
build/deprecated/index.min.js 485 B
build/dom-ready/index.min.js 304 B
build/dom/index.min.js 4.5 kB
build/edit-navigation/index.min.js 16 kB
build/edit-navigation/style-rtl.css 3.76 kB
build/edit-navigation/style.css 3.76 kB
build/edit-post/classic-rtl.css 492 B
build/edit-post/classic.css 494 B
build/edit-post/index.min.js 29.5 kB
build/edit-post/style-rtl.css 7.16 kB
build/edit-post/style.css 7.15 kB
build/edit-site/index.min.js 35.8 kB
build/edit-site/style-rtl.css 6.61 kB
build/edit-site/style.css 6.6 kB
build/edit-widgets/index.min.js 16.5 kB
build/edit-widgets/style-rtl.css 4.18 kB
build/edit-widgets/style.css 4.18 kB
build/editor/index.min.js 37.9 kB
build/editor/style-rtl.css 3.75 kB
build/editor/style.css 3.74 kB
build/element/index.min.js 3.29 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 6.58 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.63 kB
build/html-entities/index.min.js 424 B
build/i18n/index.min.js 3.71 kB
build/is-shallow-equal/index.min.js 501 B
build/keyboard-shortcuts/index.min.js 1.8 kB
build/keycodes/index.min.js 1.39 kB
build/list-reusable-blocks/index.min.js 1.72 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.92 kB
build/notices/index.min.js 925 B
build/nux/index.min.js 2.08 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.84 kB
build/primitives/index.min.js 924 B
build/priority-queue/index.min.js 582 B
build/react-i18n/index.min.js 671 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.65 kB
build/reusable-blocks/index.min.js 2.22 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 11 kB
build/server-side-render/index.min.js 1.57 kB
build/shortcode/index.min.js 1.49 kB
build/token-list/index.min.js 639 B
build/url/index.min.js 1.9 kB
build/viewport/index.min.js 1.05 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 7.15 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.04 kB

compressed-size-action

@stacimc stacimc marked this pull request as ready for review November 4, 2021 20:07
@stacimc stacimc changed the title [WIP] Spacer: add custom units for height and width Spacer: add custom units for height and width Nov 4, 2021
@stacimc stacimc removed the [Status] In Progress Tracking issues with work in progress label Nov 4, 2021
@glendaviesnz
Copy link
Contributor

For me the this works in the editor interface as expected, but it isn't saving the selected unit to the attributes:
spacer

@@ -24,6 +31,133 @@ const MAX_SPACER_HEIGHT = 500;
const MIN_SPACER_WIDTH = 1;
const MAX_SPACER_WIDTH = 500;

function DimensionInput( {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth exporting these smaller components and adding some unit tests? Also, I know it is common to have multiple functional components in a single file, but I wonder it is worth trying to move more to a single file -> single component approach? I don't have a strong opinion on it, but it does seem that some of the core block files can get quite long and complicated.

@stacimc stacimc force-pushed the add/custom-unit-to-spacer-dimensions branch from 0f81675 to c57a4bb Compare November 22, 2021 19:26
@stacimc
Copy link
Contributor Author

stacimc commented Nov 22, 2021

Thanks for testing, @glendaviesnz! This has been rebased and updated to respect units on the frontend :)

I wonder it is worth trying to move more to a single file -> single component approach? I don't have a strong opinion on it, but it does seem that some of the core block files can get quite long and complicated.

There's a lot that could be done here. I think it might be a good idea to make a ResizableBoxWithOrientation component and use it both here and in the Cover block 🤔 For now for a start, I've broken out the controls into a separate file. I'll look into refactoring further.

@jasmussen
Copy link
Contributor

Thanks for this PR. Additional unit support has been requested quite a few times, and I think you'll make a lot of people happy with landing this. I took it for a spin, and it worked rather well for everything but percentage units:
vertical

Do you know what's up with percentage units that's making that one tricky? My best guess: the problem is that percentages are relative to the parent, making it hit or miss whether percentages work at all. I.e. if it's inside a parent with zero height, the spacer will be zero height. In that light, can we disable just the percentage unit from spacers? Even doing so in a UI-only way (not preventing themers from still defining them in the code if they want to) would be fine.

@kjellr
Copy link
Contributor

kjellr commented Dec 6, 2021

In that light, can we disable just the percentage unit from spacers? Even doing so in a UI-only way (not preventing themers from still defining them in the code if they want to) would be fine.

This seems fine to me. 👍

@stacimc stacimc force-pushed the add/custom-unit-to-spacer-dimensions branch 2 times, most recently from 36b8192 to bec1ef2 Compare December 6, 2021 20:39
@stacimc stacimc added [Status] In Progress Tracking issues with work in progress and removed [Status] In Progress Tracking issues with work in progress labels Dec 6, 2021
@stacimc
Copy link
Contributor Author

stacimc commented Dec 7, 2021

In that light, can we disable just the percentage unit from spacers?

Thanks for catching this! I think disabling the percentage unit is a good idea, as the majority of the time they will not be in a parent container where this makes sense/is meaningful. Updated.

@jasmussen jasmussen self-requested a review December 7, 2021 08:11
Copy link
Contributor

@jasmussen jasmussen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took this for a good spin, and in my testing it works very well, with no perceptible downsides. It works vertically and horizontally and the units appear to behave as they should:
spacer

The omission of percentage makes complete sense to me, and feels like a good solution.

I'd encourage a sanity check on the code, but overall, this feels solid. Thank you for your work!

@jasmussen
Copy link
Contributor

Looks like the snapshots need to be updated.

@kjellr
Copy link
Contributor

kjellr commented Dec 7, 2021

Question: Is it possible to use dynamic CSS values like variables or min()/max() if we adopt this approach? That's possible for many other areas that accept custom units (font size, margin, padding, etc.). But because the markup here requires a heightUnit attribute, I'm not sure how that would work.

The main use case I have in mind is this space beneath the header in Twenty Twenty-Two. I'd love to use a spacer to replace that, but to keep it in sync with other areas of the theme we currently use a max(1.25rem, 5vw) value so that the space isn't too large on small screens.

This wouldn't need to be visible in the UI, but if there were a "custom" unit size or something that would allow other values that would be great.

@Mamaduka
Copy link
Member

Mamaduka commented Dec 7, 2021

Hi, @stacimc

Thanks for working on this 🌟

What's the reason for storing unit values as separate attributes?

@stacimc
Copy link
Contributor Author

stacimc commented Dec 8, 2021

What's the reason for storing unit values as separate attributes?

@Mamaduka The units were added as separate attributes to prevent needing to change the attribute type for the existing height and width attributes, which would invalidate existing blocks. It also makes it easier to do some of the manipulation when dragging to resize the spacer without needing to parse out the unit -- for example, updating to px units when the handle is dragged. It's the same approach that was taken when adding custom units to Cover's minHeight (#20888).

@kjellr brings up an interesting limitation of using separate attributes.

Edit: I may have been incorrect in assuming that changing the attribute type would require a deprecation. I'll play around with this a bit more.

@stacimc stacimc added the [Status] In Progress Tracking issues with work in progress label Dec 9, 2021
@stacimc stacimc requested a review from nerrad as a code owner December 10, 2021 02:19
@aaronrobertshaw
Copy link
Contributor

Also, I hope you don't mind but I rebased the PR branch again in the hope that picking up recent commits such as #37501 will get the failing e2e test passing.

@stacimc
Copy link
Contributor Author

stacimc commented Dec 22, 2021

Also, I hope you don't mind but I rebased the PR branch again in the hope that picking up recent commits such as #37501 will get the failing e2e test passing.

Thank you!

On Native, the step value for em and rem seems overly small at 0.01. Can this be improved? Obviously not a blocker and can be addressed separately if the tweak is desired.

The step value comes from the configuration here. It's the same for the Cover block minHeight for example, and I think it makes the increment look slow/too small on desktop as well:

px-vs-em-step.mov

Investigating, it seems like different steps were chosen for each category of units, with em/rem as "character-size based units" (#32692) If we change that step in the configuration, we could update it everywhere at once. From a UI perspective I would be on board with that change, although maybe in a separate PR since it touches more than just Spacer, and to allow others to weigh in. What do you think?

@aaronrobertshaw
Copy link
Contributor

From a UI perspective I would be on board with that change, although maybe in a separate PR since it touches more than just Spacer, and to allow others to weigh in. What do you think?

That was my thinking, to address it in a separate PR. It could be a little subjective as well.

Another perspective to consider is that most using the step functionality will be doing so to fine-tune a value rather than set it for these units. The small step value makes more sense in this case.

@stacimc
Copy link
Contributor Author

stacimc commented Dec 23, 2021

That was my thinking, to address it in a separate PR. It could be a little subjective as well.

Sounds good. I opened #37620 to allow for discussion.

Merging, but I'm not clear if this should receive a Backport label -- @kjellr or @jasmussen can you weigh in here on whether the use case warrants backporting?

@stacimc stacimc merged commit c8f6ac3 into trunk Dec 23, 2021
@stacimc stacimc deleted the add/custom-unit-to-spacer-dimensions branch December 23, 2021 18:47
@github-actions github-actions bot added this to the Gutenberg 12.3 milestone Dec 23, 2021
@kjellr
Copy link
Contributor

kjellr commented Jan 3, 2022

👋 I'm unsure if it requires back porting. We haven't used this in Twenty Twenty-Two at this point, so it's not technically required. Though we do have WordPress/twentytwentytwo#272, which could technically be solved by this. I'll take a closer look in the next day or so.

@kjellr
Copy link
Contributor

kjellr commented Jan 4, 2022

I opened WordPress/twentytwentytwo#319 to use these custom units in some of Twenty Twenty-Two's patterns and templates. This fixes a bug we had with the header template margin not being editable, and I think it's a very noticeable improvement. So let's try and backport this for release.

cc @noisysocks.

@kjellr kjellr added the Backport to WP Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Jan 4, 2022
@noisysocks
Copy link
Member

We're past RC 1 unfortunately so not able to land new functionality. If this isn't technically required, like you say, then It think let's leave it for WP 5.9.1.

@noisysocks noisysocks added Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release and removed Backport to WP Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Jan 5, 2022
@kjellr
Copy link
Contributor

kjellr commented Jan 5, 2022

@noisysocks I think this one is a bit of a special case — it's technically a new feature here in Gutenberg, but it fixes a somewhat obvious bug in Twenty Twenty-Two: the fact that you can't edit the space here via the UI:

Site Editor Template Editor
Screen Shot 2022-01-05 at 7 45 51 AM Screen Shot 2022-01-05 at 7 49 50 AM

If this were something we could fix in the theme, I'd do it, but unfortunately it's not (at least, not in a way that works well for mobile + desktop). We tried to fix it before in #37105, but decided to continue pursue the approach in this PR instead.

I understand why we'd avoid pushing it, but I think it's worth a thorough consideration at least. That space is one of the first things a user is going to see when they activate Twenty Twenty-Two, and it's rough that there's no clear way to edit it.

@Mamaduka
Copy link
Member

Mamaduka commented Jan 7, 2022

If we decide to backport this, we should also include #37774.

@noisysocks
Copy link
Member

Sorry, it's too late. There's a bit of new functionality here which puts it more towards the enhancement end of the spectrum. Also there are new strings which would not be localised in time as we're now past the RC 1 hard string freeze.

We can include it in 5.9.1. We usually do a quick minor release after releasing a version with so many substantial changes (e.g. 5.0.1 and 5.0.2 came pretty quick after 5.0).

@kjellr
Copy link
Contributor

kjellr commented Jan 10, 2022

👍 No worries, thanks.

@Mamaduka
Copy link
Member

Cherry picked for 5.9.1.

@Mamaduka Mamaduka removed the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label Feb 16, 2022
Mamaduka pushed a commit that referenced this pull request Feb 16, 2022
* Add width and height units and use the custom UnitControl

* Refactor out the ResizableSpacer and fix resizing in the canvas

* Correctly initialize width and height for horizontal spacer

* Handle min and max values for px

* Apply unit to the dimensions on the frontend

* Refactor out the controls

* Disable percentage units for Spacer

* Only output width or height styles as needed for orientation

* Correctly generate styles when width or height is set to 0

* Remove unnecessary parsing, interpolation

* Remove separate unit attributes and update type of height and width attrs

* Add block deprecation

* Update and add fixtures for deprecation

* Update snapshots

* Ensure that the unit is updated to px when resizing by dragging the handle

* Add mobile support for custom units
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Spacer Affects the Spacer Block
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants