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

fix(Avatar): avatar size and loading skeleton #2880

Merged
merged 8 commits into from
Sep 20, 2024

Conversation

cf-remylenoir
Copy link
Collaborator

@cf-remylenoir cf-remylenoir commented Sep 18, 2024

Purpose of PR

Fixes the Avatar's loading skeleton rendering.

We extend the size property to receive custom sizes. This should prevent people from using custom styling that does not deeply apply to the Avatar > Image > Skeleton loader component, see below:

Current rendering with custom styling

size-with-custom-styling.mov

Loading skeleton

Tip

One can observe the loading skeleton before/after in the deployed Storybook by blocking the request to the avatar image:

  • In the Avatar stories
  • In the Navbar stories

Before

before.mov

After

after.mov

Storybook update

  • Add loading state to all Loading section
  • Includes custom size via props examples
Screen.Recording.2024-09-18.at.14.30.46.mov

PR Checklist

  • I have read the relevant readme.md file(s)
  • All commits follow our Git commit message convention
  • Tests are added/updated/not required
  • Tests are passing
  • Storybook stories are added/updated/not required
  • Usage notes are added/updated/not required
  • Has been tested based on Contentful's browser support
  • Doesn't contain any sensitive information

@cf-remylenoir cf-remylenoir self-assigned this Sep 18, 2024
Copy link

vercel bot commented Sep 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
forma-36 ✅ Ready (Inspect) Visit Preview Sep 20, 2024 1:09pm

Copy link

changeset-bot bot commented Sep 18, 2024

🦋 Changeset detected

Latest commit: 2ae8735

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 36 packages
Name Type
@contentful/f36-avatar Patch
@contentful/f36-components Patch
@contentful/f36-navbar Patch
@contentful/f36-accordion Patch
@contentful/f36-asset Patch
@contentful/f36-autocomplete Patch
@contentful/f36-badge Patch
@contentful/f36-button Patch
@contentful/f36-card Patch
@contentful/f36-collapse Patch
@contentful/f36-copybutton Patch
@contentful/f36-core Patch
@contentful/f36-datetime Patch
@contentful/f36-datepicker Patch
@contentful/f36-drag-handle Patch
@contentful/f36-entity-list Patch
@contentful/f36-empty-state Patch
@contentful/f36-forms Patch
@contentful/f36-icon Patch
@contentful/f36-header Patch
@contentful/f36-list Patch
@contentful/f36-menu Patch
@contentful/f36-modal Patch
@contentful/f36-note Patch
@contentful/f36-notification Patch
@contentful/f36-pagination Patch
@contentful/f36-pill Patch
@contentful/f36-popover Patch
@contentful/f36-skeleton Patch
@contentful/f36-spinner Patch
@contentful/f36-table Patch
@contentful/f36-tabs Patch
@contentful/f36-text-link Patch
@contentful/f36-tooltip Patch
@contentful/f36-typography Patch
@contentful/f36-image Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

github-actions bot commented Sep 18, 2024

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
CommonJS 111.96 KB (-0.03% 🔽) 2.3 s (-0.03% 🔽) 1.3 s (+8.16% 🔺) 3.6 s
Module 110.58 KB (-0.11% 🔽) 2.3 s (-0.11% 🔽) 1.6 s (+4.28% 🔺) 3.8 s

@cf-remylenoir cf-remylenoir force-pushed the fix-avatar-size-and-loading-skeleton branch from 720a0cc to 0d375e0 Compare September 18, 2024 14:07
@cf-remylenoir cf-remylenoir marked this pull request as ready for review September 18, 2024 14:09
@cf-remylenoir cf-remylenoir requested review from damann and a team as code owners September 18, 2024 14:09
* @default 'medium'
*/
size?: Size;
size?: Size | string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would rather adhere to the sizes we have in our product than introduce this to break the rules 🤷

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Offering flexibility on top of our system isn't necessarily bad, especially for this component.

99% of the time, the Avatar will be used with a size variant to fit the overall composition and what designers followed in the Design System. With this change, the size is distributed up to 2 levels down (Avatar > Image + Skeleton loader), without CSS override.

That said, this is to satisfy the 1%, one could argue that having a CSS override with nested targeting to reach the image + skeleton is a good compromise too, and that we should not update the API.

@damann @andipaetzold thoughts?

Copy link

Choose a reason for hiding this comment

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

Without having a deep understanding of it, I’m not seeing the value in allowing overrides for images and skeletons. Could you provide an example of when these overrides would be necessary?

Copy link
Collaborator Author

@cf-remylenoir cf-remylenoir Sep 19, 2024

Choose a reason for hiding this comment

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

The account setting page uses the Avatar component with a custom size via CSS override, which results in a broken experience (see first video in PR description).

With the proposed changes, the custom size can be specified via the Avatar props (e.g. 52px), does not require CSS override, and is propagated to the Image + skeleton loader components.

The flip side of the coin that Kristoffer mentions, is that with the proposed changes, we allow any custom value in (on top of the size variants system).

Copy link
Contributor

@andipaetzold andipaetzold Sep 19, 2024

Choose a reason for hiding this comment

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

I would rather adhere to the sizes we have in our product than introduce this to break the rules 🤷

I generally agree with that. Most other components don't allow that kind of override, but we limit users to specific values.

In this case, CSS overrides are not straight forward. The size impacts multiple CSS properties and relies on knowing the internal structure.

With the proposed type, we loose all autocompletion for the property. I would therefore go for Size | `${number}px` or similar. That way, the IDE still suggests the official sizes.

Alternatively, we could allow passing a custom size but hide that from the public API.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point for the typing, template literal is a better approach.

Copy link
Contributor

@andipaetzold andipaetzold left a comment

Choose a reason for hiding this comment

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

Remember to add a changeset

@cf-remylenoir cf-remylenoir force-pushed the fix-avatar-size-and-loading-skeleton branch from a118eda to 2ae8735 Compare September 20, 2024 13:02
@cf-remylenoir cf-remylenoir merged commit 74b10dc into main Sep 20, 2024
12 checks passed
@cf-remylenoir cf-remylenoir deleted the fix-avatar-size-and-loading-skeleton branch September 20, 2024 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants