UNPKG

1.17 kBJavaScriptView Raw
1import React from "react";
2import BraftEditor from "braft-editor";
3import "braft-editor/dist/index.css";
4export const Braft = BraftEditor;
5/**
6 * ----------------------------------------
7 * BraftEditor
8 * @param {EditorState} value
9 * @param {Function} onChange
10 *
11 * !! Usage
12 * 导入: import BraftEditor, { Braft } from "@comps/BraftEditor";
13 * 表单: <FormItem name="content"><BraftEditor /></FormItem>
14 * 编辑时 String => EditorState 转换: editData.content = Braft.createEditorState(editData.content);
15 * 提交时 EditorState => String 转换: params.content = params.content.toHTML();
16 * ----------------------------------------
17 */
18export default function BraftEditor({ style, ...props }) {
19 return (
20 <div style={{ border: "1px solid #cac9c9", ...style }}>
21 <BraftEditor
22 controls={controls}
23 placeholder="在这里输入内容"
24 contentStyle={{ height: "100%" }}
25 {...props}
26 />
27 </div>
28 );
29}
30
31const controls = [
32 "undo",
33 "redo",
34 "font-size",
35 "line-height",
36 "text-color",
37 "bold",
38 "italic",
39 "underline",
40 "remove-styles",
41 "text-align",
42 "headings",
43 "list-ul",
44 "list-ol",
45 "media",
46];