Skip to content

Allow customization of AvatarStack hover behavior and size - #3466

Merged
mperrotti merged 23 commits into
mainfrom
mp/avatarstack-disable-expand
Jul 7, 2023
Merged

Allow customization of AvatarStack hover behavior and size#3466
mperrotti merged 23 commits into
mainfrom
mp/avatarstack-disable-expand

Conversation

@mperrotti

Copy link
Copy Markdown
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.

Closeshttps://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 langermankJune 30, 2023 20:17
@changeset-bot

changeset-botBot commented Jun 30, 2023

Copy link
Copy Markdown

🦋 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
NameType
@primer/reactMinor

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

github-actionsBot commented Jun 30, 2023

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
dist/browser.esm.js102.31 KB (+0.69% 🔺)
dist/browser.umd.js102.88 KB (+0.71% 🔺)

@github-actions
github-actionsBot temporarily deployed to storybook-preview-3466 June 30, 2023 20:24 Inactive
@github-actions
github-actionsBot 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-actionsBot temporarily deployed to storybook-preview-3466 June 30, 2023 20:27 Inactive
@github-actions
github-actionsBot temporarily deployed to storybook-preview-3466 June 30, 2023 20:28 Inactive

@broccolinisoupbroccolinisoup left a comment

Copy link
Copy Markdown
Member

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.

Comment threadsrc/AvatarStack/AvatarStack.tsx Outdated
count?: number
} & SxProp

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

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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.

@maximedegrevemaximedegreve left a comment

Copy link
Copy Markdown
Contributor

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:

<Boxsx={{display: ['block','block','none']}}><AvatarStacksize={26}/></Box><Boxsx={{display: ['none','none','block']}}><AvatarStacksize={20}/></Box>

Instead of:

<AvatarStacksize={[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.


export type AvatarStackProps = {
alignRight?: boolean
disableExpand?: boolean

@siddharthkpsiddharthkpJul 3, 2023

Copy link
Copy Markdown
Member

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/><AvatarStackexpand={false}/>

Copy link
Copy Markdown
ContributorAuthor

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} />

@siddharthkpsiddharthkpJul 6, 2023

Copy link
Copy Markdown
Member

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/>=<AvatarStackexpand/>=<AvatarStackexpand={true}/>// disabling default: <AvatarStackexpand={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-actionsBot temporarily deployed to storybook-preview-3466 July 5, 2023 23:03 Inactive
@mperrotti

Copy link
Copy Markdown
ContributorAuthor

@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-actionsBot temporarily deployed to storybook-preview-3466 July 6, 2023 02:34 Inactive
@maximedegreve

Copy link
Copy Markdown
Contributor

@mperrotti Oh no!

@mperrotti

Copy link
Copy Markdown
ContributorAuthor

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

@mperrotti
mperrotti temporarily deployed to github-pages July 6, 2023 20:41 — with GitHub Actions Inactive
@github-actions
github-actionsBot temporarily deployed to storybook-preview-3466 July 6, 2023 20:41 Inactive
@mperrottimperrotti added the update snapshots 🤖 Command that updates VRT snapshots on the pull request label Jul 6, 2023
@github-actionsgithub-actionsBot removed the update snapshots 🤖 Command that updates VRT snapshots on the pull request label Jul 6, 2023
@primer
primerBot temporarily deployed to github-pages July 6, 2023 21:13 Inactive
@github-actions
github-actionsBot temporarily deployed to storybook-preview-3466 July 6, 2023 21:14 Inactive
@maximedegreve

Copy link
Copy Markdown
Contributor

LGTM 🚀💪

@dusave

dusave commented Jul 6, 2023

Copy link
Copy Markdown
Contributor

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.

@broccolinisoupbroccolinisoup left a comment

Copy link
Copy Markdown
Member

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.

🚀 🚀 🚀

Comment threadsrc/Avatar/Avatar.tsx Outdated
) {
return <StyledAvatar ref={ref} alt={alt} size={size} square={square} {...rest} />
const avatarSx = isResponsiveValue(size)
? merge(

Copy link
Copy Markdown
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

constavatarSx=isResponsiveValue(size)
? getBreakpointDeclarations(size,'--avatar-size'askeyofReact.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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

@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
Copy Markdown
ContributorAuthor

@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-actionsBot temporarily deployed to storybook-preview-3466 July 7, 2023 15:34 Inactive
@github-actions
github-actionsBottemporarily deployed to storybook-preview-3466 July 7, 2023 15:55 Inactive
@mperrotti
mperrotti added this pull request to the merge queueJul 7, 2023
Merged via the queue into main with commit 11b54acJul 7, 2023
@mperrotti
mperrotti deleted the mp/avatarstack-disable-expand branch July 7, 2023 16:13
This was referenced Jul 7, 2023
Sign up for freeto 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

@mperrotti@maximedegreve@dusave@broccolinisoup@siddharthkp