1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 21:39:40 +02:00
portainer/app/react/components/FallbackImage.tsx
Ali d78b762f7b
refactor(icons): replace fa icons [EE-4459] (#7907)
refactor(icons): remove fontawesome EE-4459

refactor(icon) replace feather with lucide EE-4472
2022-11-28 15:00:28 +13:00

40 lines
776 B
TypeScript

import { useEffect, useState } from 'react';
import { BadgeIcon, BadgeSize } from './BadgeIcon/BadgeIcon';
interface Props {
// props for the image to load
src: string; // a link to an external image
fallbackIcon: string;
alt?: string;
size?: BadgeSize;
className?: string;
}
export function FallbackImage({
src,
fallbackIcon,
alt,
size,
className,
}: Props) {
const [error, setError] = useState(false);
useEffect(() => {
setError(false);
}, [src]);
if (!error && src) {
return (
<img
className={className}
src={src}
alt={alt}
onError={() => setError(true)}
/>
);
}
// fallback icon if there is an error loading the image
return <BadgeIcon icon={fallbackIcon} size={size} />;
}