-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathindex.tsx
More file actions
83 lines (73 loc) · 2.06 KB
/
index.tsx
File metadata and controls
83 lines (73 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use client';
import classNames from 'classnames';
import type { FC } from 'react';
import { useState, useMemo } from 'react';
import type { AvatarProps } from '#ui/Common/AvatarGroup/Avatar';
import Avatar from '#ui/Common/AvatarGroup/Avatar';
import avatarstyles from '#ui/Common/AvatarGroup/Avatar/index.module.css';
import AvatarOverlay from '#ui/Common/AvatarGroup/Overlay';
import Tooltip from '#ui/Common/Tooltip';
import type { LinkLike } from '#ui/types';
import styles from './index.module.css';
type AvatarGroupProps = {
avatars: Array<AvatarProps>;
limit?: number;
isExpandable?: boolean;
size?: AvatarProps['size'];
container?: HTMLElement;
as?: LinkLike;
};
const AvatarGroup: FC<AvatarGroupProps> = ({
avatars,
limit = 10,
isExpandable = true,
size = 'small',
container,
as,
}) => {
const [showMore, setShowMore] = useState(false);
const renderAvatars = useMemo(
() => avatars.slice(0, showMore ? avatars.length : limit),
[avatars, limit, showMore]
);
const handleShowMoreClick = isExpandable
? () => setShowMore(prev => !prev)
: undefined;
return (
<div className={classNames(styles.avatarGroup, styles[size])}>
{renderAvatars.map(avatar => (
<Tooltip
key={avatar.nickname}
asChild
container={container}
content={<AvatarOverlay {...avatar} as={as} />}
>
<Avatar
{...avatar}
size={size}
className={classNames({
'cursor-pointer': avatar.url,
'pointer-events-none': !avatar.url,
})}
as={as}
/>
</Tooltip>
))}
{avatars.length > limit && (
<span
onClick={handleShowMoreClick}
className={classNames(
avatarstyles.avatar,
avatarstyles[size],
'cursor-pointer'
)}
>
<span className={avatarstyles.item}>
{`${showMore ? '-' : '+'}${avatars.length - limit}`}
</span>
</span>
)}
</div>
);
};
export default AvatarGroup;