Files
jarv.is/components/media/Figure.tsx
T
2022-01-16 18:31:51 -05:00

21 lines
626 B
TypeScript

import Image from "./Image";
import innerText from "react-innertext";
import type { ReactNode } from "react";
import type { ImageProps } from "next/image";
type CustomFigureProps = Omit<ImageProps, "alt"> & {
children: ReactNode; // caption (can be in markdown, yay!!!)
alt?: string; // becomes optional -- pulled from plaintext-ified caption if missing
};
const CustomFigure = ({ children, alt, ...imageProps }: CustomFigureProps) => {
return (
<figure>
<Image alt={alt || innerText(children)} {...imageProps} />
<figcaption>{children}</figcaption>
</figure>
);
};
export default CustomFigure;