2022-07-23 00:39:50 +00:00
|
|
|
import classNames from "@calcom/lib/classNames";
|
|
|
|
|
2022-11-04 15:40:46 +00:00
|
|
|
import { Avatar } from "./Avatar";
|
2022-07-23 00:39:50 +00:00
|
|
|
|
|
|
|
export type AvatarGroupProps = {
|
|
|
|
size: "sm" | "lg";
|
|
|
|
items: {
|
|
|
|
image: string;
|
|
|
|
title?: string;
|
|
|
|
alt?: string;
|
2023-01-21 11:41:49 +00:00
|
|
|
href?: string;
|
2022-07-23 00:39:50 +00:00
|
|
|
}[];
|
|
|
|
className?: string;
|
|
|
|
accepted?: boolean;
|
2023-01-11 15:00:46 +00:00
|
|
|
truncateAfter?: number;
|
2022-07-23 00:39:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const AvatarGroup = function AvatarGroup(props: AvatarGroupProps) {
|
|
|
|
const LENGTH = props.items.length;
|
2023-01-11 15:00:46 +00:00
|
|
|
const truncateAfter = props.truncateAfter || 4;
|
2023-02-11 16:25:36 +00:00
|
|
|
/**
|
|
|
|
* First, filter all the avatars object that have image
|
|
|
|
* Then, slice it until before `truncateAfter` index
|
|
|
|
*/
|
|
|
|
const displayedAvatars = props.items.filter((avatar) => avatar.image).slice(0, truncateAfter);
|
|
|
|
const numTruncatedAvatars = LENGTH - displayedAvatars.length;
|
2022-07-23 00:39:50 +00:00
|
|
|
|
|
|
|
return (
|
2023-01-20 14:19:12 +00:00
|
|
|
<ul className={classNames("flex items-center", props.className)}>
|
2023-02-11 16:25:36 +00:00
|
|
|
{displayedAvatars.map((item, idx) => (
|
|
|
|
<li key={idx} className="-mr-[4px] inline-block">
|
|
|
|
<Avatar
|
|
|
|
className="border-gray-200"
|
|
|
|
imageSrc={item.image}
|
|
|
|
title={item.title}
|
|
|
|
alt={item.alt || ""}
|
|
|
|
accepted={props.accepted}
|
|
|
|
size={props.size}
|
|
|
|
href={item.href}
|
|
|
|
/>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
{numTruncatedAvatars > 0 && (
|
|
|
|
<li
|
|
|
|
className={classNames(
|
|
|
|
"bg-darkgray-300 relative -mr-[4px] mb-1 inline-flex justify-center overflow-hidden rounded-full",
|
|
|
|
props.size === "sm" ? "min-w-6 h-6" : "min-w-16 h-16"
|
|
|
|
)}>
|
|
|
|
<span
|
|
|
|
className={classNames(
|
|
|
|
"m-auto px-1 text-center text-white",
|
|
|
|
props.size === "sm" ? "text-[12px]" : "text-2xl"
|
|
|
|
)}>
|
|
|
|
+{numTruncatedAvatars}
|
|
|
|
</span>
|
|
|
|
</li>
|
|
|
|
)}
|
2022-07-23 00:39:50 +00:00
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
};
|