summaryrefslogtreecommitdiff
path: root/src-migrate/components/ui/image.tsx
blob: c7ed0b0ea3bb2ad9e8d25e4067b35df610cbe273 (plain)
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
38
39
40
41
42
43
44
45
46
import clsx from 'clsx';
import NextImage, { ImageProps as NextImageProps } from 'next/image';
import { useState } from 'react';

import clsxm from '~/libs/clsxm';

type ImageProps = {
  rounded?: string;
  classNames?: {
    wrapper: string
  }
} & NextImageProps;

const Image = (props: ImageProps) => {
  const { alt, src, className, classNames, rounded, ...rest } = props;
  const [isLoading, setLoading] = useState(true);

  return (
    <div
      className={clsx(
        'overflow-hidden',
        isLoading ? 'animate-pulse' : '',
        rounded,
        classNames?.wrapper
      )}
    >
      <NextImage
        className={clsxm(
          'duration-500 ease-in-out',
          isLoading
            ? 'scale-[1.02] blur-xl grayscale'
            : 'scale-100 blur-0 grayscale-0',
          rounded,
          className
        )}
        src={src}
        alt={alt}
        loading='lazy'
        quality={100}
        onLoadingComplete={() => setLoading(false)}
        {...rest}
      />
    </div>
  );
};
export default Image;