import type { AvatarSize } from '@langgenius/dify-ui/avatar' import type { FC } from 'react' import { AvatarFallback, AvatarImage, AvatarRoot } from '@langgenius/dify-ui/avatar' import { useAtomValue } from 'jotai' import { memo } from 'react' import { getUserColor } from '@/app/components/workflow/collaboration/utils/user-color' import { userProfileIdAtom } from '@/context/account-state' type User = { id: string name: string avatar_url?: string | null } type UserAvatarListProps = { users: User[] maxVisible?: number size?: AvatarSize className?: string showCount?: boolean } const avatarSizeToPx: Record = { xxs: 16, xs: 20, sm: 24, md: 32, lg: 36, xl: 40, '2xl': 48, '3xl': 64, } export const UserAvatarList: FC = memo( ({ users, maxVisible = 3, size = 'sm', className = '', showCount = true }) => { const currentUserId = useAtomValue(userProfileIdAtom) if (!users.length) return null const shouldShowCount = showCount && users.length > maxVisible const actualMaxVisible = shouldShowCount ? Math.max(1, maxVisible - 1) : maxVisible const visibleUsers = users.slice(0, actualMaxVisible) const remainingCount = users.length - actualMaxVisible return (
{visibleUsers.map((user, index) => { const isCurrentUser = user.id === currentUserId const userColor = isCurrentUser ? undefined : getUserColor(user.id) return (
{user.avatar_url && } {user.name?.[0]?.toLocaleUpperCase()}
) })} {shouldShowCount && remainingCount > 0 && (
+{remainingCount}
)}
) }, ) UserAvatarList.displayName = 'UserAvatarList'