-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- now we don't use srcset solution for which was our Image component prepared - it was replaced with the solution provided by Next.js which is NextImage component - this component allows us many more possibilities.
- Loading branch information
1 parent
1c53d06
commit 0311a43
Showing
37 changed files
with
229 additions
and
178 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
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 |
---|---|---|
@@ -1,58 +1,21 @@ | ||
import { ImageFragmentApi } from 'graphql/generated'; | ||
import { twMergeCustom } from 'helpers/twMerge'; | ||
import { ImgHTMLAttributes } from 'react'; | ||
import NextImage, { ImageProps as NextImageProps } from 'next/image'; | ||
import { useState } from 'react'; | ||
|
||
type ImageProps = { | ||
image: ImageFragmentApi | null | undefined; | ||
alt: string | null | undefined; | ||
loading?: ImgHTMLAttributes<HTMLImageElement>['loading']; | ||
width?: string | number; | ||
height?: string | number; | ||
wrapperClassName?: string; | ||
}; | ||
|
||
const getDataTestId = (dataTestId?: string) => dataTestId ?? 'basic-image'; | ||
|
||
export const Image: FC<ImageProps> = ({ | ||
image, | ||
alt, | ||
loading, | ||
dataTestId, | ||
width, | ||
height, | ||
className, | ||
wrapperClassName, | ||
}) => { | ||
const imageTwClass = twMergeCustom( | ||
'object-contain [image-rendering:-webkit-optimize-contrast] max-w-full max-h-full mx-auto', | ||
className, | ||
); | ||
src: NextImageProps['src'] | undefined | null; | ||
} & Omit<NextImageProps, 'src'>; | ||
|
||
if (!image) { | ||
return ( | ||
<div className={wrapperClassName}> | ||
<img | ||
alt={alt || ''} | ||
className={twMergeCustom('h-auto w-full', imageTwClass)} | ||
data-testid={getDataTestId(dataTestId) + '-empty'} | ||
height={height || 160} | ||
src="/images/optimized-noimage.webp" | ||
width={width || 160} | ||
/> | ||
</div> | ||
); | ||
} | ||
export const Image: FC<ImageProps> = ({ src, className, ...props }) => { | ||
const [imageUrl, setImageUrl] = useState(src ?? '/images/optimized-noimage.webp'); | ||
|
||
return ( | ||
<picture className={wrapperClassName}> | ||
<img | ||
alt={image.name || alt || ''} | ||
className={imageTwClass} | ||
height={height} | ||
loading={loading} | ||
src={image.url} | ||
width={width} | ||
/> | ||
</picture> | ||
<NextImage | ||
className={twMergeCustom('[image-rendering:-webkit-optimize-contrast]', className)} | ||
loader={({ src, width }) => `${src}?width=${width || '0'}`} | ||
src={imageUrl} | ||
onError={() => setImageUrl('/images/optimized-noimage.webp')} | ||
{...props} | ||
/> | ||
); | ||
}; |
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
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
Oops, something went wrong.