1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2026-04-17 09:28:43 -04:00

new <Figure> component for image captions

This commit is contained in:
2022-01-13 13:39:22 -05:00
parent 1a0541776e
commit 64a91d67bf
21 changed files with 226 additions and 409 deletions

View File

@@ -1,9 +1,9 @@
import CopyButton from "../clipboard/CopyButton";
import CopyButton from "./CopyButton";
import type { ReactNode } from "react";
import styles from "./Code.module.css";
type CustomCodeProps = {
export type CustomCodeProps = {
className?: string;
children: ReactNode;
};

View File

@@ -0,0 +1,20 @@
import Image from "./Image";
import innerText from "react-innertext";
import type { ReactNode } from "react";
import type { CustomImageProps } from "./Image";
export type CustomFigureProps = Omit<CustomImageProps, "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;

View File

@@ -2,10 +2,7 @@ import Image from "next/image";
import type { ImageProps } from "next/image";
import type { CSSProperties } from "react";
// TODO: infer ratio when given zero/one dimensions
// TODO: fold figure/figcaption tags into this component
type CustomImageProps = ImageProps & {
export type CustomImageProps = ImageProps & {
style?: CSSProperties;
};