2023-04-26 22:30:41 +03:00
|
|
|
import * as React from 'react';
|
2023-05-10 13:59:29 +03:00
|
|
|
|
2023-04-26 22:30:41 +03:00
|
|
|
import classNames from 'classnames';
|
2023-05-10 13:59:29 +03:00
|
|
|
|
2023-05-09 22:30:10 +03:00
|
|
|
import { useHovering } from 'flavours/glitch/hooks/useHovering';
|
2023-05-10 13:59:29 +03:00
|
|
|
import { autoPlayGif } from 'flavours/glitch/initial_state';
|
2023-05-08 22:32:26 +03:00
|
|
|
import type { Account } from 'flavours/glitch/types/resources';
|
2023-04-26 22:30:41 +03:00
|
|
|
|
2023-05-10 13:59:29 +03:00
|
|
|
interface Props {
|
2023-04-26 22:30:41 +03:00
|
|
|
account: Account | undefined;
|
|
|
|
className?: string;
|
|
|
|
size: number;
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
inline?: boolean;
|
2023-05-10 13:59:29 +03:00
|
|
|
}
|
2023-04-26 22:30:41 +03:00
|
|
|
|
|
|
|
export const Avatar: React.FC<Props> = ({
|
|
|
|
account,
|
|
|
|
className,
|
|
|
|
size = 20,
|
|
|
|
inline = false,
|
|
|
|
style: styleFromParent,
|
|
|
|
}) => {
|
2023-05-10 00:41:18 +03:00
|
|
|
const { hovering, handleMouseEnter, handleMouseLeave } =
|
|
|
|
useHovering(autoPlayGif);
|
2023-04-26 22:30:41 +03:00
|
|
|
|
|
|
|
const style = {
|
|
|
|
...styleFromParent,
|
|
|
|
width: `${size}px`,
|
|
|
|
height: `${size}px`,
|
|
|
|
backgroundSize: `${size}px ${size}px`,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (account) {
|
2023-05-10 00:41:18 +03:00
|
|
|
style.backgroundImage = `url(${account.get(
|
2023-07-13 14:58:47 +03:00
|
|
|
hovering ? 'avatar' : 'avatar_static',
|
2023-05-10 00:41:18 +03:00
|
|
|
)})`;
|
2023-04-26 22:30:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2023-05-10 00:41:18 +03:00
|
|
|
className={classNames(
|
|
|
|
'account__avatar',
|
|
|
|
{ 'account__avatar-inline': inline },
|
2023-07-13 14:58:47 +03:00
|
|
|
className,
|
2023-05-10 00:41:18 +03:00
|
|
|
)}
|
2023-04-26 22:30:41 +03:00
|
|
|
onMouseEnter={handleMouseEnter}
|
|
|
|
onMouseLeave={handleMouseLeave}
|
|
|
|
style={style}
|
|
|
|
data-avatar-of={account && `@${account.get('acct')}`}
|
|
|
|
role='img'
|
|
|
|
aria-label={account?.get('acct')}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|