Skip to content

Evenly space AvatarStack #5911

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 7 additions & 33 deletions packages/react/src/AvatarStack/AvatarStack.module.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/* stylelint-disable selector-max-specificity */
.AvatarStack {
--avatar-border-width: 1px;
--overlap-size: calc(var(--avatar-stack-size) * 0.55);
--overlap-size-avatar-three-plus: calc(var(--avatar-stack-size) * 0.85);
--overlap-size: calc(var(--avatar-stack-size) * 0.5);
--mask-size: calc(100% + (var(--avatar-border-width) * 2));
--mask-start: -1;
--opacity-step: 15%;

position: relative;
display: flex;
Expand Down Expand Up @@ -47,26 +45,18 @@
/*
MIN-WIDTH CALC FORMULA EXPLAINED:
avatar size ➡️ var(--avatar-stack-size)
plus the visible part of the 2nd avatar ➡️ var(--avatar-stack-size) - var(--overlap-size)
plus the visible part of the 3rd avatar ➡️ var(--avatar-stack-size) - var(--overlap-size-avatar-three-plus)
plus the visible part of the 2nd and 3rd avatars ➡️ (var(--avatar-stack-size) - var(--overlap-size)) * 2
*/
min-width: calc(
var(--avatar-stack-size) + (var(--avatar-stack-size) - var(--overlap-size)) +
(var(--avatar-stack-size) - var(--overlap-size-avatar-three-plus))
);
min-width: calc(var(--avatar-stack-size) + ((var(--avatar-stack-size) - var(--overlap-size)) * 2));
}

&:where([data-avatar-count='3+']) {
/*
MIN-WIDTH CALC FORMULA EXPLAINED:
avatar size ➡️ var(--avatar-stack-size)
plus the visible part of the 2nd avatar ➡️ var(--avatar-stack-size) - var(--overlap-size)
plus the visible part of the 3rd AND 4th avatar ➡️ (var(--avatar-stack-size) - var(--overlap-size-avatar-three-plus)) * 2
Copy link
Author

Choose a reason for hiding this comment

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

Currently, the max amount of avatars that can be displayed at rest is 5 - shouldn't the min-width include the 5th avatar?

plus the visible part of the 2nd, 3rd, and 4th avatars ➡️ (var(--avatar-stack-size) - var(--overlap-size)) * 3
*/
min-width: calc(
var(--avatar-stack-size) + (var(--avatar-stack-size) - var(--overlap-size)) +
(var(--avatar-stack-size) - var(--overlap-size-avatar-three-plus)) * 2
);
min-width: calc(var(--avatar-stack-size) + ((var(--avatar-stack-size) - var(--overlap-size)) * 3));
}

&:where([data-align-right]) {
Expand Down Expand Up @@ -98,7 +88,8 @@
margin 0.2s ease-in-out,
opacity 0.2s ease-in-out,
mask-position 0.2s ease-in-out,
mask-size 0.2s ease-in-out;
mask-size 0.2s ease-in-out,
visibility 0.2s ease-in-out;

&:is(img) {
/* stylelint-disable-next-line primer/box-shadow */
Expand Down Expand Up @@ -134,23 +125,6 @@
padding: 0.1px;
}

&:nth-child(n + 3) {
--overlap-size: var(--overlap-size-avatar-three-plus);

/* stylelint-disable-next-line alpha-value-notation */
opacity: calc(100% - 2 * var(--opacity-step));
}

&:nth-child(n + 4) {
/* stylelint-disable-next-line alpha-value-notation */
opacity: calc(100% - 3 * var(--opacity-step));
}

&:nth-child(n + 5) {
/* stylelint-disable-next-line alpha-value-notation */
opacity: calc(100% - 4 * var(--opacity-step));
}

&:nth-child(n + 6) {
Copy link
Author

@joeoak joeoak Apr 9, 2025

Choose a reason for hiding this comment

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

Maybe this can be variable? Consumers of AvatarStack can decide on the max amount of avatars to show at rest 🤔

visibility: hidden;
opacity: 0;
Expand Down
36 changes: 7 additions & 29 deletions packages/react/src/AvatarStack/AvatarStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ const AvatarStackWrapper = toggleStyledComponent(
'span',
styled.span<StyledAvatarStackWrapperProps>`
--avatar-border-width: 1px;
--overlap-size: calc(var(--avatar-stack-size) * 0.55);
--overlap-size-avatar-three-plus: calc(var(--avatar-stack-size) * 0.85);
--overlap-size: calc(var(--avatar-stack-size) * 0.5);
--mask-size: calc(100% + (var(--avatar-border-width) * 2));
--mask-start: -1;
--opacity-step: 15%;

display: flex;
position: relative;
Expand All @@ -60,7 +58,8 @@ const AvatarStackWrapper = toggleStyledComponent(
margin 0.2s ease-in-out,
opacity 0.2s ease-in-out,
mask-position 0.2s ease-in-out,
mask-size 0.2s ease-in-out;
mask-size 0.2s ease-in-out,
visibility 0.2s ease-in-out;

&:is(img) {
box-shadow: 0 0 0 var(--avatar-border-width)
Expand Down Expand Up @@ -91,19 +90,6 @@ const AvatarStackWrapper = toggleStyledComponent(
padding: 0.1px;
}

&:nth-child(n + 3) {
--overlap-size: var(--overlap-size-avatar-three-plus);
opacity: calc(100% - 2 * var(--opacity-step));
}

&:nth-child(n + 4) {
opacity: calc(100% - 3 * var(--opacity-step));
}

&:nth-child(n + 5) {
opacity: calc(100% - 4 * var(--opacity-step));
}

&:nth-child(n + 6) {
opacity: 0;
visibility: hidden;
Expand All @@ -120,23 +106,15 @@ const AvatarStackWrapper = toggleStyledComponent(
&.pc-AvatarStack--three {
// MIN-WIDTH CALC FORMULA EXPLAINED:
// avatar size ➡️ var(--avatar-stack-size)
// plus the visible part of the 2nd avatar ➡️ var(--avatar-stack-size) - var(--overlap-size)
// plus the visible part of the 3rd avatar ➡️ var(--avatar-stack-size) - var(--overlap-size-avatar-three-plus)
min-width: calc(
var(--avatar-stack-size) + (var(--avatar-stack-size) - var(--overlap-size)) +
(var(--avatar-stack-size) - var(--overlap-size-avatar-three-plus))
);
// plus the visible part of the 2nd and 3rd avatars ➡️ (var(--avatar-stack-size) - var(--overlap-size)) * 2
min-width: calc(var(--avatar-stack-size) + ((var(--avatar-stack-size) - var(--overlap-size)) * 2));
}

&.pc-AvatarStack--three-plus {
// MIN-WIDTH CALC FORMULA EXPLAINED:
// avatar size ➡️ var(--avatar-stack-size)
// plus the visible part of the 2nd avatar ➡️ var(--avatar-stack-size) - var(--overlap-size)
// plus the visible part of the 3rd AND 4th avatar ➡️ (var(--avatar-stack-size) - var(--overlap-size-avatar-three-plus)) * 2
min-width: calc(
var(--avatar-stack-size) + (var(--avatar-stack-size) - var(--overlap-size)) +
(var(--avatar-stack-size) - var(--overlap-size-avatar-three-plus)) * 2
);
// plus the visible part of the 2nd, 3rd, and 4th avatars ➡️ (var(--avatar-stack-size) - var(--overlap-size)) * 3
min-width: calc(var(--avatar-stack-size) + ((var(--avatar-stack-size) - var(--overlap-size)) * 3));
}

&.pc-AvatarStack--right {
Expand Down
Loading