frontPanel/src/pages/Questions/SliderOptions/SliderOptions.tsx

117 lines
3.9 KiB
TypeScript
Raw Normal View History

2023-09-06 13:20:12 +00:00
import { useParams } from "react-router-dom";
import { Box, Typography } from "@mui/material";
import ButtonsOptions from "../ButtonsOptions";
import React from "react";
2023-09-12 14:36:22 +00:00
import CustomNumberField from "@ui_kit/CustomNumberField";
import SwitchSlider from "./switchSlider";
2023-09-06 08:01:44 +00:00
import { questionStore, updateQuestionsList } from "@root/questions";
2023-08-24 11:09:47 +00:00
interface Props {
totalIndex: number;
}
2023-08-24 11:09:47 +00:00
export default function SliderOptions({ totalIndex }: Props) {
const [switchState, setSwitchState] = React.useState("setting");
2023-09-06 13:20:12 +00:00
const quizId = Number(useParams().quizId);
2023-09-06 08:01:44 +00:00
const { listQuestions } = questionStore();
2023-09-06 13:20:12 +00:00
2023-08-24 11:09:47 +00:00
const SSHC = (data: string) => {
setSwitchState(data);
};
2023-08-24 11:09:47 +00:00
return (
<>
<Box
sx={{
width: "100%",
maxWidth: "640px",
display: "flex",
padding: "20px",
flexDirection: "column",
gap: "20px",
}}
>
<Box sx={{ gap: "10px", display: "flex", flexDirection: "column" }}>
<Typography>Выбор значения из диапазона</Typography>
<Box sx={{ display: "flex", alignItems: "center", gap: "20px" }}>
2023-09-12 14:36:22 +00:00
<CustomNumberField
2023-09-06 08:01:44 +00:00
placeholder={"0"}
2023-09-06 13:20:12 +00:00
text={
listQuestions[quizId][totalIndex].content.range.split("—")[0]
}
2023-09-06 08:01:44 +00:00
onChange={({ target }) => {
2023-09-06 13:20:12 +00:00
const clonContent = listQuestions[quizId][totalIndex].content;
2023-09-06 08:01:44 +00:00
clonContent.range = `${target.value}${
2023-09-06 13:20:12 +00:00
listQuestions[quizId][totalIndex].content.range.split("—")[1]
2023-09-06 08:01:44 +00:00
}`;
2023-09-06 13:20:12 +00:00
updateQuestionsList(quizId, totalIndex, {
content: clonContent,
});
2023-09-06 08:01:44 +00:00
}}
/>
2023-08-24 11:09:47 +00:00
<Typography></Typography>
2023-09-12 14:36:22 +00:00
<CustomNumberField
2023-09-06 08:01:44 +00:00
placeholder={"100"}
2023-09-06 13:20:12 +00:00
text={
listQuestions[quizId][totalIndex].content.range.split("—")[1]
}
2023-09-06 08:01:44 +00:00
onChange={({ target }) => {
2023-09-06 13:20:12 +00:00
const clonContent = listQuestions[quizId][totalIndex].content;
2023-09-06 08:01:44 +00:00
clonContent.range = `${
2023-09-06 13:20:12 +00:00
listQuestions[quizId][totalIndex].content.range.split("—")[0]
2023-09-06 08:01:44 +00:00
}${target.value}`;
2023-09-06 13:20:12 +00:00
updateQuestionsList(quizId, totalIndex, {
content: clonContent,
});
2023-09-06 08:01:44 +00:00
}}
/>
2023-08-24 11:09:47 +00:00
</Box>
</Box>
<Box
sx={{
display: "flex",
alignItems: "center",
justifyContent: "space-between",
2023-09-12 14:36:22 +00:00
gap: "50px",
2023-08-24 11:09:47 +00:00
}}
>
2023-09-12 14:36:22 +00:00
<Box sx={{ width: "100%" }}>
2023-08-24 11:09:47 +00:00
<Typography>Начальное значение</Typography>
2023-09-12 14:36:22 +00:00
<CustomNumberField
2023-09-06 08:01:44 +00:00
placeholder={"50"}
2023-09-06 13:20:12 +00:00
text={String(listQuestions[quizId][totalIndex].content.start)}
2023-09-06 08:01:44 +00:00
onChange={({ target }) => {
2023-09-06 13:20:12 +00:00
const clonContent = listQuestions[quizId][totalIndex].content;
2023-09-06 08:01:44 +00:00
clonContent.start = Number(target.value);
2023-09-06 13:20:12 +00:00
updateQuestionsList(quizId, totalIndex, {
content: clonContent,
});
2023-09-06 08:01:44 +00:00
}}
/>
2023-08-24 11:09:47 +00:00
</Box>
2023-09-12 14:36:22 +00:00
<Box sx={{ width: "100%" }}>
2023-08-24 11:09:47 +00:00
<Typography>Шаг</Typography>
2023-09-12 14:36:22 +00:00
<CustomNumberField
2023-09-06 08:01:44 +00:00
placeholder={"1"}
2023-09-06 13:20:12 +00:00
text={String(listQuestions[quizId][totalIndex].content.step)}
2023-09-06 08:01:44 +00:00
onChange={({ target }) => {
2023-09-06 13:20:12 +00:00
const clonContent = listQuestions[quizId][totalIndex].content;
2023-09-06 08:01:44 +00:00
clonContent.step = Number(target.value);
2023-09-06 13:20:12 +00:00
updateQuestionsList(quizId, totalIndex, {
content: clonContent,
});
2023-09-06 08:01:44 +00:00
}}
/>
2023-08-24 11:09:47 +00:00
</Box>
</Box>
</Box>
<ButtonsOptions
switchState={switchState}
SSHC={SSHC}
totalIndex={totalIndex}
/>
<SwitchSlider switchState={switchState} totalIndex={totalIndex} />
</>
);
}