frontPanel/src/pages/Questions/OwnTextField/OwnTextField.tsx

79 lines
2.3 KiB
TypeScript
Raw Normal View History

2023-08-25 08:29:42 +00:00
import { useState } from "react";
2023-09-06 13:20:12 +00:00
import { useParams } from "react-router-dom";
2023-09-18 12:34:41 +00:00
import { Box, Typography, Tooltip, useTheme } from "@mui/material";
2023-08-25 08:29:42 +00:00
import CustomTextField from "@ui_kit/CustomTextField";
import ButtonsOptions from "../ButtonsOptions";
import SwitchTextField from "./switchTextField";
2023-08-25 08:29:42 +00:00
import { questionStore, updateQuestionsList } from "@root/questions";
import InfoIcon from "../../../assets/icons/InfoIcon";
2023-08-25 08:29:42 +00:00
import type { ChangeEvent } from "react";
interface Props {
2023-08-24 11:09:47 +00:00
totalIndex: number;
}
export default function OwnTextField({ totalIndex }: Props) {
2023-08-25 08:29:42 +00:00
const [switchState, setSwitchState] = useState("setting");
2023-09-06 13:20:12 +00:00
const quizId = Number(useParams().quizId);
2023-08-25 08:29:42 +00:00
const { listQuestions } = questionStore();
2023-08-24 11:09:47 +00:00
const theme = useTheme();
2023-08-25 08:29:42 +00:00
2023-08-24 11:09:47 +00:00
const SSHC = (data: string) => {
setSwitchState(data);
};
2023-08-25 08:29:42 +00:00
2023-08-24 11:09:47 +00:00
return (
<>
<Box
sx={{
2023-09-15 12:37:12 +00:00
width: "auto",
maxWidth: "745px",
2023-08-24 11:09:47 +00:00
display: "flex",
padding: "20px",
flexDirection: "column",
gap: "20px",
}}
>
2023-08-25 08:29:42 +00:00
<CustomTextField
placeholder={"Пример ответа"}
2023-09-06 13:20:12 +00:00
text={listQuestions[quizId][totalIndex].content.placeholder}
2023-08-25 08:29:42 +00:00
onChange={({ target }: ChangeEvent<HTMLInputElement>) => {
2023-09-06 13:20:12 +00:00
const clonContent = listQuestions[quizId][totalIndex].content;
2023-08-25 08:29:42 +00:00
clonContent.placeholder = target.value;
2023-09-06 13:20:12 +00:00
updateQuestionsList(quizId, totalIndex, { content: clonContent });
2023-08-25 08:29:42 +00:00
}}
/>
2023-08-24 11:09:47 +00:00
<Box sx={{ display: "flex", alignItems: "center", gap: "12px" }}>
<Typography
sx={{
fontWeight: 400,
fontSize: "16px",
lineHeight: "18.96px",
color: theme.palette.grey2.main,
}}
>
Пользователю будет дано поле для ввода значения{" "}
</Typography>
2023-09-18 12:34:41 +00:00
<Tooltip
title="Будет использоваться для ввода значения."
placement="top"
>
<Box>
<InfoIcon />
</Box>
</Tooltip>
2023-08-24 11:09:47 +00:00
</Box>
</Box>
2023-09-18 12:34:41 +00:00
<ButtonsOptions
switchState={switchState}
SSHC={SSHC}
totalIndex={totalIndex}
/>
2023-08-24 11:09:47 +00:00
<SwitchTextField switchState={switchState} totalIndex={totalIndex} />
</>
);
}