Feat: Add AvatarGroup component. #3221 (#5858)

### What problem does this PR solve?
Feat: Add AvatarGroup component. #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu 2025-03-10 19:03:48 +08:00 committed by GitHub
parent bf0d516e49
commit df11fe75d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 1 deletions

View File

@ -48,3 +48,49 @@ const AvatarFallback = React.forwardRef<
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName;
export { Avatar, AvatarFallback, AvatarImage };
type AvatarProps = React.ComponentProps<typeof Avatar>;
interface AvatarGroupProps extends React.ComponentProps<'div'> {
children: React.ReactElement<AvatarProps>[];
max?: number;
}
export const AvatarGroup = ({
children,
max,
className,
...props
}: AvatarGroupProps) => {
const totalAvatars = React.Children.count(children);
const displayedAvatars = React.Children.toArray(children)
.slice(0, max)
.reverse();
const remainingAvatars = max ? Math.max(totalAvatars - max, 1) : 0;
return (
<div
className={cn('flex items-center flex-row-reverse', className)}
{...props}
>
{remainingAvatars > 0 && (
<Avatar className="-ml-2 hover:z-10 relative ring-2 ring-background">
<AvatarFallback className="bg-muted-foreground text-white">
+{remainingAvatars}
</AvatarFallback>
</Avatar>
)}
{displayedAvatars.map((avatar, index) => {
if (!React.isValidElement(avatar)) return null;
return (
<div key={index} className="-ml-2 hover:z-10 relative">
{React.cloneElement(avatar as React.ReactElement<AvatarProps>, {
className: 'ring-2 ring-background',
})}
</div>
);
})}
</div>
);
};

View File

@ -69,7 +69,7 @@ interface Es {
}
export interface ITenantUser {
avatar: null;
avatar: string;
delta_seconds: number;
email: string;
is_active: string;