Skip to content

Commit

Permalink
Revert "Pass all Image.props to nested img element"
Browse files Browse the repository at this point in the history
This reverts commit ab8cb0b.
  • Loading branch information
0xNeshi committed Jan 4, 2024
1 parent ab8cb0b commit 6dd2dcb
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/components/Image/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ export type ImageProps = React.ImgHTMLAttributes<HTMLImageElement> & {
} & ({ href: string; title: string } | { href?: never; title?: never });

const Image = React.forwardRef<HTMLImageElement, ImageProps>(
(
{ alt = "", className, isSrcLoading, href, title, onError, ...props },
forwardRef
) => {
({ className, ...props }, forwardRef) => {
const ref = useRef<HTMLImageElement>(null);
const [isError, setError] = useState(false);

Expand All @@ -26,7 +23,7 @@ const Image = React.forwardRef<HTMLImageElement, ImageProps>(
() => ref.current
);

if ((!props.src && !isSrcLoading) || isError) {
if ((!props.src && !props.isSrcLoading) || isError) {
return <ImagePlaceholder className={className} />;
}

Expand All @@ -48,8 +45,7 @@ const Image = React.forwardRef<HTMLImageElement, ImageProps>(
* 5. Component `Image` flickers as it transitions from displaying `ContentLoader` to displaying `img`
*
*/
const isLoading = !ref.current?.complete && isSrcLoading;
const commonClasses = `${className} ${isLoading ? "hidden" : ""}`;
const isLoading = !ref.current?.complete && props.isSrcLoading;

return (
<>
Expand All @@ -66,13 +62,20 @@ const Image = React.forwardRef<HTMLImageElement, ImageProps>(
* wrapping the `img`.
*
*/}
<WithLink className={commonClasses} href={href} title={title}>
<WithLink
className={`${className} ${isLoading ? "hidden" : ""}`}
href={props.href}
title={props.title}
>
<img
ref={ref}
className={`object-contain ${commonClasses}`}
alt={alt}
onError={(e) => (onError ? onError(e) : setError(true))}
{...props}
src={props.src}
className={`object-contain ${
isLoading ? "hidden" : ""
} ${className}`}
alt={props.alt || ""}
loading={props.loading}
onError={(e) => (props.onError ? props.onError(e) : setError(true))}
/>
</WithLink>
</>
Expand Down

0 comments on commit 6dd2dcb

Please sign in to comment.