提交 71f8d7d5 authored 作者: 王鹏飞's avatar 王鹏飞

refactor(admin): extract editor sidebar

上级 7c60f75c
import { Button } from 'antd'
import { Toolbar } from '@wangeditor/editor-for-react'
const tabs = [
{ key: 'text', title: '文本设置' },
{ key: 'style', title: '样式模版' },
]
export const EditorSidebar = ({ editor, toolbarConfig, toolbarRef, tabKey, onTabChange, colorList, onApplyColor }) => <div className="menu-tabs-key">
<div className="tabs">
{tabs.map(item => <div className={`tabs-item ${item.key === tabKey ? 'active' : ''}`} key={item.key} onClick={() => onTabChange(item.key)}>{item.title}<span /></div>)}
</div>
<div className="menu-tabs-content">
{tabKey === 'text' && <div ref={toolbarRef} className="toolbox-parent"><Toolbar editor={editor} defaultConfig={toolbarConfig} mode="default" className="editor-toolbar-container" /></div>}
{tabKey === 'style' && <div className="styletem"><p>样式模板</p><ul>{colorList.map(item => <li key={item.color}><div className="left"><span className="color" style={{ backgroundColor: item.color }} /><b className="type">{item.name}</b></div><Button type="link" className="use" onClick={() => onApplyColor(item.color)}>使用</Button></li>)}</ul></div>}
</div>
</div>
...@@ -40,16 +40,12 @@ import PracticeSettingModal from "../features/practice/PracticeSettingsDialog"; ...@@ -40,16 +40,12 @@ import PracticeSettingModal from "../features/practice/PracticeSettingsDialog";
import PreviewModal from "../features/preview/PreviewDialog"; import PreviewModal from "../features/preview/PreviewDialog";
import HistoryModal from "../features/history/HistoryDialog"; import HistoryModal from "../features/history/HistoryDialog";
import { EditorHeader } from './EditorHeader' import { EditorHeader } from './EditorHeader'
import { EditorSidebar } from './EditorSidebar'
import "../index.less"; import "../index.less";
registerEditorFeatures(Boot); registerEditorFeatures(Boot);
const tabsMenu = [
{ key: "text", title: "文本设置" },
{ key: "style", title: "样式模版" },
];
const WangEditorCustomer = (props, ref) => { const WangEditorCustomer = (props, ref) => {
const { const {
...@@ -590,58 +586,7 @@ const WangEditorCustomer = (props, ref) => { ...@@ -590,58 +586,7 @@ const WangEditorCustomer = (props, ref) => {
style={{ height: "calc(100vh - 250px)", overflowY: "hidden" }} style={{ height: "calc(100vh - 250px)", overflowY: "hidden" }}
/> />
</div> </div>
{!isView && ( {!isView && <EditorSidebar editor={editor} toolbarConfig={toolbarConfig} toolbarRef={toolbarRef} tabKey={tabKey} onTabChange={tabKeyChange} colorList={colorList} onApplyColor={setColor} />}
<div className="menu-tabs-key">
<div className="tabs">
{tabsMenu &&
tabsMenu.length &&
tabsMenu.map((item) => {
return (
<div
className={`tabs-item ${item.key === tabKey ? "active" : ""}`}
key={item.key}
onClick={() => tabKeyChange(item.key)}
>
{item.title}
<span></span>
</div>
);
})}
</div>
<div className="menu-tabs-content">
{tabKey === "text" && (
<div ref={toolbarRef} className="toolbox-parent">
<Toolbar
editor={editor}
defaultConfig={toolbarConfig}
mode="default"
className="editor-toolbar-container"
></Toolbar>
</div>
)}
{tabKey === "style" && (
<div className="styletem">
<p>样式模板</p>
<ul>
{colorList.map((item) => {
return (
<li key={item.color}>
<div className="left">
<span className="color" style={{ backgroundColor: item.color }}></span>
<b className="type">{item.name}</b>
</div>
<Button type="link" className="use" onClick={() => setColor(item.color)}>
使用
</Button>
</li>
);
})}
</ul>
</div>
)}
</div>
</div>
)}
<Modal <Modal
open={imageVisible} open={imageVisible}
footer={null} footer={null}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论