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

Update the Spinner design #37551

Merged
merged 31 commits into from
Feb 1, 2022
Merged

Update the Spinner design #37551

merged 31 commits into from
Feb 1, 2022

Conversation

jameskoster
Copy link
Contributor

@jameskoster jameskoster commented Dec 21, 2021

This PR updates the Spinner component based on the designs in #36725. It also adjusts/fixes the position of the Spinner that appears when searching for documents in the add-link interface. Finally, it adds the gray-300 value to color-values.js, which has until now been missing. On this point I did notice that gray-200 has the incorrect value, but as I'm not sure where that is used, I figured we should fix it separately.

Things seem to be working well in the following scenarios:

  • Loading a document that has internal dependencies like template parts, or the site logo
  • Embedding third party content like a Tweet.
  • Searching blocks in the Inserter
  • Searching in the link input

Testing instructions

  • Perform any action that invokes a spinner and check that it displays and behaves as expected, examples:
    • Edit a template in the site editor that includes template parts
    • Embed third party content like a tweet
    • Search for a block in the Inserter
    • Add a link and search for a post/page
    • Others that I'm missing? :)
  • Try different browsers. This is working in Chrome, Firefox, and Safari, but I am unable to test Edge

@jameskoster jameskoster marked this pull request as draft December 21, 2021 12:46
@github-actions
Copy link

github-actions bot commented Dec 21, 2021

Size Change: +79 B (0%)

Total Size: 1.14 MB

Filename Size Change
build/block-editor/style-rtl.css 14.6 kB -1 B (0%)
build/block-editor/style.css 14.6 kB -1 B (0%)
build/block-library/editor-rtl.css 10 kB -1 B (0%)
build/components/index.min.js 215 kB +82 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.22 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 141 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 150 B
build/block-library/blocks/audio/editor.css 150 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 292 B
build/block-library/blocks/buttons/editor.css 292 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 131 B
build/block-library/blocks/code/theme.css 131 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 406 B
build/block-library/blocks/columns/style.css 406 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/comments-query-loop/editor-rtl.css 95 B
build/block-library/blocks/comments-query-loop/editor.css 95 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 965 B
build/block-library/blocks/gallery/editor.css 967 B
build/block-library/blocks/gallery/style-rtl.css 1.61 kB
build/block-library/blocks/gallery/style.css 1.61 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 199 B
build/block-library/blocks/latest-posts/editor.css 198 B
build/block-library/blocks/latest-posts/style-rtl.css 447 B
build/block-library/blocks/latest-posts/style.css 446 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.92 kB
build/block-library/blocks/navigation/editor.css 1.93 kB
build/block-library/blocks/navigation/style-rtl.css 1.85 kB
build/block-library/blocks/navigation/style.css 1.84 kB
build/block-library/blocks/navigation/view.min.js 2.81 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 402 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 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 521 B
build/block-library/blocks/post-comments/style.css 521 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 323 B
build/block-library/blocks/post-template/style.css 323 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 201 B
build/block-library/blocks/quote/style.css 201 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 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.37 kB
build/block-library/blocks/social-links/style.css 1.36 kB
build/block-library/blocks/spacer/editor-rtl.css 332 B
build/block-library/blocks/spacer/editor.css 332 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 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 214 B
build/block-library/blocks/tag-cloud/style.css 215 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 571 B
build/block-library/blocks/video/editor.css 572 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 908 B
build/block-library/common.css 905 B
build/block-library/editor.css 10 kB
build/block-library/index.min.js 166 kB
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/style-rtl.css 10.8 kB
build/block-library/style.css 10.8 kB
build/block-library/theme-rtl.css 672 B
build/block-library/theme.css 676 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.4 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.4 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.2 kB
build/edit-navigation/style-rtl.css 3.76 kB
build/edit-navigation/style.css 3.76 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-post/index.min.js 29.6 kB
build/edit-post/style-rtl.css 7.15 kB
build/edit-post/style.css 7.14 kB
build/edit-site/index.min.js 41.5 kB
build/edit-site/style-rtl.css 7.22 kB
build/edit-site/style.css 7.21 kB
build/edit-widgets/index.min.js 16.6 kB
build/edit-widgets/style-rtl.css 4.17 kB
build/edit-widgets/style.css 4.17 kB
build/editor/index.min.js 38.4 kB
build/editor/style-rtl.css 3.71 kB
build/editor/style.css 3.71 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.75 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 917 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.58 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

@jameskoster jameskoster linked an issue Dec 21, 2021 that may be closed by this pull request
@jameskoster jameskoster marked this pull request as ready for review January 6, 2022 12:02
@jameskoster jameskoster requested a review from ellatrix as a code owner January 6, 2022 12:02
@jameskoster jameskoster requested a review from jasmussen January 6, 2022 12:03
@amustaque97 amustaque97 added [Package] Components /packages/components [Type] Enhancement A suggestion for improvement. labels Jan 7, 2022
@jasmussen
Copy link
Contributor

This is very nice! Thanks for working on it.

I also really love these designs:
Screenshot 2022-01-10 at 09 48 00

Is there any way we can get closer to these in terms of design? Stroke-width, white instead of spot color in dark contexts, a gray base circle track?

@jameskoster
Copy link
Contributor Author

The only way I can think to include the track would be to use an svg rather than css alone, otherwise the mask is interfering too much. I've pushed an update to try this.

spinner.mp4

I'm not sure what the stroke width is in those screenshots, but I've set them to 1.5px for now. Easily changed.

I can't think of a way to make the colors adapt based on the background as the Spinner isn't aware of that. This might be something better left as an option on the Spinner itself.

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.

The SVG is working really well here. For testing it I managed to record this GIF:
spin

I can't help but feel like the material influence here makes it a bit stuttery. The way the expansion and contraction of the blue indicator makes it appear as if it's pausing. I may be rather dull in the following, but a simple uniform rotation with no contracting might actually be preferable.

I'm going to tinker a bit in this codepen and come back! Thanks again for the work 👌

@@ -0,0 +1,44 @@
.components-spinner--svg {
Copy link
Contributor

Choose a reason for hiding this comment

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

The SVG is working fairly well here! However just as far as classnames go, should we call it "track" instead? Also, I think it should be __ instad of --. I.e. .components-spinner__track for example.

left: 0;
}

@keyframes rotatesvg {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment with above, denoting the element as "track" might be better.

It seems correct to me to put this keyframe statement right in this components file where it will be used, especially since it's unique to this component and not reused. But naming-wise, we could use some BEM niceness here as well, for example components-spinner__spin-track perhaps?

}
}

.components-spinner--circle {
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, this is the blue part of the spinner that in this PR contracts and expands, so it's more of a quarter-circle. I realize this is nitpick territory, but I think it'd help readability. How about something like .components-spinner__indicator? Note the __ instead of --.

transform-origin: 50% 50%;
}

@keyframes rotatecircle {
Copy link
Contributor

Choose a reason for hiding this comment

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

BEM all the way. How about components-spinner__spin-indicator?

@jasmussen
Copy link
Contributor

jasmussen commented Jan 11, 2022

Another reason to maybe reconsider the expansion and contraction of the indicator is that it isn't relative to the size of the spinner. While I don't know exactly how often we'll show a 128x128 spinner, a few things broke apart when I tried it:

spin 128

It's actually still expanding and contracting, it's just not very visible because the dashoffset change is insignificant when large. I wonder if you could use ems there? Probably not? 🤔

Another one is the fact that the gray track is outset compared to the blue indicator. I don't know why that happens. Edit: Oh I know, the radius of the circle is 8.25, it should be 9 to match with half of the 18x18 svg viewbox. Combined with overflow: visible; on the SVG, it works.

@jasmussen
Copy link
Contributor

jasmussen commented Jan 11, 2022

Using an SVG seems appropriate enough for this, but I'm starting to think that using dasharray might not be. Mainly because I can't figure out how to make a dasharray that behaves in a relatively scaling way. Shown here a dasharray that approaches (but isn't precisely) a quarter circle as from the initial mockup, but only when the spinner is really big:
Screenshot 2022-01-11 at 13 41 35

We might need a static SVG that just draws that quarter-circle precisely, and not use the dasharray trick 🤔

Edit: Feel free to tinker in this codepen: https://codepen.io/joen/pen/RwLeByP?editors=1100

@jameskoster
Copy link
Contributor Author

because I can't figure out how to make a dasharray that behaves in a relatively scaling way

Perhaps we can add some logic so that the dasharray value(s) are based on the spinner size?

I appreciate it's subjective/intangible, but I quite like the expansion/contraction effect. I can't put my finger on why but it makes it feel like something is happening compared with the linear spinner. Maybe it's the pulsing.

Then again, if we eliminate that effect it would make the original design much easier to accomplish without the need for an svg. Maybe we can add a pulsing effect another way 🤔 I will also have a play in codepen :D

@jameskoster
Copy link
Contributor Author

I added a "Pulsey no svg" version to this codepen.

Gif:

spinner

The main drawback to this approach is that it uses borders for the indicator line, which cannot be set to a 1.5px width.

@jasmussen
Copy link
Contributor

Impressive work going on in these codepens, I love it. I'm also starting to see your point about the contraction/expansions being a bit more dynamic. But just looking at them side by side, I'm personally still most attracted to the complete calmness of the linearly rotating circle, I feel like it might just work the best in noisy contexts.

@jameskoster
Copy link
Contributor Author

Reverted to html + css only, and simplified the animation. Here's the result:

spinner

The last question seems to be what to do about the discrepancy between track/indicator width.

@jasmussen
Copy link
Contributor

Clever trick to use border-top to grab exactly one quarter of the circle! I suppose box-shadow wouldn't work for that, as it would be affected by the contours of the circle shape. I do think it's important we get the right stroke width, though — maybe the SVG was fine after all? That might also let us keep that neat rounded edgecap.

Alternatively we could create another full circle and mask a quadrant of it?

@jameskoster
Copy link
Contributor Author

To get the strokes to be 1.5px I think we'll have to return to the SVG approach. I just pushed a change that does this, and includes logic so that the dasharray will scale correctly. You can change the spinnerSize value in config-values.js to test this. Here's an example at 180px:

@jasmussen
Copy link
Contributor

I mean, I really dig that one 👌

Is this one ready for final review?

@jameskoster
Copy link
Contributor Author

Yup, I think so!

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.

This is working really well for me:
spin

It's a nice and simple spinner that benefits from the spot color.

I know you had your heart set on some expansion/contraction of the indicator, I think that's still something that can be explored in a codepen if you're finding yourself missing it. But because it's so rarely shown (thankfully things load fast), starting minimalist like this feels like a good baseline.

I left a few comments, but this looks good. Nice work, thank you!

packages/components/src/spinner/index.js Outdated Show resolved Hide resolved
packages/components/src/utils/colors-values.js Outdated Show resolved Hide resolved
packages/components/src/utils/config-values.js Outdated Show resolved Hide resolved
@ciampo ciampo self-requested a review January 19, 2022 16:36
Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

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

Hey @jameskoster , thank you for your work, and sorry for the late review — I wasn't away of this PR until @sarayourfriend pinged me.

I left a few comments around — would you also be able to add an entry to the CHANGELOG ? Thank you!

packages/components/src/spinner/index.js Outdated Show resolved Hide resolved
packages/components/src/spinner/index.js Outdated Show resolved Hide resolved
packages/components/src/spinner/index.js Outdated Show resolved Hide resolved
packages/components/src/spinner/index.js Outdated Show resolved Hide resolved
packages/components/src/spinner/index.js Outdated Show resolved Hide resolved
packages/components/src/spinner/index.js Outdated Show resolved Hide resolved
packages/components/src/spinner/index.js Outdated Show resolved Hide resolved
Comment on lines 26 to 31
const viewBox = `0 0 ${ CONFIG.spinnerSize } ${ CONFIG.spinnerSize }`;
const radius = Number( CONFIG.spinnerSize ) / 2;
const strokeDasharray = [
Number( CONFIG.spinnerSize ),
Number( CONFIG.spinnerSize ) * 10,
];
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry if missed this while skimming through the previous conversations, but is there a reason why we compute dynamically viewBox, radius and strokeDasharray, all in relation to spinnerSize ?

With SVG we should be able to define an arbitrary viewBox and then scale everything accordingly. We could then use spinnerSize in the styles to change width and height of the SVG element itself (example)

Copy link
Contributor Author

@jameskoster jameskoster Jan 20, 2022

Choose a reason for hiding this comment

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

Yeah that would be a lot simpler wouldn't it :) We'll need to keep the computed stroke-dasharray though in order for the indicator to scale correctly, so we'll probably need to add a size property to the Spinner in the future.

packages/components/src/utils/config-values.js Outdated Show resolved Hide resolved
@@ -48,7 +48,7 @@ export default {
borderWidth: '1px',
borderWidthFocus: '1.5px',
borderWidthTab: '4px',
spinnerSize: '18px',
spinnerSize: Number( '18' ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ciampo let me know if this is correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to just use the value 18, without wrapping it in Number(). You could then also update the stroke-dasharray attribute, since it doesn't require a runtime calc anymore

For example (click to expand):
diff --git a/packages/components/src/spinner/index.js b/packages/components/src/spinner/index.js
index b256e44a75..f30a852403 100644
--- a/packages/components/src/spinner/index.js
+++ b/packages/components/src/spinner/index.js
@@ -39,8 +39,7 @@ export const SpinnerIndicator = styled.circle`
 	stroke-linecap: round;
 	stroke-width: 1.5px;
 	transform-origin: 50% 50%;
-	stroke-dasharray: ${ CONFIG.spinnerSize },
-		calc( ${ CONFIG.spinnerSize } * 10 );
+	stroke-dasharray: ${ CONFIG.spinnerSize }, ${ CONFIG.spinnerSize * 10 };
 `;
 
 export default function Spinner() {
diff --git a/packages/components/src/utils/config-values.js b/packages/components/src/utils/config-values.js
index 526f85c457..7ba2b9d3dc 100644
--- a/packages/components/src/utils/config-values.js
+++ b/packages/components/src/utils/config-values.js
@@ -48,7 +48,7 @@ export default {
 	borderWidth: '1px',
 	borderWidthFocus: '1.5px',
 	borderWidthTab: '4px',
-	spinnerSize: Number( '18' ),
+	spinnerSize: 18,
 	fontSize: '13px',
 	fontSizeH1: 'calc(2.44 * 13px)',
 	fontSizeH2: 'calc(1.95 * 13px)',

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 get an error when I try it this way 🤔

Screenshot 2022-01-20 at 12 46 21

Thinking about this a little more, do we actually need the spinnerSize config value? It doesn't seem to serve much of a purpose right now, especially as all Spinner instances are currently the same size. Might a better approach be to allow a size prop on the Spinner component? That way it's easy to use different sized spinners ad hoc.

Copy link
Contributor

@ciampo ciampo Jan 20, 2022

Choose a reason for hiding this comment

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

I get an error when I try it this way 🤔

It seems like your IDE thinks that spinnerSize is a string — did you also update spinnerSize in the config (as part of the diff above)? i.e

Suggested change
spinnerSize: Number( '18' ),
spinnerSize: 18,

Thinking about this a little more, do we actually need the spinnerSize config value? It doesn't seem to serve much of a purpose right now, especially as all Spinner instances are currently the same size. Might a better approach be to allow a size prop on the Spinner component? That way it's easy to use different sized spinners ad hoc.

Let's leave it in the config for now, as it matches the $spinner-size variable in the base styles. We have plans later this year to take a closer look at the overall config variables :)

Re. adding a size prop, let's investigate that separately from this PR, maybe while we also address some of the ideas discussed in #37551 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

did you also update spinnerSize in the config (as part of the diff above)? i.e

Derp, I did not :)

Re. adding a size prop, let's investigate that separately from this PR

Okay! I think we'll need to do something, because atm if you use a Spinner and resize it with css alone it won't scale correctly:

Screenshot 2022-01-20 at 13 26 18

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh nice, this looks more comprehensive – thanks so much :) Please feel free to push the changes.

Do you think it's worth including the preset sizes in the component as a part of this PR? If so the only tweak I would suggest would be to use multiples of our grid unit (or spinner-size) values for the medium/large spinners.

Now that I think of it, it might be a good idea to make the default spinnerSize 16px so that it better aligns with the broader grid.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please feel free to push the changes.

Thank you ! I went ahead and pushed those changes (including a change to the README to remove the out of date screenshot).

Do you think it's worth including the preset sizes in the component as a part of this PR? If so the only tweak I would suggest would be to use multiples of our grid unit (or spinner-size) values for the medium/large spinners.

I did include the updates to the Storybook examples, if anything to test that the stroke width is not changing as we increase the overall size of the spinner — I also made sure that those storybook examples use multiples of the grid unit.

For now, I wouldn't include any new APIs to the component (e.g. size), since the previous one also didn't have it.

Now that I think of it, it might be a good idea to make the default spinnerSize 16px so that it better aligns with the broader grid.

I haven't made that change yet as I'm not sure if resizing the spinner (from 18px to 16px) would have any ripercussions / would be considered breaking change. @jasmussen do you have any opinions on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, this is looking fantastic :)

I think there's a reasonable case to resize from 18px to 16px. It aligns with our grid unit, and most other icons tend to render at ~16px, e.g. Styles icon:

Screenshot 2022-01-21 at 16 36 14

Not a strong feeling though, and happy to defer to @jasmussen on this point.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done in 91a861f

Let me know once you've had a look, I think we may be able to merge this PR :)

@jameskoster
Copy link
Contributor Author

Thanks @ciampo.

would you also be able to add an entry to the CHANGELOG ?

I thought this got updated automatically? 🤔

Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

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

would you mind rebasing on top of trunk to include those changes and solve conflicts? (Feel free to delete Riad's fix on this PR, as it was already included with the merge of #38237).

I took the freedom of doing that (hope you don't mind, @jameskoster !)

We can have a final look at the PR and hopefully everything will be in a good shape 🤞

I gave one final quick look and everything seems to work well — although I'd appreciate if other folks could also give it a final look before merging!

Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for all the hard work and patience on this one as we went back and forth on that iframe issue, really appreciate it 🙏

Comment on lines 24 to 25
display: block;
margin: auto;
Copy link
Contributor

@ciampo ciampo Jan 31, 2022

Choose a reason for hiding this comment

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

As I gave one last look at the code changes, I just noticed a couple of differences that I'd like to discuss:

  • display: it used to be inline-block, it's currently block. I personally like block more, but this change could be potentially breaking for some layouts
  • margin: it used to be 5px 11px 0, it's not auto. This is also a potentially breaking change. I personally believe that a component should not define rules for its own margin, and so my preference would be to either keep things as they are, or to introduce a breaking change by removing the margin rule altogether.

What do folks think? (also cc @mirka @jasmussen )

Copy link
Contributor

Choose a reason for hiding this comment

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

High level I do like the idea of unifying and systematizing how the spinner appears, for example always centered. But it also seems like something that needs a little exploration and guideline in terms of where the spinner is currently used, and might involve updating the places where it's used. That seems to suggest a separate exploratory PR for that, and then in order to land this big improvement, perhaps going back to inline-block. Though I do think we find a better margin, perhaps $grid-unit-10 $grid-unit-10 0?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with your point.

Probably best thing to do here is to switch back to the values we had before (display: inline-block and margin: 5px 11px 0), to make sure we don't introduce any breaking changes.

We can then definitely explore what to do separately, as you 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'm unaware of the history around the margin value, but the results are suboptimal in places like the Site Logo and Template Part blocks. margin: auto; works better as a default in that regard.

Then again the idea of having no margin on the Spinner at all does seem better on the surface. So I'm happy to leave the margin/display values as-is and revisit separately.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh definitely we need that. Just in order to land this one with minimal disruption, we can pull back on those, and then follow up in small PRs, either a separate PR that just re-adds the auto margin entirely, or adds the margin in the contexts where they are needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, I'll go ahead, push these changes, give it a "final final" look and hopefully merge

Copy link
Contributor

Choose a reason for hiding this comment

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

Merged!

follow up in small PRs, either a separate PR that just re-adds the auto margin entirely, or adds the margin in the contexts where they are needed.

My preference would be to remove the margin rule altogether from Spinner and add any necessary margin where each instance of Spinner is used

Copy link
Contributor

Choose a reason for hiding this comment

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

Generally agree that the component itself should be unopinionated and subject to its container. But given very few existing containers are likely to be aware of this new responsibility, it might still make sense to have something. We could then consider that a default margin (either a fixed clearance all around, or auto margins), which would then be easily overriden by it's container?

Copy link
Member

Choose a reason for hiding this comment

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

My preference would be to remove the margin rule altogether from Spinner and add any necessary margin where each instance of Spinner is used

This is my general preference, too. And if the audit shows that it's frequently used as an inline item, I'd consider giving it some padding (instead of margin) so it isn't flush with the bounding box. Basically like an icon component.

@pablohoneyhoney
Copy link

Round of applause!

It really needed an update 😄

@jameskoster
Copy link
Contributor Author

Aside from the margin issue above, everything seems to be working well. Thanks for all the help :)

@ciampo ciampo merged commit 65f7c31 into trunk Feb 1, 2022
@ciampo ciampo deleted the update/spinner branch February 1, 2022 12:22
@github-actions github-actions bot added this to the Gutenberg 12.6 milestone Feb 1, 2022
@getdave
Copy link
Contributor

getdave commented Feb 18, 2022

@jameskoster First up - great work here. This is a big improvement! 🤝 👏 .

I've been looking into improving the communication around loading states in a block I'm working on. I'm curious did you do any research into whether using speak from @wordpress/a11y would be helpful as part of the component?

I noticed you added aria-busy so I'm interested to understand more about this.

Also did anyone from the Core Accessibility team review this PR?

@jameskoster
Copy link
Contributor Author

I noticed you added aria-busy so I'm interested to understand more about this.

I think you are referring to a different Spinner :D

In terms of this PR there was a little discussion around a11y, but the primary focus was to update the visuals.

jeherve added a commit to Automattic/jetpack that referenced this pull request May 8, 2023
@jameskoster jameskoster added the Design System Issues related to the system of combining components according to best practices. label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design System Issues related to the system of combining components according to best practices. [Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Updating the loading spinner
9 participants