2024-03-29 20:08:34 -04:00
|
|
|
// Editor.tsx
|
|
|
|
|
import React, { useState, useRef } from 'react';
|
|
|
|
|
import './editor.css';
|
2024-09-17 18:56:13 -04:00
|
|
|
import { TextareaAutosize } from '@mui/material';
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
interface EditorProps {
|
2024-09-17 18:56:13 -04:00
|
|
|
label: string;
|
2024-03-29 20:08:34 -04:00
|
|
|
initialValue: string;
|
|
|
|
|
onEditorChange: (value: string) => void;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-17 18:56:13 -04:00
|
|
|
const Editor: React.FC<EditorProps> = ({ initialValue, onEditorChange, label }) => {
|
2024-03-29 20:08:34 -04:00
|
|
|
const [value, setValue] = useState(initialValue);
|
|
|
|
|
const editorRef = useRef<HTMLTextAreaElement | null>(null);
|
|
|
|
|
|
|
|
|
|
function handleEditorChange(event: React.ChangeEvent<HTMLTextAreaElement>) {
|
|
|
|
|
const text = event.target.value;
|
|
|
|
|
setValue(text);
|
|
|
|
|
onEditorChange(text || '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2024-09-17 18:56:13 -04:00
|
|
|
<label>
|
|
|
|
|
<h4>{label}</h4>
|
|
|
|
|
<TextareaAutosize
|
|
|
|
|
id="editor-textarea"
|
2024-03-29 20:08:34 -04:00
|
|
|
ref={editorRef}
|
|
|
|
|
onChange={handleEditorChange}
|
|
|
|
|
value={value}
|
|
|
|
|
className="editor"
|
2024-09-17 18:56:13 -04:00
|
|
|
minRows={5}
|
|
|
|
|
/>
|
|
|
|
|
</label>
|
2024-03-29 20:08:34 -04:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Editor;
|