MCPcopy Create free account
hub / github.com/dailydotdev/apps / LazyImageComponent

Function LazyImageComponent

packages/shared/src/components/LazyImage.tsx:24–77  ·  view source on GitHub ↗
(
  {
    imgSrc,
    imgAlt,
    eager,
    className,
    ratio,
    background,
    fallbackSrc,
    children,
    absolute = false,
    fit = 'cover',
    fetchPriority = 'auto',
    ...props
  }: LazyImageProps,
  ref?: Ref<HTMLImageElement>,
)

Source from the content-addressed store, hash-verified

22}
23
24function LazyImageComponent(
25 {
26 imgSrc,
27 imgAlt,
28 eager,
29 className,
30 ratio,
31 background,
32 fallbackSrc,
33 children,
34 absolute = false,
35 fit = 'cover',
36 fetchPriority = 'auto',
37 ...props
38 }: LazyImageProps,
39 ref?: Ref<HTMLImageElement>,
40): ReactElement {
41 const src = imgSrc || fallbackSrc;
42 const onError = (event: SyntheticEvent<HTMLImageElement>): void => {
43 if (fallbackSrc && fallbackSrc !== event.currentTarget.src) {
44 // eslint-disable-next-line no-param-reassign
45 event.currentTarget.src = fallbackSrc;
46 }
47 };
48
49 return (
50 <figure
51 {...props}
52 className={classNames(
53 className,
54 absolute ? 'absolute' : 'relative',
55 'overflow-hidden',
56 )}
57 style={{ background, ...props?.style }}
58 ref={ref}
59 >
60 {ratio && <div style={{ paddingTop: ratio, zIndex: -1 }} />}
61 <img
62 alt={imgAlt}
63 className={classNames(
64 'absolute inset-0 m-auto block h-full w-full',
65 fit === 'cover' ? 'object-cover' : 'object-contain',
66 )}
67 key={src}
68 loading={eager ? 'eager' : 'lazy'}
69 src={src}
70 onError={onError}
71 /* @ts-expect-error - Not supported by react yet */ /* eslint-disable react/no-unknown-property */
72 fetchpriority={fetchPriority}
73 />
74 {children}
75 </figure>
76 );
77}
78
79export type LazyVideoProps = Omit<
80 LazyImageProps,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected