add reusable ImageFigure component

This commit is contained in:
2024-07-07 17:43:19 +02:00
parent e03e2624db
commit ada7d25083
15 changed files with 70 additions and 58 deletions
+20 -2
View File
@@ -1,7 +1,25 @@
import NextImage, { ImageProps as NextImageProps } from "next/image";
import styles from "./image.module.scss";
type ImageProps = NextImageProps;
type ImageProps = NextImageProps & {
attribution?: string | null;
caption?: string | null;
imageFormat?: string | null; // "original" | "bleed" | "fullWidth"
};
export default function Image(props: ImageProps) {
export function ImageFigure(props: ImageProps) {
const { attribution, caption, imageFormat, ...nextImageProps } = props;
return (
<figure
className={`${styles.image} ${imageFormat ? styles[imageFormat] : ""}`}
>
<NextImage {...nextImageProps} />
{attribution && <div className={styles.attribution}>{attribution}</div>}
{caption && <figcaption>{caption}</figcaption>}
</figure>
);
}
export function Image(props: NextImageProps) {
return <NextImage {...props} />;
}
@@ -0,0 +1,59 @@
.image {
width: 100%;
margin: 0;
img {
display: block;
max-width: 100%;
height: auto;
}
figcaption {
width: 100%;
max-width: var(--size-width-p);
margin: 0 auto;
padding: var(--spacing-s) 0;
font-size: var(--font-size-caption);
line-height: 1.4;
opacity: .8;
}
&.bleed {
width: 100vw;
margin: 2rem calc(var(--spacing-sitepadding-inline)*-1);
img {
width: 100%;
}
@media (max-width: 800px) {
padding: var(--spacing-xs) var(--spacing-sitepadding-inline);
}
}
&.fullwidth {
margin: 2rem 0;
img {
width: 100%;
}
}
&.original {
width: 100%;
margin: 2rem auto;
text-align: center;
img {
margin: auto;
}
figcaption {
text-align: left;
}
}
}
.attribution {
border: 1px dotted mediumpurple;
}