Add animated avatar placeholder (#270)

* Add animated avatar placeholder

* Fix imports
This commit is contained in:
Reckless_Satoshi 2022-10-06 18:35:32 +00:00 committed by Reckless_Satoshi
parent 01bcb03aff
commit 1352937fe6
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
6 changed files with 84 additions and 18 deletions

View File

@ -160,6 +160,7 @@ const BookTable = ({
nickname={params.row.maker_nick}
style={{ width: '3.215em', height: '3.215em' }}
smooth={true}
flipHorizontally={true}
orderType={params.row.type}
statusColor={statusBadgeColor(params.row.maker_status)}
tooltip={t(params.row.maker_status)}
@ -185,6 +186,7 @@ const BookTable = ({
<RobotAvatar
nickname={params.row.maker_nick}
smooth={true}
flipHorizontally={true}
style={{ width: '3.215em', height: '3.215em' }}
orderType={params.row.type}
statusColor={statusBadgeColor(params.row.maker_status)}

View File

@ -1,13 +1,15 @@
import React, { useEffect, useState } from 'react';
import SmoothImage from 'react-smooth-image';
import { Avatar, Badge, Tooltip } from '@mui/material';
import { Avatar, Badge, Tooltip, useTheme } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { SendReceiveIcon } from '../../Icons';
import { apiClient } from '../../../services/api';
import placeholder from './placeholder.json';
interface Props {
nickname: string;
smooth?: boolean;
flipHorizontally?: boolean;
style?: object;
imageStyle?: object;
statusColor?: 'primary' | 'secondary' | 'default' | 'error' | 'info' | 'success' | 'warning';
@ -23,13 +25,14 @@ const RobotAvatar: React.FC<Props> = ({
statusColor,
tooltip,
smooth = false,
flipHorizontally = false,
style = {},
imageStyle = {},
avatarClass = 'flippedSmallAvatar',
imageStyle = {},
onLoad = () => {},
}) => {
const { t } = useTranslation();
const theme = useTheme();
const [avatarSrc, setAvatarSrc] = useState<string>();
useEffect(() => {
@ -54,17 +57,29 @@ const RobotAvatar: React.FC<Props> = ({
const getAvatar = () => {
if (smooth) {
return (
<div style={style}>
<SmoothImage
src={avatarSrc}
imageStyles={{
borderRadius: '50%',
transform: 'scaleX(-1)',
border: '0.3px solid #555',
filter: 'dropShadow(0.5px 0.5px 0.5px #000000)',
...imageStyle,
}}
/>
<div
style={{
...style,
imageRendering: 'high-quality',
backgroundSize: '100%',
borderRadius: '50%',
transform: flipHorizontally ? 'scaleX(-1)' : '',
border: '0.3px solid #55555',
filter: 'dropShadow(0.5px 0.5px 0.5px #000000)',
backgroundImage: `url(data:${placeholder.image.mime};base64,${placeholder.image.data})`,
}}
>
<div className={theme.palette.mode === 'dark' ? 'loadingAvatarDark' : 'loadingAvatar'}>
<SmoothImage
src={avatarSrc}
imageStyles={{
borderRadius: '50%',
border: '0.3px solid #55555',
filter: 'dropShadow(0.5px 0.5px 0.5px #000000)',
...imageStyle,
}}
/>
</div>
</div>
);
} else {

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

File diff suppressed because one or more lines are too long

View File

@ -231,15 +231,15 @@ class UserGenPage extends Component {
<Grid item xs={12} align='center'>
<RobotAvatar
nickname={this.state.nickname}
style={{ maxWidth: 200 * fontSizeFactor, maxHeight: 200 * fontSizeFactor }}
smooth={true}
style={{ maxWidth: 203 * fontSizeFactor, maxHeight: 203 * fontSizeFactor }}
imageStyle={{
transform: '',
border: '2px solid #555',
filter: 'drop-shadow(1px 1px 1px #000000)',
height: `${195 * fontSizeFactor}px`,
width: `${200 * fontSizeFactor}px`,
height: `${201 * fontSizeFactor}px`,
width: `${201 * fontSizeFactor}px`,
}}
smooth={true}
tooltip={t('This is your trading avatar')}
/>
<br />

View File

@ -178,3 +178,46 @@ input[type='number'] {
width: 100%;
}
}
@keyframes animatedBackground {
from {
background-position: 0 0;
}
to {
background-position: 0 80px;
}
}
.loadingAvatar {
background-size: 100%;
border-radius: 50%;
border: 0.3px solid #555;
filter: dropShadow(0.5px 0.5px 0.5px #000000);
background-image: linear-gradient(
0deg,
#ffffffab 0%,
#cfcfcfc2 40%,
#a3a3a3cc 60%,
#ffffffab 100%
);
background-position: 0px 0px;
background-repeat: repeat;
animation: animatedBackground 5s linear infinite;
}
.loadingAvatarDark {
background-size: 100%;
border-radius: 50%;
border: 0.3px solid #555;
filter: dropShadow(0.5px 0.5px 0.5px #000000);
background-image: linear-gradient(
0deg,
#6e6e6ec2 0%,
#14141479 40%,
#14141479 60%,
#6e6e6ec2 100%
);
background-position: 0px 0px;
background-repeat: repeat;
animation: animatedBackground 5s linear infinite;
}