-
Notifications
You must be signed in to change notification settings - Fork 535
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
Conversation
🦋 Changeset detectedLatest commit: 356bf65 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
size-limit report 📦
|
There was a problem hiding this 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.
src/AvatarStack/AvatarStack.tsx
Outdated
|
||
type StyledAvatarStackWrapperProps = { | ||
count?: number | ||
} & SxProp | ||
|
||
const findSmallestNumber = (numbers: number[]): number => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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} />
There was a problem hiding this comment.
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} />
There was a problem hiding this comment.
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
@broccolinisoup and @maximedegreve - I have your suggestions implemented. This should be merge-able once I:
|
@mperrotti Oh no! |
Haha thanks for sharing that @maximedegreve - I'll be fixing that while I make my other changes today. |
LGTM 🚀💪 |
Broader question, not a blocker for this PR: Are we adding any sort of |
There was a problem hiding this 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.
🚀 🚀 🚀
src/Avatar/Avatar.tsx
Outdated
ref, | ||
) { | ||
return <StyledAvatar ref={ref} alt={alt} size={size} square={square} {...rest} /> | ||
const avatarSx = isResponsiveValue(size) | ||
? merge( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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!
We do use |
@dusave - I checked with a11y, and it looks like this is safe to keep enabled even when the user prefers reduced motion. |
…ct into mp/avatarstack-disable-expand
size
prop toAvatarStack
size
prop to theAvatar
s that are direct children ofAvatarStack
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
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.