Markdown editor
This commit is contained in:
21
components/mdeditor/TextEditor.tsx
Normal file
21
components/mdeditor/TextEditor.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import CodeMirror from "@uiw/react-codemirror";
|
||||
import { markdown } from "@codemirror/lang-markdown";
|
||||
import { duotoneDark } from "@uiw/codemirror-theme-duotone";
|
||||
|
||||
interface TextEditorProps {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
}
|
||||
|
||||
export const TextEditor: React.FC<TextEditorProps> = ({ value, onChange }) => {
|
||||
return (
|
||||
<CodeMirror
|
||||
value={value}
|
||||
extensions={[markdown({ extensions: [] })]}
|
||||
onChange={(value, _viewUpdate) => {
|
||||
onChange(value);
|
||||
}}
|
||||
theme={duotoneDark}
|
||||
/>
|
||||
);
|
||||
};
|
19
components/mdeditor/index.tsx
Normal file
19
components/mdeditor/index.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
"use client";
|
||||
import { useDeferredValue, useState } from "react";
|
||||
import { TextEditor } from "./TextEditor";
|
||||
import { TTCMD } from "../ttcmd";
|
||||
|
||||
export const MDEditor: React.FC = () => {
|
||||
const [text, setText] = useState("");
|
||||
const body = useDeferredValue(text);
|
||||
return (
|
||||
<div className="flex gap-8">
|
||||
<div className="w-1/2">
|
||||
<TextEditor value={text} onChange={setText} />
|
||||
</div>
|
||||
<div className="w-1/2">
|
||||
<TTCMD body={body} parserId="preview" title="preview" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
Reference in New Issue
Block a user