diff options
author | Claire <claire.github-309c@sitedethib.com> | 2023-04-04 12:01:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-04 12:01:52 +0200 |
commit | af01ab7efebab356e73b498afe4258ae7515cc6a (patch) | |
tree | 798f5cde568987b7641543eb3972f355bae9170b /app/javascript/mastodon/components/avatar.tsx | |
parent | 8192b0da7cd1fac38a68eab6746fc7ec74328a77 (diff) | |
parent | d29cf8a044f6c0d004649223e018d240983e8437 (diff) |
Merge pull request #2159 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/javascript/mastodon/components/avatar.tsx')
-rw-r--r-- | app/javascript/mastodon/components/avatar.tsx | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/app/javascript/mastodon/components/avatar.tsx b/app/javascript/mastodon/components/avatar.tsx new file mode 100644 index 000000000..e64a8af74 --- /dev/null +++ b/app/javascript/mastodon/components/avatar.tsx @@ -0,0 +1,49 @@ +import * as React from 'react'; +import classNames from 'classnames'; +import { autoPlayGif } from '../initial_state'; +import { useHovering } from '../../hooks/useHovering'; +import type { Account } from '../../types/resources'; + +type Props = { + account: Account; + size: number; + style?: React.CSSProperties; + inline?: boolean; + animate?: boolean; +}; + +export const Avatar: React.FC<Props> = ({ + account, + animate = autoPlayGif, + size = 20, + inline = false, + style: styleFromParent, +}) => { + const { hovering, handleMouseEnter, handleMouseLeave } = useHovering(animate); + + const style = { + ...styleFromParent, + width: `${size}px`, + height: `${size}px`, + }; + + const src = + hovering || animate + ? account?.get('avatar') + : account?.get('avatar_static'); + + return ( + <div + className={classNames('account__avatar', { + 'account__avatar-inline': inline, + })} + onMouseEnter={handleMouseEnter} + onMouseLeave={handleMouseLeave} + style={style} + > + {src && <img src={src} alt={account?.get('acct')} />} + </div> + ); +}; + +export default Avatar; |