1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-14 00:19:16 +01:00

fix: Avoid collaborators being smooshed together (#7741)

Fixes an issue where the collaborator component would be smooshed
together when you have too many collaborators and too many flag tab
items.

The primary things I have done are:
1. Limit the amount of collaborators we show to 6 instead of 8. I
believe the number 8 was arbitrary, so let's go with 6 for now.
2. Instead of using a fixed gap, use a separator element that grows up
to a certain limit. I've added a `Separator` component, which is an
empty div with flex-grow. It feels like you should be able to do that
with gap too, but I can't think of how right now.
3. Don't allow collaborator component text (or avatars) to wrap. We
don't have a lot of space in this header, so let's keep it tight.

Additionally, I've added the `className` prop to the AvatarGroup
component so that it can be styled externally. I also cleaned up some
naming that was left in while I was at it.

Before:

![image](https://github.com/user-attachments/assets/98525a23-c086-433a-8f60-3e281805409f)


After:

![image](https://github.com/user-attachments/assets/559f8975-9cbe-4260-ba5a-409a303375ed)
This commit is contained in:
Thomas Heartman 2024-08-05 10:33:10 +02:00 committed by GitHub
parent 3a00a6a5e6
commit 0284daf2ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 9 deletions

View File

@ -32,6 +32,7 @@ type AvatarGroupProps = {
users: User[]; users: User[];
avatarLimit?: number; avatarLimit?: number;
AvatarComponent?: typeof UserAvatar; AvatarComponent?: typeof UserAvatar;
className?: string;
}; };
export const AvatarGroup = ({ export const AvatarGroup = ({
@ -40,18 +41,19 @@ export const AvatarGroup = ({
}: AvatarGroupProps) => { }: AvatarGroupProps) => {
const Avatar = StyledAvatar(AvatarComponent ?? UserAvatar); const Avatar = StyledAvatar(AvatarComponent ?? UserAvatar);
return <GroupCardAvatarsInner AvatarComponent={Avatar} {...props} />; return <AvatarGroupInner AvatarComponent={Avatar} {...props} />;
}; };
type GroupCardAvatarsInnerProps = Omit<AvatarGroupProps, 'AvatarComponent'> & { type AvatarGroupInnerProps = Omit<AvatarGroupProps, 'AvatarComponent'> & {
AvatarComponent: typeof UserAvatar; AvatarComponent: typeof UserAvatar;
}; };
const GroupCardAvatarsInner = ({ const AvatarGroupInner = ({
users = [], users = [],
avatarLimit = 9, avatarLimit = 9,
AvatarComponent, AvatarComponent,
}: GroupCardAvatarsInnerProps) => { className,
}: AvatarGroupInnerProps) => {
const shownUsers = useMemo( const shownUsers = useMemo(
() => () =>
users users
@ -72,7 +74,7 @@ const GroupCardAvatarsInner = ({
); );
return ( return (
<StyledAvatars> <StyledAvatars className={className}>
{shownUsers.map((user) => ( {shownUsers.map((user) => (
<AvatarComponent key={objectId(user)} user={user} /> <AvatarComponent key={objectId(user)} user={user} />
))} ))}

View File

@ -16,6 +16,7 @@ const SectionContainer = styled('div')(({ theme }) => ({
gap: theme.spacing(0.5), gap: theme.spacing(0.5),
alignItems: 'flex-start', alignItems: 'flex-start',
height: 'min-content', height: 'min-content',
whiteSpace: 'nowrap',
})); }));
const LastModifiedByAvatarAndLink = styled('div')(({ theme }) => ({ const LastModifiedByAvatarAndLink = styled('div')(({ theme }) => ({
@ -36,15 +37,19 @@ const LastModifiedBy: FC<Collaborator> = ({ id, name, imageUrl }) => {
); );
}; };
const StyledAvatarGroup = styled(AvatarGroup)({
flexWrap: 'nowrap',
});
const CollaboratorList: FC<{ collaborators: Collaborator[] }> = ({ const CollaboratorList: FC<{ collaborators: Collaborator[] }> = ({
collaborators, collaborators,
}) => { }) => {
return ( return (
<SectionContainer> <SectionContainer>
<span className='description'>Collaborators</span> <span className='description'>Collaborators</span>
<AvatarGroup <StyledAvatarGroup
users={collaborators} users={collaborators}
avatarLimit={8} avatarLimit={6}
AvatarComponent={StyledAvatar} AvatarComponent={StyledAvatar}
/> />
</SectionContainer> </SectionContainer>
@ -54,18 +59,24 @@ const CollaboratorList: FC<{ collaborators: Collaborator[] }> = ({
const Container = styled('article')(({ theme }) => ({ const Container = styled('article')(({ theme }) => ({
display: 'flex', display: 'flex',
flexDirection: 'row', flexDirection: 'row',
gap: theme.spacing(10),
alignItems: 'center', alignItems: 'center',
justifyContent: 'space-between', justifyContent: 'right',
[theme.breakpoints.down('xl')]: { [theme.breakpoints.down('xl')]: {
display: 'none', display: 'none',
}, },
flex: 1,
})); }));
type Props = { type Props = {
collaborators: Collaborator[] | undefined; collaborators: Collaborator[] | undefined;
}; };
const Separator = styled('div')(({ theme }) => ({
maxWidth: theme.spacing(10),
minWidth: theme.spacing(2),
flexGrow: 1,
}));
export const Collaborators: FC<Props> = ({ collaborators }) => { export const Collaborators: FC<Props> = ({ collaborators }) => {
if (!collaborators || collaborators.length === 0) { if (!collaborators || collaborators.length === 0) {
return null; return null;
@ -76,6 +87,7 @@ export const Collaborators: FC<Props> = ({ collaborators }) => {
return ( return (
<Container> <Container>
<LastModifiedBy {...lastModifiedBy} /> <LastModifiedBy {...lastModifiedBy} />
<Separator />
<CollaboratorList collaborators={collaborators} /> <CollaboratorList collaborators={collaborators} />
</Container> </Container>
); );