From c18f2f8a9d189343db9740945196af46c903d2d9 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Wed, 26 Jan 2022 12:43:20 +0100
Subject: chore: create a ResponsiveImage component for MDX rendering

---
 .../MDX/ResponsiveImage/ResponsiveImage.tsx        | 36 ++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 src/components/MDX/ResponsiveImage/ResponsiveImage.tsx

(limited to 'src/components/MDX/ResponsiveImage/ResponsiveImage.tsx')

diff --git a/src/components/MDX/ResponsiveImage/ResponsiveImage.tsx b/src/components/MDX/ResponsiveImage/ResponsiveImage.tsx
new file mode 100644
index 0000000..062c04b
--- /dev/null
+++ b/src/components/MDX/ResponsiveImage/ResponsiveImage.tsx
@@ -0,0 +1,36 @@
+import Image, { ImageProps } from 'next/image';
+import Link from 'next/link';
+import styles from './ResponsiveImage.module.scss';
+
+type ResponsiveImageProps = ImageProps & {
+  caption?: string;
+  linkTarget?: string;
+};
+
+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="intrinsic" {...attributes} />
+            {caption && (
+              <figcaption className={styles.caption}>{caption}</figcaption>
+            )}
+          </a>
+        </Link>
+      ) : (
+        <>
+          <Image alt={attributes.alt} layout="intrinsic" {...attributes} />
+          {caption && (
+            <figcaption className={styles.caption}>{caption}</figcaption>
+          )}
+        </>
+      )}
+    </figure>
+  );
+};
+
+export default ResponsiveImage;
-- 
cgit v1.2.3

