-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Replace dcl-gatsby Avatar component (#1041)
* refactor: dcl-gatsby Avatar replaced * loading & extra props removed
- Loading branch information
Showing
12 changed files
with
222 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
@keyframes Avatar--loading-animation { | ||
to { | ||
background-position-x: -200%; | ||
} | ||
} | ||
|
||
.Avatar { | ||
height: auto; | ||
border-radius: 100%; | ||
background-color: #7a7a7a; | ||
vertical-align: middle; | ||
max-width: 256px; | ||
margin: 0; | ||
} | ||
|
||
.Avatar.Avatar--loading { | ||
opacity: 0.6; | ||
background-size: 200% 100%; | ||
animation: 1.5s Avatar--loading-animation linear infinite; | ||
background-image: linear-gradient(110deg, #7a7a7a 18%, #949494 28%, #7a7a7a 43%); | ||
} | ||
|
||
.Avatar.Avatar--0, | ||
.Avatar.Avatar--1 { | ||
background-color: #4e79a7; | ||
} | ||
|
||
.Avatar.Avatar--0.Avatar--loading, | ||
.Avatar.Avatar--1.Avatar--loading { | ||
background-image: linear-gradient(110deg, #4e79a7 18%, #6e93bb 28%, #4e79a7 43%); | ||
} | ||
|
||
.Avatar.Avatar--2, | ||
.Avatar.Avatar--3 { | ||
background-color: #f28e2c; | ||
} | ||
|
||
.Avatar.Avatar--2.Avatar--loading, | ||
.Avatar.Avatar--3.Avatar--loading { | ||
background-image: linear-gradient(110deg, #f28e2c 18%, #f4a456 28%, #f28e2c 43%); | ||
} | ||
|
||
.Avatar.Avatar--4, | ||
.Avatar.Avatar--5 { | ||
background-color: #e15759; | ||
} | ||
|
||
.Avatar.Avatar--4.Avatar--loading, | ||
.Avatar.Avatar--5.Avatar--loading { | ||
background-image: linear-gradient(110deg, #e15759 18%, #e6787a 28%, #e15759 43%); | ||
} | ||
|
||
.Avatar.Avatar--6, | ||
.Avatar.Avatar--7 { | ||
background-color: #76b7b2; | ||
} | ||
|
||
.Avatar.Avatar--6.Avatar--loading, | ||
.Avatar.Avatar--7.Avatar--loading { | ||
background-image: linear-gradient(110deg, #76b7b2 18%, #91c5c1 28%, #76b7b2 43%); | ||
} | ||
|
||
.Avatar.Avatar--8, | ||
.Avatar.Avatar--9 { | ||
background-color: #59a14f; | ||
} | ||
|
||
.Avatar.Avatar--8.Avatar--loading, | ||
.Avatar.Avatar--9.Avatar--loading { | ||
background-image: linear-gradient(110deg, #59a14f 18%, #77b76e 28%, #59a14f 43%); | ||
} | ||
|
||
.Avatar.Avatar--a, | ||
.Avatar.Avatar--b { | ||
background-color: #edc949; | ||
} | ||
|
||
.Avatar.Avatar--a.Avatar--loading, | ||
.Avatar.Avatar--b.Avatar--loading { | ||
background-image: linear-gradient(110deg, #edc949 18%, #f0d36d 28%, #edc949 43%); | ||
} | ||
|
||
.Avatar.Avatar--c, | ||
.Avatar.Avatar--d { | ||
background-color: #af7aa1; | ||
} | ||
|
||
.Avatar.Avatar--c.Avatar--loading, | ||
.Avatar.Avatar--d.Avatar--loading { | ||
background-image: linear-gradient(110deg, #af7aa1 18%, #bf94b3 28%, #af7aa1 43%); | ||
} | ||
|
||
.Avatar.Avatar--e, | ||
.Avatar.Avatar--f { | ||
background-color: #ff9da7; | ||
} | ||
|
||
.Avatar.Avatar--e.Avatar--loading, | ||
.Avatar.Avatar--f.Avatar--loading { | ||
background-image: linear-gradient(110deg, #ff9da7 18%, #feb0b8 28%, #ff9da7 43%); | ||
} | ||
|
||
.Avatar.Avatar--mini { | ||
width: 20px; | ||
} | ||
|
||
.Avatar.Avatar--tiny { | ||
width: 24px; | ||
} | ||
|
||
.Avatar.Avatar--small { | ||
width: 32px; | ||
} | ||
|
||
.Avatar, | ||
.Avatar.Avatar--medium { | ||
width: 44px; | ||
} | ||
|
||
.Avatar.Avatar--large { | ||
width: 52px; | ||
} | ||
|
||
.Avatar.Avatar--big { | ||
width: 66px; | ||
} | ||
|
||
.Avatar.Avatar--huge { | ||
width: 90px; | ||
} | ||
|
||
.Avatar.Avatar--massive { | ||
width: 122px; | ||
} | ||
|
||
.Avatar.Avatar--full { | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { useState } from 'react' | ||
|
||
import classNames from 'classnames' | ||
|
||
import useProfile from '../../hooks/useProfile' | ||
|
||
import './Avatar.css' | ||
|
||
export enum AvatarSize { | ||
Mini = 'mini', | ||
Tiny = 'tiny', | ||
Small = 'small', | ||
Medium = 'medium', | ||
Large = 'large', | ||
Big = 'big', | ||
Huge = 'huge', | ||
Massive = 'massive', | ||
Full = 'full', | ||
} | ||
|
||
const DEFAULT_AVATAR = 'https://decentraland.org/images/male.png' | ||
type Props = { | ||
size?: `${AvatarSize}` | ||
src?: string | ||
address?: string | ||
className?: string | ||
} | ||
|
||
export default function Avatar({ address, size, src, className }: Props) { | ||
const [failed, setFailed] = useState(false) | ||
|
||
const { profile, isLoadingProfile } = useProfile(address) | ||
|
||
const getTarget = () => { | ||
const avatar = profile?.avatar?.snapshots?.face256 || profile?.avatar?.snapshots?.face | ||
if (src) { | ||
return src | ||
} else if (failed || !avatar) { | ||
return DEFAULT_AVATAR | ||
} | ||
|
||
return avatar | ||
} | ||
|
||
return ( | ||
<img | ||
loading="lazy" | ||
src={getTarget()} | ||
onError={() => setFailed(true)} | ||
className={classNames( | ||
'Avatar', | ||
`Avatar--${size || AvatarSize.Mini}`, | ||
`Avatar--${((address || '')[2] || '').toLowerCase()}`, | ||
!src && isLoadingProfile && `Avatar--loading`, | ||
className | ||
)} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters