frontAnswerer/lib/components/ViewPublicationPage/QuestionSelect.tsx

113 lines
3.2 KiB
TypeScript
Raw Normal View History

2024-04-11 14:11:43 +00:00
import { useQuizData } from "@/contexts/QuizDataContext";
import { AnyTypedQuizQuestion } from "@/model/questionTypes/shared";
import { Box, FormControl, MenuItem, Select as MuiSelect, useTheme } from "@mui/material";
interface Props {
2024-05-31 16:41:18 +00:00
selectedQuestion: AnyTypedQuizQuestion;
setQuestion: (questionIdF: string) => void;
2024-04-11 14:11:43 +00:00
}
export default function QuestionSelect({ selectedQuestion, setQuestion }: Props) {
2024-05-31 16:41:18 +00:00
const theme = useTheme();
const { questions, preview } = useQuizData();
2024-04-11 14:11:43 +00:00
2024-05-31 16:41:18 +00:00
if (!preview) return null;
2024-04-11 14:11:43 +00:00
2024-05-31 16:41:18 +00:00
return (
<Box
sx={{
p: "20px",
display: "flex",
justifyContent: "center",
}}
>
<FormControl
fullWidth
size="small"
sx={{
maxWidth: "500px",
minWidth: "200px",
height: "48px",
}}
className="cancel"
>
<MuiSelect
id="category-select"
variant="outlined"
value={selectedQuestion.id}
placeholder="Заголовок вопроса"
onChange={({ target }) => {
setQuestion(target.value);
}}
sx={{
height: "48px",
borderRadius: "8px",
"& .MuiOutlinedInput-notchedOutline": {
border: `1px solid ${theme.palette.primary.main} !important`,
},
"& .MuiSelect-icon": {
color: theme.palette.primary.main,
},
}}
MenuProps={{
PaperProps: {
sx: {
mt: "8px",
p: "4px",
borderRadius: "8px",
border: "1px solid #EEE4FC",
boxShadow: "0px 8px 24px rgba(210, 208, 225, 0.4)",
backgroundColor: theme.palette.background.default,
},
},
MenuListProps: {
sx: {
py: 0,
display: "flex",
flexDirection: "column",
gap: "8px",
"& .Mui-selected": {
backgroundColor: theme.palette.background.default,
color: theme.palette.primary.main,
},
},
},
}}
inputProps={{
sx: {
color: theme.palette.primary.main,
display: "block",
px: "9px",
gap: "20px",
width: "87%",
overflow: "hidden",
textOverflow: "ellipsis",
},
}}
>
{questions
.filter((q) => q.type !== "result")
.map((question, index) => (
<MenuItem
key={question.id}
value={question.id}
2024-04-11 14:11:43 +00:00
sx={{
2024-05-31 16:41:18 +00:00
display: "flex",
alignItems: "center",
gap: "20px",
p: "4px",
borderRadius: "5px",
color: "#9A9AAF",
wordBreak: "break-word",
whiteSpace: "normal",
2024-04-11 14:11:43 +00:00
}}
2024-05-31 16:41:18 +00:00
>
{`${index + 1}. ${question.title}`}
</MenuItem>
))}
</MuiSelect>
</FormControl>
</Box>
);
2024-04-11 14:11:43 +00:00
}