element-call/src/Facepile.jsx

39 lines
1.1 KiB
React
Raw Normal View History

2021-10-04 22:37:23 +00:00
import React from "react";
import styles from "./Facepile.module.css";
2021-11-10 23:44:08 +00:00
import classNames from "classnames";
2021-12-08 01:59:55 +00:00
import { Avatar } from "./Avatar";
2022-01-06 01:19:03 +00:00
import { getAvatarUrl } from "./matrix-utils";
2021-10-04 22:37:23 +00:00
2021-12-20 17:12:28 +00:00
export function Facepile({ className, client, participants, ...rest }) {
2021-10-04 22:37:23 +00:00
return (
<div
2021-12-08 01:59:55 +00:00
className={classNames(styles.facepile, className)}
2021-10-04 22:37:23 +00:00
title={participants.map((member) => member.name).join(", ")}
2021-12-08 01:59:55 +00:00
{...rest}
2021-10-04 22:37:23 +00:00
>
2021-12-20 17:12:28 +00:00
{participants.slice(0, 3).map((member, i) => {
const avatarUrl = member.user?.avatarUrl;
return (
<Avatar
key={member.userId}
size="xs"
src={avatarUrl && getAvatarUrl(client, avatarUrl, 22)}
fallback={member.name.slice(0, 1).toUpperCase()}
className={styles.avatar}
style={{ left: i * 22 }}
/>
);
})}
2021-11-10 23:44:08 +00:00
{participants.length > 3 && (
2021-12-08 01:59:55 +00:00
<Avatar
2021-11-10 23:44:08 +00:00
key="additional"
2021-12-17 19:01:40 +00:00
size="xs"
2021-12-08 01:59:55 +00:00
fallback={`+${participants.length - 3}`}
className={styles.avatar}
style={{ left: 3 * 22 }}
/>
2021-11-10 23:44:08 +00:00
)}
2021-10-04 22:37:23 +00:00
</div>
);
}