summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-01-26 12:43:20 +0100
committerArmand Philippot <git@armandphilippot.com>2022-01-26 12:43:20 +0100
commitc18f2f8a9d189343db9740945196af46c903d2d9 (patch)
treeaa676f9aa24edc6e5d6eab841b134f028800f5ba /src
parent7e12b2aa7f511e70b727bd865a0b5d0ac6723cb8 (diff)
chore: create a ResponsiveImage component for MDX rendering
Diffstat (limited to 'src')
-rw-r--r--src/components/MDX/ResponsiveImage/ResponsiveImage.module.scss49
-rw-r--r--src/components/MDX/ResponsiveImage/ResponsiveImage.tsx36
-rw-r--r--src/components/MDX/index.tsx3
3 files changed, 87 insertions, 1 deletions
diff --git a/src/components/MDX/ResponsiveImage/ResponsiveImage.module.scss b/src/components/MDX/ResponsiveImage/ResponsiveImage.module.scss
new file mode 100644
index 0000000..34b1a92
--- /dev/null
+++ b/src/components/MDX/ResponsiveImage/ResponsiveImage.module.scss
@@ -0,0 +1,49 @@
+@use "@styles/abstracts/functions" as fun;
+
+.wrapper {
+ width: max-content;
+ max-width: 100%;
+ margin: var(--spacing-sm) auto;
+ position: relative;
+}
+
+.link {
+ display: flex;
+ flex-flow: column;
+ background: none;
+ text-decoration: none;
+
+ .caption {
+ color: var(--color-primary-darker);
+ }
+
+ &:hover,
+ &:focus {
+ transform: scale(1.1);
+ }
+
+ &:focus {
+ .caption {
+ text-decoration: underline solid var(--color-primary-darker)
+ fun.convert-px(3);
+ }
+ }
+
+ &:active {
+ transform: scale(0.9);
+
+ .caption {
+ text-decoration: none;
+ }
+ }
+}
+
+.caption {
+ margin: 0;
+ padding: fun.convert-px(4) var(--spacing-2xs);
+ background: var(--color-bg-secondary);
+ border: fun.convert-px(1) solid var(--color-border);
+ box-shadow: 0 fun.convert-px(-1) fun.convert-px(1) fun.convert-px(1)
+ var(--color-shadow-light);
+ font-weight: 500;
+}
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;
diff --git a/src/components/MDX/index.tsx b/src/components/MDX/index.tsx
index 5ebe6bf..acb885e 100644
--- a/src/components/MDX/index.tsx
+++ b/src/components/MDX/index.tsx
@@ -1,4 +1,5 @@
import CodeBlock from './CodeBlock/CodeBlock';
import Link from './Link/Link';
+import ResponsiveImage from './ResponsiveImage/ResponsiveImage';
-export { CodeBlock, Link };
+export { CodeBlock, Link, ResponsiveImage };