2025-03-12 13:43:11 -04:00
|
|
|
import React from 'react';
|
|
|
|
|
import { TextField, Typography, IconButton, Box } from '@mui/material';
|
2025-03-26 14:52:09 -04:00
|
|
|
import DeleteIcon from '@mui/icons-material/Delete';
|
|
|
|
|
import VisibilityIcon from '@mui/icons-material/Visibility';
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
interface EditorProps {
|
2024-09-17 18:56:13 -04:00
|
|
|
label: string;
|
2025-03-12 13:43:11 -04:00
|
|
|
values: string[];
|
|
|
|
|
onValuesChange: (values: string[]) => void;
|
2025-03-26 14:52:09 -04:00
|
|
|
onFocusQuestion?: (index: number) => void;
|
2024-03-29 20:08:34 -04:00
|
|
|
}
|
|
|
|
|
|
2025-03-26 14:52:09 -04:00
|
|
|
const Editor: React.FC<EditorProps> = ({ label, values, onValuesChange, onFocusQuestion }) => {
|
2025-03-12 13:43:11 -04:00
|
|
|
const handleChange = (index: number) => (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
const newValues = [...values];
|
|
|
|
|
newValues[index] = event.target.value;
|
|
|
|
|
onValuesChange(newValues);
|
|
|
|
|
};
|
2024-03-29 20:08:34 -04:00
|
|
|
|
2025-03-12 13:43:11 -04:00
|
|
|
const handleDeleteQuestion = (index: number) => () => {
|
|
|
|
|
const newValues = values.filter((_, i) => i !== index); // Remove the question at the specified index
|
|
|
|
|
onValuesChange(newValues);
|
|
|
|
|
};
|
2024-03-29 20:08:34 -04:00
|
|
|
|
2025-03-26 14:52:09 -04:00
|
|
|
const handleFocusQuestion = (index: number) => () => {
|
|
|
|
|
if (onFocusQuestion) {
|
|
|
|
|
onFocusQuestion(index); // Call the focus function if provided
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2025-03-12 13:43:11 -04:00
|
|
|
<div>
|
|
|
|
|
<Typography variant="h6" fontWeight="bold" style={{ marginBottom: '24px' }}>
|
|
|
|
|
{label}
|
|
|
|
|
</Typography>
|
|
|
|
|
|
|
|
|
|
{values.map((value, index) => (
|
|
|
|
|
<Box key={index} style={{ marginBottom: '24px' }}>
|
|
|
|
|
<Box display="flex" alignItems="center" justifyContent="space-between">
|
2025-03-26 14:52:09 -04:00
|
|
|
<Typography variant="subtitle1" fontWeight="bold" style={{ marginBottom: '8px' }}>
|
|
|
|
|
Question {index + 1}
|
|
|
|
|
</Typography>
|
|
|
|
|
<Box>
|
|
|
|
|
{/* Focus (Eye) Button */}
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={handleFocusQuestion(index)}
|
|
|
|
|
aria-label="focus question"
|
|
|
|
|
sx={{
|
|
|
|
|
color: 'gray',
|
|
|
|
|
'&:hover': { color: 'blue' },
|
|
|
|
|
marginRight: '8px', // Space between eye and delete
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<VisibilityIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
{/* Delete Button */}
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={handleDeleteQuestion(index)}
|
|
|
|
|
aria-label="delete"
|
|
|
|
|
sx={{
|
|
|
|
|
color: 'light-gray',
|
|
|
|
|
'&:hover': { color: 'red' },
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<DeleteIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Box>
|
2025-03-12 13:43:11 -04:00
|
|
|
</Box>
|
|
|
|
|
<TextField
|
|
|
|
|
value={value}
|
|
|
|
|
onChange={handleChange(index)}
|
|
|
|
|
fullWidth
|
|
|
|
|
multiline
|
|
|
|
|
minRows={4}
|
|
|
|
|
maxRows={Infinity}
|
|
|
|
|
variant="outlined"
|
2025-03-26 14:52:09 -04:00
|
|
|
style={{ overflow: 'auto' }}
|
2025-03-12 13:43:11 -04:00
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
2024-03-29 20:08:34 -04:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-12 13:43:11 -04:00
|
|
|
export default Editor;
|