diff options
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; |
