mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-18 07:16:34 +00:00
- 在根布局中添加编辑器配置面板按钮- 实现编辑器配置面板组件,支持字体、字号、行高等设置 - 新增 useEditorConfigStore 钩子,用于管理编辑器配置状态 - 在问题编辑器中应用用户配置,并支持 TypeScript 语法
71 lines
2.0 KiB
TypeScript
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>
|
|
);
|
|
}; |