summaryrefslogtreecommitdiff
path: root/src/core/components/elements/Image/Image.jsx
blob: be275e8d0d0afd09e5f398f41f90dfe919487d8b (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
import NextImage from 'next/image'
import { useState } from 'react'
import classNames from 'classnames'

/**
 * The `Image` component is used to display lazy-loaded images.
 *
 * @param {Object} props - Props passed to the `Image` component.
 * @param {string} props.src - URL of the image to be displayed.
 * @param {string} props.alt - Alternative text to be displayed if the image is not found.
 * @returns {JSX.Element} - Rendered `Image` component.
 */
const Image = ({ ...props }) => {
  const [isLoading, setIsLoading] = useState(true)

  const imageClassNames = classNames(
    'duration-500 ease-in-out',
    {
      'blur-2xl grayscale': isLoading,
      'blur-0 grayscale-0': !isLoading
    },
    props.className
  )

  return (
    <>
      <NextImage
        {...props}
        src={props.src || '/images/noimage.jpeg'}
        alt={props.src ? props.alt : 'Image Not Found - Indoteknik'}
        key={props.src || '/images/noimage.jpeg'}
        className={imageClassNames}
        width={256}
        height={256}
        onLoadingComplete={() => setIsLoading(false)}
      />
    </>
  )
}

export default Image