富文本编辑器 WangEditor
这是一个自定义的 React 组件 WangEditorFrame,它通过 iframe 内嵌的方式实现了 @wangeditor/editor-for-react 的隔离渲染,适用于需要避免编辑器污染主文档 CSS、JS 的场景。
📦 引入方式
import { WangEditor } from '@itera-web/react-ui-editor';
🧩 使用示例
- 示例
- 源码
<WangEditor
ref={null}
value="<p>初始内容</p>"
width="100%"
readOnly={false}
bordered
minHeight="800px"
offsetTop={0}
className="my-editor"
toolbarConfig={{
toolbarKeys: ['bold', 'italic', 'underline'],
}}
editorConfig={{
placeholder: '请输入内容...',
}}
onChange={(html) => {
console.log('编辑内容变更:', html);
}}
onCreated={(editorInstance) => {
console.log('编辑器初始化完成', editorInstance);
}}
onSave={() => {
console.log('触发保存(Ctrl + S)');
}}
/>
🧩 Props
| Prop | 类型 | 默认值 | 描述 |
|---|---|---|---|
value | string | '' | 初始内容(HTML 格式) |
width | string | '100%' | 编辑器宽度 |
height | string | '500px' | 编辑器高度 |
minHeight | string | '800px' | 最小高度 |
offsetTop | number | 0 | 顶部工具栏吸顶偏移量 和 最小高度搭配使用 |
readOnly | boolean | false | 是否为只读模式 |
bordered | boolean | true | 是否显示边框(尚未使用) |
className | string | '' | 外层 div 的样式类名 |
toolbarConfig | Partial<IToolbarConfig> | {} | 工具栏配置 |
editorConfig | Partial<IEditorConfig> | { placeholder: '请输入内容...' } | 编辑器配置 |
onChange | (html: string) => void | () => null | 内容发生变化时的回调 |
onCreated | (editor: IDomEditor) => void | () => null |