judge4c/src/components/editor-config-panel.tsx
fly6516 b36c4af282 feat(editor): 添加编辑器配置功能并优化布局
- 在根布局中添加编辑器配置面板按钮- 实现编辑器配置面板组件,支持字体、字号、行高等设置
- 新增 useEditorConfigStore 钩子,用于管理编辑器配置状态
- 在问题编辑器中应用用户配置,并支持 TypeScript 语法
2025-05-17 03:36:28 +08:00

71 lines
2.0 KiB
TypeScript

import React from 'react';
import { useEditorConfigStore } from '@/lib/store';
export const EditorConfigPanel = () => {
const { config, updateConfig } = useEditorConfigStore();
const handleFontFamilyChange = (e: React.ChangeEvent<HTMLInputElement>) => {
updateConfig({ fontFamily: e.target.value });
};
const handleFontSizeChange = (e: React.ChangeEvent<HTMLInputElement>) => {
updateConfig({ fontSize: parseInt(e.target.value) });
};
const handleLineHeightChange = (e: React.ChangeEvent<HTMLInputElement>) => {
updateConfig({ lineHeight: parseInt(e.target.value) });
};
const handleReset = () => {
useEditorConfigStore.getState().resetConfig();
};
return (
<div className="p-4 space-y-4">
<h2 className="text-lg font-semibold"></h2>
<div className="space-y-2">
<label className="text-sm font-medium"></label>
<input
type="text"
value={config.fontFamily}
onChange={handleFontFamilyChange}
className="w-full p-2 border rounded-md"
/>
</div>
<div className="space-y-2">
<label className="text-sm font-medium"></label>
<input
type="number"
min="10"
max="24"
value={config.fontSize}
onChange={handleFontSizeChange}
className="w-full p-2 border rounded-md"
/>
</div>
<div className="space-y-2">
<label className="text-sm font-medium"></label>
<input
type="number"
min="18"
max="36"
value={config.lineHeight}
onChange={handleLineHeightChange}
className="w-full p-2 border rounded-md"
/>
</div>
<div className="pt-2">
<button
onClick={handleReset}
className="px-4 py-2 text-sm font-medium text-white bg-red-500 rounded-md hover:bg-red-600"
>
</button>
</div>
</div>
);
};