aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/MDX/ResponsiveImage/ResponsiveImage.tsx
blob: 6c39e7f317d0eead46c9047afd16fcaf52cca3c7 (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
import { ResponsiveImageProps } from '@ts/types/app';
import Image from 'next/image';
import Link from 'next/link';
import styles from './ResponsiveImage.module.scss';

const ResponsiveImage = (props: ResponsiveImageProps) => {
  const { caption, linkTarget, ...attributes } = props;

  return (
    <figure className={styles.wrapper}>
      {linkTarget ? (
        <Link href={linkTarget}>
          <a className={styles.link}>
            <Image
              alt={attributes.alt}
              layout={attributes.layout || 'intrinsic'}
              {...attributes}
            />
            {caption && (
              <figcaption className={styles.caption}>{caption}</figcaption>
            )}
          </a>
        </Link>
      ) : (
        <>
          <Image
            alt={attributes.alt}
            layout={attributes.layout || 'intrinsic'}
            {...attributes}
          />
          {caption && (
            <figcaption className={styles.caption}>{caption}</figcaption>
          )}
        </>
      )}
    </figure>
  );
};

export default ResponsiveImage;