Skip to content
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

refactor: make avatar group more customizable #7989

Merged
merged 3 commits into from
Aug 27, 2024
Merged
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
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
Loading