Skip to content

Commit

Permalink
refactor: make avatar group more customizable (#7989)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymek authored Aug 27, 2024
1 parent 25617f7 commit 7425047
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
32 changes: 15 additions & 17 deletions frontend/src/component/common/AvatarGroup/AvatarGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,34 @@ const StyledAvatars = styled('div')(({ theme }) => ({
justifyContent: 'start',
}));

const StyledAvatar = (component: typeof UserAvatar) =>
styled(component)(({ theme }) => ({
outline: `${theme.spacing(0.25)} solid ${theme.palette.background.paper}`,
margin: 0,
marginLeft: theme.spacing(-1),
'&:hover': {
outlineColor: theme.palette.primary.main,
},
}));
export const AvatarComponent = styled(UserAvatar)(({ theme }) => ({
outline: `${theme.spacing(0.25)} solid ${theme.palette.background.paper}`,
margin: 0,
marginLeft: theme.spacing(-1),
'&:hover': {
outlineColor: theme.palette.primary.main,
},
}));

type User = {
name: string;
description?: string;
imageUrl?: string;
};

type AvatarGroupProps = {
users: User[];
avatarLimit?: number;
AvatarComponent?: typeof UserAvatar;
className?: string;
};

export const AvatarGroup = ({
AvatarComponent,
...props
}: AvatarGroupProps) => {
const Avatar = StyledAvatar(AvatarComponent ?? UserAvatar);

return <AvatarGroupInner AvatarComponent={Avatar} {...props} />;
};
export const AvatarGroup = ({ ...props }: AvatarGroupProps) => (
<AvatarGroupInner
AvatarComponent={props.AvatarComponent ?? AvatarComponent}
{...props}
/>
);

type AvatarGroupInnerProps = Omit<AvatarGroupProps, 'AvatarComponent'> & {
AvatarComponent: typeof UserAvatar;
Expand Down
14 changes: 10 additions & 4 deletions frontend/src/component/feature/FeatureView/Collaborators.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { styled } from '@mui/material';
import { AvatarGroup } from 'component/common/AvatarGroup/AvatarGroup';
import { UserAvatar } from 'component/common/UserAvatar/UserAvatar';
import {
AvatarComponent,
AvatarGroup,
} from 'component/common/AvatarGroup/AvatarGroup';
import type { Collaborator } from 'interfaces/featureToggle';
import type { FC } from 'react';
import { Link } from 'react-router-dom';

const StyledAvatar = styled(UserAvatar)(({ theme }) => ({
const StyledAvatarComponent = styled(AvatarComponent)(({ theme }) => ({
width: theme.spacing(3),
height: theme.spacing(3),
}));

const StyledAvatar = styled(StyledAvatarComponent)(() => ({
marginLeft: 0,
}));

const SectionContainer = styled('div')(({ theme }) => ({
display: 'flex',
flexFlow: 'column',
Expand Down Expand Up @@ -50,7 +56,7 @@ const CollaboratorList: FC<{ collaborators: Collaborator[] }> = ({
<StyledAvatarGroup
users={collaborators}
avatarLimit={6}
AvatarComponent={StyledAvatar}
AvatarComponent={StyledAvatarComponent}
/>
</SectionContainer>
);
Expand Down

0 comments on commit 7425047

Please sign in to comment.