返回 presentation-ai
media-image-node-static.tsx
根目录 / src / components / plate / ui / media-image-node-static.tsx
1 import Image from "next/image";
2 import {
3 NodeApi,
4 type TCaptionProps,
5 type TImageElement,
6 type TResizableProps,
7 } from "platejs";
8 import { SlateElement, type SlateElementProps } from "platejs/static";
9
10 import { cn } from "@/lib/utils";
11
12 export function ImageElementStatic(
13 props: SlateElementProps<TImageElement & TCaptionProps & TResizableProps>,
14 ) {
15 const { align = "center", caption, url, width } = props.element;
16
17 return (
18 <SlateElement {...props} className="py-2.5">
19 <figure className="group relative m-0 inline-block" style={{ width }}>
20 <div
21 className="relative max-w-full min-w-23"
22 style={{ textAlign: align }}
23 >
24 <Image
25 unoptimized
26 width={400}
27 height={300}
28 className={cn(
29 "w-full max-w-full cursor-default object-cover px-0",
30 "rounded-sm",
31 )}
32 alt={props.attributes.alt as string}
33 src={url}
34 />
35 {caption && (
36 <figcaption className="mx-auto mt-2 h-6 max-w-full">
37 {NodeApi.string(caption![0]!)}
38 </figcaption>
39 )}
40 </div>
41 </figure>
42 {props.children}
43 </SlateElement>
44 );
45 }
46
46 lines Plain Text