website refactor
This commit is contained in:
@@ -1,35 +1,28 @@
|
||||
import React, { useState } from 'react';
|
||||
import React from 'react';
|
||||
import { Box, BoxProps } from './Box';
|
||||
import { ImagePlaceholder } from './ImagePlaceholder';
|
||||
|
||||
export interface ImageProps extends Omit<BoxProps<'img'>, 'children'> {
|
||||
src: string;
|
||||
alt: string;
|
||||
fallbackSrc?: string;
|
||||
fallbackComponent?: React.ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Image
|
||||
*
|
||||
* Stateless UI primitive for images.
|
||||
* For error handling, use SafeImage component.
|
||||
*/
|
||||
export const Image = ({
|
||||
src,
|
||||
alt,
|
||||
fallbackSrc,
|
||||
fallbackComponent,
|
||||
...props
|
||||
}: ImageProps) => {
|
||||
const [error, setError] = useState(false);
|
||||
|
||||
if (error) {
|
||||
if (fallbackComponent) return <>{fallbackComponent}</>;
|
||||
if (fallbackSrc) return <Box as="img" src={fallbackSrc} alt={alt} {...props} />;
|
||||
return <ImagePlaceholder />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Box
|
||||
as="img"
|
||||
src={src}
|
||||
alt={alt}
|
||||
onError={() => setError(true)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user