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