diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-01-26 12:43:20 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-01-26 12:43:20 +0100 |
| commit | c18f2f8a9d189343db9740945196af46c903d2d9 (patch) | |
| tree | aa676f9aa24edc6e5d6eab841b134f028800f5ba /src/components/MDX/ResponsiveImage/ResponsiveImage.tsx | |
| parent | 7e12b2aa7f511e70b727bd865a0b5d0ac6723cb8 (diff) | |
chore: create a ResponsiveImage component for MDX rendering
Diffstat (limited to 'src/components/MDX/ResponsiveImage/ResponsiveImage.tsx')
| -rw-r--r-- | src/components/MDX/ResponsiveImage/ResponsiveImage.tsx | 36 |
1 files changed, 36 insertions, 0 deletions
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; |
