mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
images: fixed lazy loading of SVG's
This commit is contained in:
parent
6230a769e0
commit
02dd66a6af
3 changed files with 56 additions and 10 deletions
51
src/components/node/NodeImageLazy/index.tsx
Normal file
51
src/components/node/NodeImageLazy/index.tsx
Normal file
|
@ -0,0 +1,51 @@
|
|||
import { FC } from 'react';
|
||||
|
||||
import { imagePresets } from '~/constants/urls';
|
||||
import { IFile } from '~/types';
|
||||
import { normalizeBrightColor } from '~/utils/color';
|
||||
import { getURL } from '~/utils/dom';
|
||||
import { getFileSrcSet } from '~/utils/srcset';
|
||||
|
||||
interface NodeImageLazyProps {
|
||||
className?: string;
|
||||
file: IFile;
|
||||
onLoad?: () => void;
|
||||
onClick?: () => void;
|
||||
}
|
||||
|
||||
/** Separates SVG-s and raster images to be used in NodeImageSwiperBlock */
|
||||
const NodeImageLazy: FC<NodeImageLazyProps> = ({
|
||||
file,
|
||||
onLoad,
|
||||
className,
|
||||
onClick,
|
||||
}) => {
|
||||
if (file.url.endsWith('svg')) {
|
||||
return (
|
||||
<img
|
||||
data-src={getURL(file, imagePresets[1600])}
|
||||
className={className}
|
||||
onClick={onClick}
|
||||
onLoad={onLoad}
|
||||
color={normalizeBrightColor(file?.metadata?.dominant_color)}
|
||||
alt=""
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<img
|
||||
data-srcset={getFileSrcSet(file)}
|
||||
width={file.metadata?.width}
|
||||
height={file.metadata?.height}
|
||||
onLoad={onLoad}
|
||||
onClick={onClick}
|
||||
className={className}
|
||||
color={normalizeBrightColor(file?.metadata?.dominant_color)}
|
||||
alt=""
|
||||
sizes="(max-width: 560px) 100vw, 50vh"
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export { NodeImageLazy };
|
Loading…
Add table
Add a link
Reference in a new issue