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

Spacing: Optimize & condense unlinked spacing controls #50660

Merged
merged 25 commits into from
May 29, 2023

Conversation

aaronrobertshaw
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw commented May 16, 2023

Fixes: #49264

What?

Refactors the SpacingSizesControl to reduce the footprint of the control when its sides are unlinked.

🤖 Generated by Copilot at b33165d

This pull request improves the SpacingSizesControl component and its subcomponents in the block-editor package by adding new icons, a new dropdown menu, a new hook, and a new UI. It also removes some unused or unnecessary code and props, and updates the import paths, the styles, and the tests. The overall purpose is to simplify the UI and make it easier to switch between different views of the spacing sizes.

Why?

When the spacing controls are unlinked they take up a huge amount of real estate. This is compounded multiple times if the block has support for padding, margin, block gap and any other ad hoc controls that use the same component.

How?

  • Replaces the current linked button with a dropdown menu
  • The dropdown menu will now present options to select only a subset of sides for display
  • The control now offers an "axial" view (horizontal/vertical) for when the supported sides could be adjusted in such a manner
  • Adds new custom icons for the various sides (this could just be temporary, see next steps)
  • Adds some new util methods for determining the correct control view to display on initial render or build out the menu
  • Includes unit tests for the new utils

🤖 Generated by Copilot at b33165d

  • Remove splitOnAxis prop from SpacingSizesControl component and simplify UI (link,link,link)
  • Extract logic of getting spacing sizes from useSetting hook and default values into a new custom hook useSpacingSizes (link,link)
  • Create a new component SingleInputControl that renders a single input control for a single side (link)
  • Create a new component SidesDropdown that renders a dropdown menu that allows users to switch between different views of the SpacingSizesControl component (link)
  • Add new icons that represent the different sides and views of the SpacingSizesControl component and its subcomponents (link,link,link,link,link,link,link)
  • Update SpacingInputControl component to use the new icons and a custom toggle button to switch between preset and custom values (link,link,link,link,link,link,link,link,link)
  • Update AxialInputControls and SeparatedInputControls components to use the new hasAxisSupport function and the icon prop (link,link,link,link,link)
  • Add new utility functions hasAxisSupport, getSupportedMenuItems, hasBalancedSidesSupport, and getInitialView to handle the new logic of the SpacingSizesControl component and its subcomponents (link)
  • Add tests for the new utility functions (link)
  • Update styles of the SpacingSizesControl component and its subcomponents according to the new UI (link,link,link,link)
  • Modify import paths to use relative paths instead of absolute paths and follow coding standards (link,link,link,link,link,link,link)
  • Remove duplicate objects and unused variables from the utils.js file (link,link)
  • Delete unused files all-input-control.js and linked-button.js (link,link)

Possible Next Steps

  • See if the components a11y can be improved
  • Create a dynamic icon component along the lines of the BoxControl's if we don't want to add the new icons to the library
  • Decide upon if the "linked" or all sides view should be removed. (It still provides a handy convenience and helps reduce footprint for odd side configurations e.g. top & left etc) Linked view has been removed.
  • Reinstate hints if its decided they should be retained Hints will be omitted for now.
  • Sort out a few more edge cases in terms of which view options should be presented at what times.

Testing Instructions

  1. Run spacing sizes control's util unit tests
    npm run test:unit packages/block-editor/src/components/spacing-sizes-control/test/utils.js
  2. Add a few blocks to a post that use varied spacing supports i.e. some that support all sides, some sides, axial sides etc. Example blocks could be Group, Social Icons, Gallery
  3. Select each block and make sure that only supported sides appear in the dropdown, can be manipulated, and are applied correctly.
  4. Check that each of the spacing control’s inputs can be toggled to enter custom values
  5. In your theme.json turn off custom spacing sizes, reload the editor and confirm that you can no longer toggle on the custom inputs
  6. Back to the theme.json reenable the custom spacing sizes, this time configure there to be > 8 spacing preset sizes
  7. Reload the editor and confirm that the spacing sizes control now renders the custom select input instead of the normal segmented range control
  8. Test all possible side configurations manually. It’s probably easier to tweak the Group block.json file and check it in the editor.
  9. Finally, double check the use of the SpacingSizesControl outside of a ToolsPanel. Add a Spacer block to a post and select it. Make sure that it renders correctly, including the alignment of the custom input.

Testing Instructions for Keyboard

  1. Add a few blocks to a post that use varied spacing supports i.e. some that support all sides, some sides, axial sides etc. Example blocks could be Group, Social Icons, Gallery
  2. Select a block and tab through to the Block Inspector tabs
  3. Use the arrow keys to navigate to the Styles tab, then tab down to the Padding control in the Dimensions panel
  4. Confirm you can option the "Padding options" dropdown menu and select a side
  5. Check that the individual controls continue to behave as they do on trunk using keyboard navigation
  6. Shift tab back to the "Padding options" dropdown and switch sides making sure the control updates as expected

Screenshots or screencast

Screen.Recording.2023-05-19.at.1.59.38.pm.mp4

@aaronrobertshaw aaronrobertshaw added [Type] Enhancement A suggestion for improvement. [Feature] UI Components Impacts or related to the UI component system [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi labels May 16, 2023
@aaronrobertshaw aaronrobertshaw self-assigned this May 16, 2023
@github-actions
Copy link

github-actions bot commented May 16, 2023

Size Change: +8.26 kB (+1%)

Total Size: 1.39 MB

Filename Size Change
build/a11y/index.min.js 955 B -27 B (-3%)
build/annotations/index.min.js 2.69 kB -72 B (-3%)
build/api-fetch/index.min.js 2.28 kB -49 B (-2%)
build/autop/index.min.js 2.1 kB -38 B (-2%)
build/blob/index.min.js 451 B -21 B (-4%)
build/block-directory/index.min.js 7.05 kB -128 B (-2%)
build/block-editor/content-rtl.css 4.23 kB +111 B (+3%)
build/block-editor/content.css 4.23 kB +111 B (+3%)
build/block-editor/index.min.js 194 kB -3.75 kB (-2%)
build/block-editor/style-rtl.css 14.9 kB -155 B (-1%)
build/block-editor/style.css 14.9 kB -156 B (-1%)
build/block-library/blocks/file/editor-rtl.css 316 B +16 B (+5%) 🔍
build/block-library/blocks/file/editor.css 316 B +16 B (+5%) 🔍
build/block-library/blocks/file/interactivity.min.js 395 B -6 B (-1%)
build/block-library/blocks/freeform/editor-rtl.css 2.58 kB +142 B (+6%) 🔍
build/block-library/blocks/freeform/editor.css 2.58 kB +141 B (+6%) 🔍
build/block-library/blocks/image/style-rtl.css 1.07 kB +422 B (+65%) 🆘
build/block-library/blocks/image/style.css 1.07 kB +419 B (+64%) 🆘
build/block-library/blocks/navigation/interactivity.min.js 896 B +24 B (+3%)
build/block-library/blocks/navigation/view-modal.min.js 2.78 kB -27 B (-1%)
build/block-library/blocks/navigation/view.min.js 438 B -5 B (-1%)
build/block-library/blocks/post-comments-form/style-rtl.css 508 B +7 B (+1%)
build/block-library/blocks/post-comments-form/style.css 508 B +7 B (+1%)
build/block-library/editor-rtl.css 12.1 kB +127 B (+1%)
build/block-library/editor.css 12.1 kB +121 B (+1%)
build/block-library/index.min.js 200 kB -4.26 kB (-2%)
build/block-library/interactivity/runtime.min.js 2.69 kB +456 B (+20%) 🚨
build/block-library/interactivity/vendors.min.js 8.2 kB +52 B (+1%)
build/block-library/style-rtl.css 13.1 kB +274 B (+2%)
build/block-library/style.css 13.1 kB +283 B (+2%)
build/block-serialization-spec-parser/index.min.js 2.87 kB +39 B (+1%)
build/blocks/index.min.js 50.3 kB -677 B (-1%)
build/commands/index.min.js 14.9 kB -56 B (0%)
build/components/index.min.js 230 kB +21.2 kB (+10%) ⚠️
build/components/style-rtl.css 11.7 kB -11 B (0%)
build/components/style.css 11.7 kB -12 B (0%)
build/compose/index.min.js 12.1 kB -351 B (-3%)
build/core-commands/index.min.js 1.74 kB -66 B (-4%)
build/core-data/index.min.js 15.4 kB -1.09 kB (-7%)
build/customize-widgets/index.min.js 12 kB -168 B (-1%)
build/data-controls/index.min.js 640 B -68 B (-10%) 👏
build/data/index.min.js 8.24 kB -446 B (-5%)
build/date/index.min.js 40.4 kB -32 B (0%)
build/deprecated/index.min.js 451 B -56 B (-11%) 👏
build/dom/index.min.js 4.63 kB -99 B (-2%)
build/edit-post/index.min.js 34.6 kB -641 B (-2%)
build/edit-site/index.min.js 64.6 kB -165 B (0%)
build/edit-site/style-rtl.css 10.9 kB +294 B (+3%)
build/edit-site/style.css 10.9 kB +289 B (+3%)
build/edit-widgets/index.min.js 17 kB -249 B (-1%)
build/editor/index.min.js 44.6 kB -1.12 kB (-2%)
build/element/index.min.js 4.8 kB -89 B (-2%)
build/format-library/index.min.js 7.57 kB -202 B (-3%)
build/hooks/index.min.js 1.55 kB -90 B (-6%)
build/i18n/index.min.js 3.58 kB -149 B (-4%)
build/keyboard-shortcuts/index.min.js 1.71 kB -77 B (-4%)
build/keycodes/index.min.js 1.84 kB -68 B (-4%)
build/list-reusable-blocks/index.min.js 2.13 kB -12 B (-1%)
build/media-utils/index.min.js 2.9 kB -69 B (-2%)
build/notices/index.min.js 875 B -88 B (-9%)
build/plugins/index.min.js 1.84 kB -10 B (-1%)
build/preferences-persistence/index.min.js 1.84 kB -381 B (-17%) 👏
build/preferences/index.min.js 1.24 kB -90 B (-7%)
build/primitives/index.min.js 941 B -3 B (0%)
build/redux-routine/index.min.js 2.7 kB -39 B (-1%)
build/reusable-blocks/index.min.js 2.21 kB -44 B (-2%)
build/rich-text/index.min.js 10.7 kB -347 B (-3%)
build/router/index.min.js 1.77 kB -6 B (0%)
build/server-side-render/index.min.js 2.02 kB -50 B (-2%)
build/shortcode/index.min.js 1.39 kB -28 B (-2%)
build/style-engine/index.min.js 1.42 kB -105 B (-7%)
build/token-list/index.min.js 582 B -62 B (-10%) 👏
build/url/index.min.js 3.57 kB -80 B (-2%)
build/vendors/react-dom.min.js 41.8 kB -13 B (0%)
build/viewport/index.min.js 1.04 kB -42 B (-4%)
build/widgets/index.min.js 7.16 kB -123 B (-2%)
build/wordcount/index.min.js 1.02 kB -36 B (-3%)
ℹ️ View Unchanged
Filename Size
build/block-directory/style-rtl.css 1.02 kB
build/block-directory/style.css 1.02 kB
build/block-editor/default-editor-styles-rtl.css 381 B
build/block-editor/default-editor-styles.css 381 B
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 90 B
build/block-library/blocks/archives/style.css 90 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 122 B
build/block-library/blocks/audio/style.css 122 B
build/block-library/blocks/audio/theme-rtl.css 126 B
build/block-library/blocks/audio/theme.css 126 B
build/block-library/blocks/avatar/editor-rtl.css 116 B
build/block-library/blocks/avatar/editor.css 116 B
build/block-library/blocks/avatar/style-rtl.css 91 B
build/block-library/blocks/avatar/style.css 91 B
build/block-library/blocks/block/editor-rtl.css 305 B
build/block-library/blocks/block/editor.css 305 B
build/block-library/blocks/button/editor-rtl.css 584 B
build/block-library/blocks/button/editor.css 582 B
build/block-library/blocks/button/style-rtl.css 624 B
build/block-library/blocks/button/style.css 623 B
build/block-library/blocks/buttons/editor-rtl.css 337 B
build/block-library/blocks/buttons/editor.css 337 B
build/block-library/blocks/buttons/style-rtl.css 332 B
build/block-library/blocks/buttons/style.css 332 B
build/block-library/blocks/calendar/style-rtl.css 239 B
build/block-library/blocks/calendar/style.css 239 B
build/block-library/blocks/categories/editor-rtl.css 113 B
build/block-library/blocks/categories/editor.css 112 B
build/block-library/blocks/categories/style-rtl.css 124 B
build/block-library/blocks/categories/style.css 124 B
build/block-library/blocks/code/editor-rtl.css 53 B
build/block-library/blocks/code/editor.css 53 B
build/block-library/blocks/code/style-rtl.css 121 B
build/block-library/blocks/code/style.css 121 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 409 B
build/block-library/blocks/columns/style.css 409 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-content/style-rtl.css 92 B
build/block-library/blocks/comment-content/style.css 92 B
build/block-library/blocks/comment-template/style-rtl.css 199 B
build/block-library/blocks/comment-template/style.css 198 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/comments-title/editor-rtl.css 75 B
build/block-library/blocks/comments-title/editor.css 75 B
build/block-library/blocks/comments/editor-rtl.css 840 B
build/block-library/blocks/comments/editor.css 839 B
build/block-library/blocks/comments/style-rtl.css 637 B
build/block-library/blocks/comments/style.css 636 B
build/block-library/blocks/cover/editor-rtl.css 647 B
build/block-library/blocks/cover/editor.css 650 B
build/block-library/blocks/cover/style-rtl.css 1.61 kB
build/block-library/blocks/cover/style.css 1.6 kB
build/block-library/blocks/details/editor-rtl.css 65 B
build/block-library/blocks/details/editor.css 65 B
build/block-library/blocks/details/style-rtl.css 159 B
build/block-library/blocks/details/style.css 159 B
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 410 B
build/block-library/blocks/embed/style.css 410 B
build/block-library/blocks/embed/theme-rtl.css 126 B
build/block-library/blocks/embed/theme.css 126 B
build/block-library/blocks/file/style-rtl.css 269 B
build/block-library/blocks/file/style.css 270 B
build/block-library/blocks/file/view.min.js 375 B
build/block-library/blocks/gallery/editor-rtl.css 947 B
build/block-library/blocks/gallery/editor.css 952 B
build/block-library/blocks/gallery/style-rtl.css 1.53 kB
build/block-library/blocks/gallery/style.css 1.53 kB
build/block-library/blocks/gallery/theme-rtl.css 108 B
build/block-library/blocks/gallery/theme.css 108 B
build/block-library/blocks/group/editor-rtl.css 654 B
build/block-library/blocks/group/editor.css 654 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 76 B
build/block-library/blocks/heading/style.css 76 B
build/block-library/blocks/html/editor-rtl.css 336 B
build/block-library/blocks/html/editor.css 337 B
build/block-library/blocks/image/editor-rtl.css 834 B
build/block-library/blocks/image/editor.css 833 B
build/block-library/blocks/image/interactivity.min.js 783 B
build/block-library/blocks/image/theme-rtl.css 126 B
build/block-library/blocks/image/theme.css 126 B
build/block-library/blocks/latest-comments/style-rtl.css 357 B
build/block-library/blocks/latest-comments/style.css 357 B
build/block-library/blocks/latest-posts/editor-rtl.css 213 B
build/block-library/blocks/latest-posts/editor.css 212 B
build/block-library/blocks/latest-posts/style-rtl.css 478 B
build/block-library/blocks/latest-posts/style.css 478 B
build/block-library/blocks/list/style-rtl.css 88 B
build/block-library/blocks/list/style.css 88 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 507 B
build/block-library/blocks/media-text/style.css 505 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 712 B
build/block-library/blocks/navigation-link/editor.css 711 B
build/block-library/blocks/navigation-link/style-rtl.css 115 B
build/block-library/blocks/navigation-link/style.css 115 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 296 B
build/block-library/blocks/navigation-submenu/editor.css 295 B
build/block-library/blocks/navigation/editor-rtl.css 2.33 kB
build/block-library/blocks/navigation/editor.css 2.33 kB
build/block-library/blocks/navigation/style-rtl.css 2.21 kB
build/block-library/blocks/navigation/style.css 2.2 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 401 B
build/block-library/blocks/page-list/editor.css 401 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 174 B
build/block-library/blocks/paragraph/editor.css 174 B
build/block-library/blocks/paragraph/style-rtl.css 279 B
build/block-library/blocks/paragraph/style.css 281 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/editor-rtl.css 96 B
build/block-library/blocks/post-comments-form/editor.css 96 B
build/block-library/blocks/post-date/style-rtl.css 61 B
build/block-library/blocks/post-date/style.css 61 B
build/block-library/blocks/post-excerpt/editor-rtl.css 71 B
build/block-library/blocks/post-excerpt/editor.css 71 B
build/block-library/blocks/post-excerpt/style-rtl.css 141 B
build/block-library/blocks/post-excerpt/style.css 141 B
build/block-library/blocks/post-featured-image/editor-rtl.css 588 B
build/block-library/blocks/post-featured-image/editor.css 586 B
build/block-library/blocks/post-featured-image/style-rtl.css 319 B
build/block-library/blocks/post-featured-image/style.css 319 B
build/block-library/blocks/post-navigation-link/style-rtl.css 153 B
build/block-library/blocks/post-navigation-link/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 281 B
build/block-library/blocks/post-template/style.css 281 B
build/block-library/blocks/post-terms/style-rtl.css 96 B
build/block-library/blocks/post-terms/style.css 96 B
build/block-library/blocks/post-time-to-read/style-rtl.css 69 B
build/block-library/blocks/post-time-to-read/style.css 69 B
build/block-library/blocks/post-title/style-rtl.css 100 B
build/block-library/blocks/post-title/style.css 100 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 135 B
build/block-library/blocks/pullquote/editor.css 135 B
build/block-library/blocks/pullquote/style-rtl.css 335 B
build/block-library/blocks/pullquote/style.css 335 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 288 B
build/block-library/blocks/query-pagination/style.css 284 B
build/block-library/blocks/query-title/style-rtl.css 63 B
build/block-library/blocks/query-title/style.css 63 B
build/block-library/blocks/query/editor-rtl.css 450 B
build/block-library/blocks/query/editor.css 449 B
build/block-library/blocks/quote/style-rtl.css 222 B
build/block-library/blocks/quote/style.css 222 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 B
build/block-library/blocks/rss/editor-rtl.css 149 B
build/block-library/blocks/rss/editor.css 149 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 178 B
build/block-library/blocks/search/editor.css 178 B
build/block-library/blocks/search/style-rtl.css 434 B
build/block-library/blocks/search/style.css 432 B
build/block-library/blocks/search/theme-rtl.css 114 B
build/block-library/blocks/search/theme.css 114 B
build/block-library/blocks/separator/editor-rtl.css 146 B
build/block-library/blocks/separator/editor.css 146 B
build/block-library/blocks/separator/style-rtl.css 234 B
build/block-library/blocks/separator/style.css 234 B
build/block-library/blocks/separator/theme-rtl.css 194 B
build/block-library/blocks/separator/theme.css 194 B
build/block-library/blocks/shortcode/editor-rtl.css 323 B
build/block-library/blocks/shortcode/editor.css 323 B
build/block-library/blocks/site-logo/editor-rtl.css 754 B
build/block-library/blocks/site-logo/editor.css 754 B
build/block-library/blocks/site-logo/style-rtl.css 203 B
build/block-library/blocks/site-logo/style.css 203 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 116 B
build/block-library/blocks/site-title/editor.css 116 B
build/block-library/blocks/site-title/style-rtl.css 57 B
build/block-library/blocks/site-title/style.css 57 B
build/block-library/blocks/social-link/editor-rtl.css 184 B
build/block-library/blocks/social-link/editor.css 184 B
build/block-library/blocks/social-links/editor-rtl.css 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.4 kB
build/block-library/blocks/social-links/style.css 1.39 kB
build/block-library/blocks/spacer/editor-rtl.css 348 B
build/block-library/blocks/spacer/editor.css 348 B
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 433 B
build/block-library/blocks/table/editor.css 433 B
build/block-library/blocks/table/style-rtl.css 645 B
build/block-library/blocks/table/style.css 644 B
build/block-library/blocks/table/theme-rtl.css 146 B
build/block-library/blocks/table/theme.css 146 B
build/block-library/blocks/tag-cloud/style-rtl.css 251 B
build/block-library/blocks/tag-cloud/style.css 253 B
build/block-library/blocks/template-part/editor-rtl.css 403 B
build/block-library/blocks/template-part/editor.css 403 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 99 B
build/block-library/blocks/verse/style.css 99 B
build/block-library/blocks/video/editor-rtl.css 552 B
build/block-library/blocks/video/editor.css 555 B
build/block-library/blocks/video/style-rtl.css 174 B
build/block-library/blocks/video/style.css 174 B
build/block-library/blocks/video/theme-rtl.css 126 B
build/block-library/blocks/video/theme.css 126 B
build/block-library/classic-rtl.css 179 B
build/block-library/classic.css 179 B
build/block-library/common-rtl.css 1.1 kB
build/block-library/common.css 1.1 kB
build/block-library/editor-elements-rtl.css 75 B
build/block-library/editor-elements.css 75 B
build/block-library/elements-rtl.css 54 B
build/block-library/elements.css 54 B
build/block-library/reset-rtl.css 478 B
build/block-library/reset.css 478 B
build/block-library/theme-rtl.css 686 B
build/block-library/theme.css 691 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/commands/style-rtl.css 827 B
build/commands/style.css 827 B
build/customize-widgets/style-rtl.css 1.38 kB
build/customize-widgets/style.css 1.38 kB
build/dom-ready/index.min.js 324 B
build/edit-post/classic-rtl.css 544 B
build/edit-post/classic.css 545 B
build/edit-post/style-rtl.css 7.76 kB
build/edit-post/style.css 7.75 kB
build/edit-widgets/style-rtl.css 4.53 kB
build/edit-widgets/style.css 4.53 kB
build/editor/style-rtl.css 3.54 kB
build/editor/style.css 3.53 kB
build/escape-html/index.min.js 537 B
build/format-library/style-rtl.css 554 B
build/format-library/style.css 553 B
build/html-entities/index.min.js 448 B
build/is-shallow-equal/index.min.js 527 B
build/list-reusable-blocks/style-rtl.css 836 B
build/list-reusable-blocks/style.css 836 B
build/priority-queue/index.min.js 1.52 kB
build/private-apis/index.min.js 939 B
build/react-i18n/index.min.js 696 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/reusable-blocks/style-rtl.css 243 B
build/reusable-blocks/style.css 243 B
build/vendors/inert-polyfill.min.js 2.48 kB
build/vendors/react.min.js 4.02 kB
build/warning/index.min.js 268 B
build/widgets/style-rtl.css 1.15 kB
build/widgets/style.css 1.16 kB

compressed-size-action

@paaljoachim
Copy link
Contributor

I just watched the video and got to say that this looks really good and very useful!

@aaronrobertshaw aaronrobertshaw force-pushed the try/refactor-spacing-controls branch from 1f31160 to b33165d Compare May 19, 2023 03:05
@github-actions
Copy link

github-actions bot commented May 19, 2023

Flaky tests detected in 34c172e.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5107902130
📝 Reported issues:

@aaronrobertshaw aaronrobertshaw changed the title [WIP] Spacing: Optimize & condense unlinked spacing controls Spacing: Optimize & condense unlinked spacing controls May 19, 2023
@aaronrobertshaw aaronrobertshaw marked this pull request as ready for review May 19, 2023 04:11
@aaronrobertshaw aaronrobertshaw requested a review from ellatrix as a code owner May 19, 2023 04:11
@aaronrobertshaw
Copy link
Contributor Author

Do we want to add the new side/axis icons to the library, or should we look to create a dynamic icon component like the BoxControl?

@aaronrobertshaw
Copy link
Contributor Author

The tweak to the font size picker's header spacing is up in #50855.

as for the current spacing fixes, if we trust we'll remember to remove the dead code if/when a new component lands, we can keep it. Otherwise, I'd prefer not to add the scoped code, and fix it all in the better code kind of way. What do you think?

The fix is really just adding a couple of styled components to the FontSizePicker to apply the required CSS styles (16px height + negative margin on the toggle). If we can create a shared component to make this layout more consistent across controls, the new styled components will be removed when the FontSizePicker is refactored to use the proposed component.

I initially thought we might have gotten away with only creating the new component in the block-editor package but given the FontSizePicker lives in our components package, we'd need to add it there. It could be made private though if we don't wish to expose it.

@jasmussen
Copy link
Contributor

I don't personally have a strong opinion on whether we create the correct component first and then fix the spacing, or hack the spacing and then update the hacks once we have the right components. Perhaps @mirka or @jameskoster can chime in?

@@ -29,7 +29,7 @@ export default function SidesDropdown( {
<DropdownMenu
icon={ sideIcon }
label={ labelProp }
className="component-spacing-sizes-control__dropdown"
className="components-spacing-sizes-control__dropdown"
Copy link
Contributor

Choose a reason for hiding this comment

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

Just realized that we're using components-* class names for this component, even if it's not in the @wordpress/components package — this could be causing confusion around which package this component belongs to, and in a way "legitimize" using components-* classnames outside of the @wordpress/components package (which we've been advocating against for some time).

Any changes we could change the components-* class name prefix? (of course, it can happen in a separate PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

In this case, it was copied from existing controls when the spacing controls were created.

There are a lot of cases where components in packages outside of @wordpress/components prefix their component classes with components- as well. These include the editor, block-editor, and block-library packages.

The water is muddied further for the spacing controls due to the styling overrides for the range control's marks, etc.

The tweak commented on here was to make the existing class name at least consistent within the same control. As the spacing sizes control has so far only been exported as experimental from the block-editor package, I think we can change its class names without too much issue.

Other uses of components- in class names will need to be evaluated separately as suggested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've pushed some changes to remove the components prefix from the spacing sizes control. Unfortunately, the need to segment the range control does still require the use of some of the range control's internal classes.

Copy link
Contributor

@ciampo ciampo May 25, 2023

Choose a reason for hiding this comment

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

The tweak commented on here was to make the existing class name at least consistent within the same control. As the spacing sizes control has so far only been exported as experimental from the block-editor package, I think we can change its class names without too much issue.

Thank you @aaronrobertshaw for the super quick work!

There are a lot of cases where components in packages outside of @wordpress/components prefix their component classes with components- as well. These include the editor, block-editor, and block-library packages.

That is absolutely true. It is definitely an uphill battle, especially since only a small group of us are actively trying to bring awareness about it.

It may be hard to remove a lot of those instances outside of the components package, but the least we can do is to avoid introducing new ones and make folks more aware of the high cost that style overrides can have on maintaining our UI components. Your work here is definitely appreciated!

Other uses of components- in class names will need to be evaluated separately as suggested.

Makes sense, let's definitely look at this separately.

Style overrides are usually added by folks when they can't achieve the desired result with the available components and their props. When trying to remove those overrides, we should ask ourselves: is the limitation that we're encountering by design? Should we consider updating the component to fulfill this new need? Or should we reconsider what we're working on and use the component how it was intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When trying to remove those overrides, we should ask ourselves: is the limitation that we're encountering by design?

I'd say for the RangeControl, yes, it is by design, however, the spacing controls being segmented is a pretty left-field design/edge case.

Should we consider updating the component to fulfill this new need?

We do have the updated SliderControls on the horizon so I don't think need to update a component that should be replaced eventually.

Or should we reconsider what we're working on and use the component how it was intended?

This wouldn't be possible while meeting the design. So if we don't want the small CSS tweak to the mark positions, we're left with updating the component or creating a "SegmentedRangeControl".

Ultimately, this overriding of the range control's styles isn't introduced in this PR, it's actually lessened by it.

Any follow-ups can make a decision to updating the RangeControl etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ultimately, this overriding of the range control's styles isn't introduced in this PR, it's lessened by it.

Yup! My earlier comment referred to the broader context around this component, and not this PR specifically.

This wouldn't be possible while meeting the design.

This is very much the point — if we end up in a situation where our designs don't meet the requirements set by other previous design specs, ideally, we should either update the older specs to meet new requirements or update the new design to follow the older specs.

Not a piece of feedback specifically for this PR but more of a general reflection on how I think that, as the developers implementing a design, we should flag this kind of inconsistencies and force them to be resolved one way or the other

@glendaviesnz
Copy link
Contributor

Nice work. For me, when switching to custom, the custom input is taking all the space and squashing the slider:
Screenshot 2023-05-29 at 12 10 27 PM

@aaronrobertshaw
Copy link
Contributor Author

aaronrobertshaw commented May 29, 2023

Thanks for catching that @glendaviesnz 👍

I missed the custom value's range slider when removing as many of the internal component class names as possible. I've fixed that in 7c14c9f.

It should be ready for another test now 🙏

Screenshot 2023-05-29 at 10 58 02 am

Co-authored-by: Glen Davies <glendaviesnz@users.noreply.github.com>
@glendaviesnz
Copy link
Contributor

glendaviesnz commented May 29, 2023

The only other thing I have found is the alignment is wrong in the custom height setting in the Spacer block.

Screenshot 2023-05-29 at 1 15 51 PM

@aaronrobertshaw
Copy link
Contributor Author

Thanks for the thorough testing @glendaviesnz 🙇

The only other thing I have found is the alignment is wrong in the custom height setting in the Spacer block.

When outside the ToolsPanel, it looks like __nextHasNoMarginBottom gets overridden. I've added the custom value input to the selector clearing bottom margins. The control is now aligned for me.

While looking into this I realised that the all side never really existed in the supported sides but was used to show the "all sides" view. Now we don't have that, the use of all for the Spacer block's controls was being treated like an individual side. Thus, showing the "single side" view and expecting it to be a supported side.

The BlockGap took a different approach and fudged things using the top or left sides. It turns out both resulted in incorrect, or unintended, visually hidden labels e.g. "undefined height" (since all isn't in the list of supported sides) or "top block spacing".

Screenshot 2023-05-29 at 12 08 33 pm

I've leveraged the existing showSideInLabel prop and plumbed that through to the SingleInputControl and the SpacingInputControl itself so we can include an appropriate label. See 34c172e.

Let me know what you think and if there's anything else I missed.

Copy link
Contributor

@glendaviesnz glendaviesnz left a comment

Choose a reason for hiding this comment

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

Tested well for me:
✅ Unit tests ran successfully
✅ Was able to adjust spacing on various blocks and axis with both preset and custom values
✅ Only supported sides appear in the dropdown
✅ Setting "customSpacingSize":false in theme.json caused only custom inputs to display
✅ Setting > 8 spacing preset sizes caused select list to appear instead of slider
✅ Setting all possible combinations of supported sides in block.json worked as expected

@aaronrobertshaw aaronrobertshaw merged commit 4bdc581 into trunk May 29, 2023
@aaronrobertshaw aaronrobertshaw deleted the try/refactor-spacing-controls branch May 29, 2023 03:50
@github-actions github-actions bot added this to the Gutenberg 16.0 milestone May 29, 2023
@jasmussen
Copy link
Contributor

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Feature] UI Components Impacts or related to the UI component system Needs User Documentation Needs new user documentation [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimise and condense unlinked padding / margin controls
6 participants