2022-08-31 02:35:06 -07:00
|
|
|
import classNames from 'clsx';
|
2022-03-21 11:09:01 -07:00
|
|
|
import * as React from 'react';
|
|
|
|
|
2022-11-15 08:00:49 -08:00
|
|
|
import StillImage from 'soapbox/components/still-image';
|
2022-03-21 11:09:01 -07:00
|
|
|
|
|
|
|
const AVATAR_SIZE = 42;
|
|
|
|
|
|
|
|
interface IAvatar {
|
2022-04-30 21:39:58 -07:00
|
|
|
/** URL to the avatar image. */
|
2022-03-21 11:09:01 -07:00
|
|
|
src: string,
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Width and height of the avatar in pixels. */
|
2022-03-21 11:09:01 -07:00
|
|
|
size?: number,
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Extra class names for the div surrounding the avatar image. */
|
2022-03-21 11:09:01 -07:00
|
|
|
className?: string,
|
|
|
|
}
|
|
|
|
|
2022-04-30 21:39:58 -07:00
|
|
|
/** Round profile avatar for accounts. */
|
2022-03-21 11:09:01 -07:00
|
|
|
const Avatar = (props: IAvatar) => {
|
|
|
|
const { src, size = AVATAR_SIZE, className } = props;
|
|
|
|
|
|
|
|
const style: React.CSSProperties = React.useMemo(() => ({
|
|
|
|
width: size,
|
|
|
|
height: size,
|
|
|
|
}), [size]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StillImage
|
2022-05-07 10:58:12 -07:00
|
|
|
className={classNames('rounded-full overflow-hidden', className)}
|
2022-03-21 11:09:01 -07:00
|
|
|
style={style}
|
|
|
|
src={src}
|
|
|
|
alt='Avatar'
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export { Avatar as default, AVATAR_SIZE };
|