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