1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

refactor: make avatar group more customizable (#7989)

This commit is contained in:
Tymoteusz Czech 2024-08-27 14:37:45 +02:00 committed by GitHub
parent 25617f7a24
commit 742504793c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 21 deletions

View File

@ -14,21 +14,21 @@ 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;
@ -36,14 +36,12 @@ type AvatarGroupProps = {
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;

View File

@ -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',
@ -50,7 +56,7 @@ const CollaboratorList: FC<{ collaborators: Collaborator[] }> = ({
<StyledAvatarGroup
users={collaborators}
avatarLimit={6}
AvatarComponent={StyledAvatar}
AvatarComponent={StyledAvatarComponent}
/>
</SectionContainer>
);