-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathindex.tsx
More file actions
37 lines (36 loc) · 965 Bytes
/
index.tsx
File metadata and controls
37 lines (36 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2023 DatabendLabs.
import React, { FC, ReactElement, useState } from "react";
// refs: https://databendcloud.github.io/databend-logos/
import { LightDatabendSingleSvg } from "databend-logos";
// @ts-ignore
import { LazyLoadImage } from "react-lazy-load-image-component";
import clsx from "clsx";
interface IProps {
src: string;
width?: number | string;
className?: string;
}
const LoadLazyImg: FC<IProps> = ({
src,
width = "100%",
className,
}): ReactElement => {
const [isLoaded, setIsLoaded] = useState(false);
const handleImageLoad = () => {
setIsLoaded(true);
};
return (
<>
{!isLoaded && (
<LightDatabendSingleSvg width={width}></LightDatabendSingleSvg>
)}
<LazyLoadImage
placeholder={<div></div>}
onLoad={() => handleImageLoad()}
className={clsx("g-w100", className, isLoaded ? "g-db" : "g-dn")}
src={src}
/>
</>
);
};
export default LoadLazyImg;