EvalueTonSavoir/client/src/components/Editor/Editor.tsx

71 lines
2.5 KiB
TypeScript
Raw Normal View History

import React from 'react';
import { TextField, Typography, IconButton, Box } from '@mui/material';
import DeleteIcon from '@mui/icons-material/Delete'; // Import delete icon
2024-03-29 20:08:34 -04:00
interface EditorProps {
label: string;
values: string[];
onValuesChange: (values: string[]) => void;
2024-03-29 20:08:34 -04:00
}
const Editor: React.FC<EditorProps> = ({ label, values, onValuesChange }) => {
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
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
return (
<div>
{/* Label with increased margin */}
<Typography variant="h6" fontWeight="bold" style={{ marginBottom: '24px' }}>
{label}
</Typography>
{/* Map through each question */}
{values.map((value, index) => (
<Box key={index} style={{ marginBottom: '24px' }}>
{/* Bold "Question #" title */}
<Box display="flex" alignItems="center" justifyContent="space-between">
<Typography variant="subtitle1" fontWeight="bold" style={{ marginBottom: '8px' }}>
Question {index + 1}
</Typography>
{/* Delete button */}
<IconButton
onClick={handleDeleteQuestion(index)}
aria-label="delete"
sx={{ color: 'light-gray',
'&:hover': {
color: 'red'
},
}}
>
<DeleteIcon />
</IconButton>
</Box>
{/* TextField for the question */}
<TextField
value={value}
onChange={handleChange(index)}
fullWidth
multiline
minRows={4}
maxRows={Infinity}
variant="outlined"
style={{ overflow: 'auto'}}
/>
</Box>
))}
</div>
2024-03-29 20:08:34 -04:00
);
};
export default Editor;