maruric 306e133651
fix: garbled text displayed on avatars (#6575)
Co-authored-by: dwelle <luzar.david@gmail.com>
2023-05-13 19:49:09 +02:00

35 lines
859 B
TypeScript

import "./Avatar.scss";
import React, { useState } from "react";
import { getNameInitial } from "../clients";
type AvatarProps = {
onClick: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
color: string;
border: string;
name: string;
src?: string;
};
export const Avatar = ({ color, onClick, name, src }: AvatarProps) => {
const shortName = getNameInitial(name);
const [error, setError] = useState(false);
const loadImg = !error && src;
const style = loadImg ? undefined : { background: color };
return (
<div className="Avatar" style={style} onClick={onClick}>
{loadImg ? (
<img
className="Avatar-img"
src={src}
alt={shortName}
referrerPolicy="no-referrer"
onError={() => setError(true)}
/>
) : (
shortName
)}
</div>
);
};