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
|
|
|
|
2022-04-28 00:19:58 +00:00
|
|
|
const overlapMap = {
|
|
|
|
xs: 2,
|
|
|
|
sm: 4,
|
|
|
|
md: 8,
|
|
|
|
};
|
|
|
|
|
|
|
|
const sizeMap = {
|
|
|
|
xs: 24,
|
|
|
|
sm: 32,
|
|
|
|
md: 36,
|
|
|
|
};
|
|
|
|
|
2022-04-27 23:47:23 +00:00
|
|
|
export function Facepile({
|
|
|
|
className,
|
|
|
|
client,
|
|
|
|
participants,
|
|
|
|
max,
|
|
|
|
size,
|
|
|
|
...rest
|
|
|
|
}) {
|
2022-04-28 00:19:58 +00:00
|
|
|
const _size = sizeMap[size];
|
|
|
|
const _overlap = overlapMap[size];
|
2022-04-27 23:47:23 +00:00
|
|
|
|
2021-10-04 22:37:23 +00:00
|
|
|
return (
|
|
|
|
<div
|
2022-04-28 00:19:58 +00:00
|
|
|
className={classNames(styles.facepile, styles[size], className)}
|
2021-10-04 22:37:23 +00:00
|
|
|
title={participants.map((member) => member.name).join(", ")}
|
2022-04-28 00:19:58 +00:00
|
|
|
style={{ width: participants.length * (_size - _overlap) + _overlap }}
|
2021-12-08 01:59:55 +00:00
|
|
|
{...rest}
|
2021-10-04 22:37:23 +00:00
|
|
|
>
|
2022-04-27 23:47:23 +00:00
|
|
|
{participants.slice(0, max).map((member, i) => {
|
2021-12-20 17:12:28 +00:00
|
|
|
const avatarUrl = member.user?.avatarUrl;
|
|
|
|
return (
|
|
|
|
<Avatar
|
|
|
|
key={member.userId}
|
2022-04-27 23:47:23 +00:00
|
|
|
size={size}
|
|
|
|
src={avatarUrl && getAvatarUrl(client, avatarUrl, _size)}
|
2021-12-20 17:12:28 +00:00
|
|
|
fallback={member.name.slice(0, 1).toUpperCase()}
|
|
|
|
className={styles.avatar}
|
2022-04-27 23:47:23 +00:00
|
|
|
style={{ left: i * (_size - _overlap) }}
|
2021-12-20 17:12:28 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
2022-04-27 23:47:23 +00:00
|
|
|
{participants.length > max && (
|
2021-12-08 01:59:55 +00:00
|
|
|
<Avatar
|
2021-11-10 23:44:08 +00:00
|
|
|
key="additional"
|
2022-04-27 23:47:23 +00:00
|
|
|
size={size}
|
|
|
|
fallback={`+${participants.length - max}`}
|
2021-12-08 01:59:55 +00:00
|
|
|
className={styles.avatar}
|
2022-04-27 23:47:23 +00:00
|
|
|
style={{ left: max * (_size - _overlap) }}
|
2021-12-08 01:59:55 +00:00
|
|
|
/>
|
2021-11-10 23:44:08 +00:00
|
|
|
)}
|
2021-10-04 22:37:23 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2022-04-27 23:47:23 +00:00
|
|
|
|
|
|
|
Facepile.defaultProps = {
|
|
|
|
max: 3,
|
|
|
|
size: "xs",
|
|
|
|
};
|