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

Allow customization of AvatarStack hover behavior and size #3466

Merged
merged 23 commits into from
Jul 7, 2023

Conversation

mperrotti
Copy link
Contributor

  • Allows consumers to disable the behavior where the stack expands to show all avatars on hover
  • Allows consumers to customize the size for the avatars in the stack. This can be done two ways:
    • pass a size prop to AvatarStack
    • pass a size prop to the Avatars that are direct children of AvatarStack
  • Does not allow an AvatarStack to render it's children at different sizes. The smallest size will always be picked.

Closes https://github.com/github/primer/issues/2366

Screenshots

Kapture.2023-06-30.at.16.09.20.mp4

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Changes are SSR compatible
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@mperrotti mperrotti requested review from a team and langermank June 30, 2023 20:17
@changeset-bot
Copy link

changeset-bot bot commented Jun 30, 2023

🦋 Changeset detected

Latest commit: 356bf65

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

This PR includes changesets to release 1 package
Name Type
@primer/react Minor

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

@github-actions
Copy link
Contributor

github-actions bot commented Jun 30, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 102.31 KB (+0.69% 🔺)
dist/browser.umd.js 102.88 KB (+0.71% 🔺)

@github-actions github-actions bot temporarily deployed to storybook-preview-3466 June 30, 2023 20:24 Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3466 June 30, 2023 20:25 Inactive
@mperrotti mperrotti temporarily deployed to github-pages June 30, 2023 20:27 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3466 June 30, 2023 20:27 Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3466 June 30, 2023 20:28 Inactive
Copy link
Member

@broccolinisoup broccolinisoup left a comment

Choose a reason for hiding this comment

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

Love it! 💖 Just left a tiny comment - not a blocker.


type StyledAvatarStackWrapperProps = {
count?: number
} & SxProp

const findSmallestNumber = (numbers: number[]): number => {
Copy link
Member

Choose a reason for hiding this comment

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

Would Math.min(...numbers) work here? 🤔 Just an idea - not a blocker at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great suggestion! Soooo much easier.

Copy link
Contributor

@maximedegreve maximedegreve 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 great @mperrotti 🎉

One thing that's missing in this PR is support for breakpoints.

Otherwise developers will have to get around this issue using:

<Box sx={{display: ['block', 'block', 'none']}}>
   <AvatarStack size={26}/>
</Box>
<Box sx={{display: ['none', 'none', 'block']}}>
   <AvatarStack size={20}/>
</Box>

Instead of:

<AvatarStack size={[20,20,24]}/>

Without this support it will also make working with HTML grids hard because the Box is never removed from the DOM and will create an additional grid cell.

@@ -127,21 +163,42 @@ const transformChildren = (children: React.ReactNode) => {

export type AvatarStackProps = {
alignRight?: boolean
disableExpand?: boolean
Copy link
Member

@siddharthkp siddharthkp Jul 3, 2023

Choose a reason for hiding this comment

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

Personal opinion, not strongly held: disableExpand is a double negative, which can feel confusing

What do you think about expand: boolean where default is true?

<AvatarStack />

<AvatarStack expand={false} />

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It feels strange to have to explicitly pass propName={false} because boolean props are normally evaluated as false if the prop is excluded.

If we didn't set expand to true by default, then <AvatarStack /> would be the same as <AvatarStack expand={false} />

Copy link
Member

@siddharthkp siddharthkp Jul 6, 2023

Choose a reason for hiding this comment

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

It feels strange to have to explicitly pass propName={false}

true true!

because boolean props are normally evaluated as false if the prop is excluded

not sure about that tho 😅

// default true
<AvatarStack/>  = <AvatarStack expand /> = <AvatarStack expand={true} />

// disabling default: 
<AvatarStack expand={false}/>

buuuut, also happy to go with what you feel strongly about

@mperrotti mperrotti temporarily deployed to github-pages July 5, 2023 23:02 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3466 July 5, 2023 23:03 Inactive
@mperrotti
Copy link
Contributor Author

@broccolinisoup and @maximedegreve - I have your suggestions implemented.

This should be merge-able once I:

  • Update tests and stories
  • Fix an annoying TypeScript error when trying to pass getBreakpointDeclarations() to merge() (@broccolinisoup - maybe we can pair on this?)
  • Other misc code cleanup
  • Comment any complicated code I couldn't simplify

@mperrotti mperrotti temporarily deployed to github-pages July 6, 2023 02:34 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3466 July 6, 2023 02:34 Inactive
@maximedegreve
Copy link
Contributor

@mperrotti Oh no!

@mperrotti
Copy link
Contributor Author

Haha thanks for sharing that @maximedegreve - I'll be fixing that while I make my other changes today.

@github-actions github-actions bot temporarily deployed to storybook-preview-3466 July 6, 2023 20:41 Inactive
@primer primer bot temporarily deployed to github-pages July 6, 2023 21:13 Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3466 July 6, 2023 21:14 Inactive
@maximedegreve
Copy link
Contributor

LGTM 🚀💪

@dusave
Copy link
Contributor

dusave commented Jul 6, 2023

Broader question, not a blocker for this PR: Are we adding any sort of prefers-reduced-motion rule in the animation definitions of components to disable them users automatically? This could be supplemented with the explicit prop (the consumer might want it disabled for all users), but for accessibility reasons, adding the css check could make it much easier to work with.

Copy link
Member

@broccolinisoup broccolinisoup left a comment

Choose a reason for hiding this comment

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

Looks great! Just left a comment about the type stuff but feel free to ignore if it is not helpful.

🚀 🚀 🚀

ref,
) {
return <StyledAvatar ref={ref} alt={alt} size={size} square={square} {...rest} />
const avatarSx = isResponsiveValue(size)
? merge(
Copy link
Member

Choose a reason for hiding this comment

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

Sorry I missed your ping about the type stuff.

I think we could also do

merge<BetterSystemStyleObject>(...)

instead of typing each input as?

Also totally optional maybe for readability

const avatarSx = isResponsiveValue(size)
    ? getBreakpointDeclarations(
        size,
        '--avatar-size' as keyof React.CSSProperties,
        value => `${value || DEFAULT_AVATAR_SIZE}px`,
      )
    : {'--avatar-size': `${size}px`}

and then in the StyledAvatar

sx={merge<BetterSystemStyleObject>(avatarSx, sxProp)}

Just a suggestion - however you prefer.

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 think I remember there being an performance issue with passing merge() directly to to sx, so I'm going to keep it as-is. Definitely going to use a generic instead of as though. Great suggestion!

Copy link
Member

Choose a reason for hiding this comment

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

Ohh I didn't know about the performance impact on using merge in sx! Thanks for letting me know!

@mperrotti
Copy link
Contributor Author

@dusave

Are we adding any sort of prefers-reduced-motion rule in the animation definitions of components to disable them users automatically?

We do use prefers-reduced-motion rules in some components, but not this one. I'm going to check with a11y design to see if it makes sense for this small transition.

@mperrotti
Copy link
Contributor Author

@dusave - I checked with a11y, and it looks like this is safe to keep enabled even when the user prefers reduced motion.

@mperrotti mperrotti enabled auto-merge July 7, 2023 15:25
@mperrotti mperrotti temporarily deployed to github-pages July 7, 2023 15:33 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3466 July 7, 2023 15:34 Inactive
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.

5 participants