2022-12-10 12:14:48 +03:00
|
|
|
import './avatar.css';
|
|
|
|
|
2023-03-13 05:10:21 +03:00
|
|
|
import { useRef } from 'preact/hooks';
|
|
|
|
|
2022-12-10 12:14:48 +03:00
|
|
|
const SIZES = {
|
|
|
|
s: 16,
|
|
|
|
m: 20,
|
|
|
|
l: 24,
|
|
|
|
xl: 32,
|
|
|
|
xxl: 50,
|
2022-12-17 19:38:19 +03:00
|
|
|
xxxl: 64,
|
2022-12-10 12:14:48 +03:00
|
|
|
};
|
|
|
|
|
2023-01-21 19:37:46 +03:00
|
|
|
function Avatar({ url, size, alt = '', ...props }) {
|
2022-12-10 12:14:48 +03:00
|
|
|
size = SIZES[size] || size || SIZES.m;
|
2023-03-13 05:10:21 +03:00
|
|
|
const avatarRef = useRef();
|
2022-12-10 12:14:48 +03:00
|
|
|
return (
|
|
|
|
<span
|
2023-03-13 05:10:21 +03:00
|
|
|
ref={avatarRef}
|
2022-12-10 12:14:48 +03:00
|
|
|
class="avatar"
|
|
|
|
style={{
|
|
|
|
width: size,
|
|
|
|
height: size,
|
|
|
|
}}
|
2022-12-14 17:46:50 +03:00
|
|
|
title={alt}
|
2023-01-21 19:37:46 +03:00
|
|
|
{...props}
|
2022-12-10 12:14:48 +03:00
|
|
|
>
|
|
|
|
{!!url && (
|
2023-03-13 05:10:21 +03:00
|
|
|
<img
|
|
|
|
src={url}
|
|
|
|
width={size}
|
|
|
|
height={size}
|
|
|
|
alt={alt}
|
|
|
|
loading="lazy"
|
|
|
|
onLoad={(e) => {
|
|
|
|
avatarRef.current.classList.add('loaded');
|
|
|
|
}}
|
|
|
|
/>
|
2022-12-10 12:14:48 +03:00
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
);
|
2022-12-16 08:27:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Avatar;
|