mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-05 04:27:03 +00:00
feat(editor): add figure block with placement and caption
This commit is contained in:
1 parent
e76558fe1f
commit
50bde45d65
3 files changed
+78
-1
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import { NodeViewWrapper, type NodeViewProps } from "@tiptap/react";
|
||||
|
||||
const PLACEMENTS = [
|
||||
{ key: "inline", label: "Inline" },
|
||||
{ key: "full-width", label: "Full width" },
|
||||
{ key: "full-page", label: "Full page" },
|
||||
{ key: "float-top", label: "Float" },
|
||||
];
|
||||
|
||||
export function FigureView({ node, updateAttributes, selected }: NodeViewProps) {
|
||||
const { src, alt, caption, placement } = node.attrs;
|
||||
|
||||
return (
|
||||
<NodeViewWrapper className="figure" data-placement={placement} data-selected={selected} contentEditable={false}>
|
||||
<div className="figure-frame">
|
||||
{src ? <img src={src} alt={alt} /> : <div className="figure-empty">No image</div>}
|
||||
</div>
|
||||
<input
|
||||
className="figure-caption"
|
||||
value={caption}
|
||||
placeholder="Add a caption…"
|
||||
onChange={(e) => updateAttributes({ caption: e.target.value })}
|
||||
/>
|
||||
{selected && (
|
||||
<div className="figure-controls">
|
||||
{PLACEMENTS.map((p) => (
|
||||
<button key={p.key} data-on={placement === p.key} onClick={() => updateAttributes({ placement: p.key })}>
|
||||
{p.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</NodeViewWrapper>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user