117 lines
3.9 KiB
TypeScript
117 lines
3.9 KiB
TypeScript
import { useParams } from "react-router-dom";
|
||
import { Box, Typography } from "@mui/material";
|
||
import ButtonsOptions from "../ButtonsOptions";
|
||
import React from "react";
|
||
import CustomNumberField from "@ui_kit/CustomNumberField";
|
||
import SwitchSlider from "./switchSlider";
|
||
import { questionStore, updateQuestionsList } from "@root/questions";
|
||
|
||
interface Props {
|
||
totalIndex: number;
|
||
}
|
||
|
||
export default function SliderOptions({ totalIndex }: Props) {
|
||
const [switchState, setSwitchState] = React.useState("setting");
|
||
const quizId = Number(useParams().quizId);
|
||
const { listQuestions } = questionStore();
|
||
|
||
const SSHC = (data: string) => {
|
||
setSwitchState(data);
|
||
};
|
||
|
||
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" }}>
|
||
<CustomNumberField
|
||
placeholder={"0"}
|
||
text={
|
||
listQuestions[quizId][totalIndex].content.range.split("—")[0]
|
||
}
|
||
onChange={({ target }) => {
|
||
const clonContent = listQuestions[quizId][totalIndex].content;
|
||
clonContent.range = `${target.value}—${
|
||
listQuestions[quizId][totalIndex].content.range.split("—")[1]
|
||
}`;
|
||
updateQuestionsList(quizId, totalIndex, {
|
||
content: clonContent,
|
||
});
|
||
}}
|
||
/>
|
||
<Typography>—</Typography>
|
||
<CustomNumberField
|
||
placeholder={"100"}
|
||
text={
|
||
listQuestions[quizId][totalIndex].content.range.split("—")[1]
|
||
}
|
||
onChange={({ target }) => {
|
||
const clonContent = listQuestions[quizId][totalIndex].content;
|
||
clonContent.range = `${
|
||
listQuestions[quizId][totalIndex].content.range.split("—")[0]
|
||
}—${target.value}`;
|
||
updateQuestionsList(quizId, totalIndex, {
|
||
content: clonContent,
|
||
});
|
||
}}
|
||
/>
|
||
</Box>
|
||
</Box>
|
||
<Box
|
||
sx={{
|
||
display: "flex",
|
||
alignItems: "center",
|
||
justifyContent: "space-between",
|
||
gap: "50px",
|
||
}}
|
||
>
|
||
<Box sx={{ width: "100%" }}>
|
||
<Typography>Начальное значение</Typography>
|
||
<CustomNumberField
|
||
placeholder={"50"}
|
||
text={String(listQuestions[quizId][totalIndex].content.start)}
|
||
onChange={({ target }) => {
|
||
const clonContent = listQuestions[quizId][totalIndex].content;
|
||
clonContent.start = Number(target.value);
|
||
updateQuestionsList(quizId, totalIndex, {
|
||
content: clonContent,
|
||
});
|
||
}}
|
||
/>
|
||
</Box>
|
||
<Box sx={{ width: "100%" }}>
|
||
<Typography>Шаг</Typography>
|
||
<CustomNumberField
|
||
placeholder={"1"}
|
||
text={String(listQuestions[quizId][totalIndex].content.step)}
|
||
onChange={({ target }) => {
|
||
const clonContent = listQuestions[quizId][totalIndex].content;
|
||
clonContent.step = Number(target.value);
|
||
updateQuestionsList(quizId, totalIndex, {
|
||
content: clonContent,
|
||
});
|
||
}}
|
||
/>
|
||
</Box>
|
||
</Box>
|
||
</Box>
|
||
<ButtonsOptions
|
||
switchState={switchState}
|
||
SSHC={SSHC}
|
||
totalIndex={totalIndex}
|
||
/>
|
||
<SwitchSlider switchState={switchState} totalIndex={totalIndex} />
|
||
</>
|
||
);
|
||
}
|