Remove error handling from Avatar component
Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
parent
34bb5f9928
commit
f8f77075ec
1 changed files with 3 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
||||||
import React, { useState, useEffect } from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import './Avatar.scss';
|
import './Avatar.scss';
|
||||||
|
|
||||||
|
@ -10,22 +10,16 @@ import RawIcon from '../system-icons/RawIcon';
|
||||||
function Avatar({
|
function Avatar({
|
||||||
text, bgColor, iconSrc, iconColor, imageSrc, size,
|
text, bgColor, iconSrc, iconColor, imageSrc, size,
|
||||||
}) {
|
}) {
|
||||||
const [image, updateImage] = useState(imageSrc);
|
|
||||||
let textSize = 's1';
|
let textSize = 's1';
|
||||||
if (size === 'large') textSize = 'h1';
|
if (size === 'large') textSize = 'h1';
|
||||||
if (size === 'small') textSize = 'b1';
|
if (size === 'small') textSize = 'b1';
|
||||||
if (size === 'extra-small') textSize = 'b3';
|
if (size === 'extra-small') textSize = 'b3';
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
updateImage(imageSrc);
|
|
||||||
return () => updateImage(null);
|
|
||||||
}, [imageSrc]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`avatar-container avatar-container__${size} noselect`}>
|
<div className={`avatar-container avatar-container__${size} noselect`}>
|
||||||
{
|
{
|
||||||
image !== null
|
imageSrc !== null
|
||||||
? <img draggable="false" src={image} onError={() => updateImage(null)} alt="avatar" />
|
? <img draggable="false" src={imageSrc} alt="avatar" />
|
||||||
: (
|
: (
|
||||||
<span
|
<span
|
||||||
style={{ backgroundColor: iconSrc === null ? bgColor : 'transparent' }}
|
style={{ backgroundColor: iconSrc === null ? bgColor : 'transparent' }}
|
||||||
|
|
Loading…
Reference in a new issue