frontPanel/src/pages/Questions/OptionsPicture/settingOpytionsPict.tsx

182 lines
5.5 KiB
TypeScript
Raw Normal View History

2023-08-28 09:31:34 +00:00
import { useEffect } from "react";
import { Box, Button, Typography, useTheme } from "@mui/material";
import CustomCheckbox from "@ui_kit/CustomCheckbox";
2023-08-28 09:31:34 +00:00
import { questionStore, updateQuestionsList } from "@root/questions";
import InfoIcon from "../../../assets/icons/InfoIcon";
import FormatIcon2 from "../../../assets/icons/questionsPage/FormatIcon2";
import FormatIcon1 from "../../../assets/icons/questionsPage/FormatIcon1";
import ProportionsIcon11 from "../../../assets/icons/questionsPage/ProportionsIcon11";
import ProportionsIcon21 from "../../../assets/icons/questionsPage/ProportionsIcon21";
import ProportionsIcon12 from "../../../assets/icons/questionsPage/ProportionsIcon12";
interface Props {
2023-04-15 09:10:59 +00:00
Icon: React.ElementType;
isActive?: boolean;
onClick: () => void;
}
2023-08-28 09:31:34 +00:00
type SettingOpytionsPictProps = {
totalIndex: number;
};
const PROPORTIONS = [
{ value: "1:1", icon: ProportionsIcon11 },
{ value: "2:1", icon: ProportionsIcon21 },
{ value: "1:2", icon: ProportionsIcon12 },
];
2023-04-15 09:10:59 +00:00
export function SelectIconButton({ Icon, isActive = false, onClick }: Props) {
const theme = useTheme();
return (
<Button
2023-04-15 09:10:59 +00:00
onClick={onClick}
variant="outlined"
2023-08-28 09:31:34 +00:00
startIcon={
<Icon
color={
isActive
? theme.palette.navbarbg.main
: theme.palette.brightPurple.main
}
/>
}
2023-04-15 09:10:59 +00:00
sx={{
backgroundColor: isActive ? theme.palette.brightPurple.main : "#eee4fc",
borderRadius: 0,
border: "none",
2023-08-28 09:31:34 +00:00
color: isActive
? theme.palette.brightPurple.main
: theme.palette.grey2.main,
2023-04-15 09:10:59 +00:00
p: "7px",
width: "auto",
minWidth: 0,
"& .MuiButton-startIcon": {
mr: 0,
ml: 0,
},
"&:hover": {
2023-04-23 08:39:34 +00:00
border: "none",
2023-08-28 09:31:34 +00:00
borderColor: isActive
? theme.palette.brightPurple.main
: theme.palette.grey2.main,
2023-04-15 09:10:59 +00:00
},
}}
/>
);
}
2023-08-28 09:31:34 +00:00
export default function SettingOpytionsPict({
totalIndex,
}: SettingOpytionsPictProps) {
const { listQuestions } = questionStore();
2023-08-28 09:31:34 +00:00
useEffect(() => {
if (!listQuestions[totalIndex].content.xy) {
updateProportions("1:1");
}
}, []);
const updateProportions = (proportions: string) => {
const clonContent = listQuestions[totalIndex].content;
clonContent.xy = proportions;
updateQuestionsList(totalIndex, { content: clonContent });
};
2023-04-15 09:10:59 +00:00
return (
<>
<Box sx={{ display: "flex" }}>
<Box sx={{ padding: "20px" }}>
<Typography sx={{ marginBottom: "15px" }}>Пропорции</Typography>
<Box
sx={{
display: "flex",
gap: "10px",
marginBottom: "20px",
}}
>
2023-08-28 09:31:34 +00:00
{PROPORTIONS.map(({ value, icon }, index) => (
<SelectIconButton
key={index}
onClick={() => updateProportions(value)}
isActive={listQuestions[totalIndex].content.xy === value}
Icon={icon}
/>
))}
2023-04-15 09:10:59 +00:00
</Box>
2023-08-28 09:31:34 +00:00
<Typography sx={{ marginBottom: "15px" }}>
Настройки ответов
</Typography>
<CustomCheckbox
label={"Можно несколько"}
checked={listQuestions[totalIndex].content.multi}
handleChange={() =>
updateQuestionsList(totalIndex, {
content: {
...listQuestions[totalIndex].content,
multi: !listQuestions[totalIndex].content.multi,
},
})
}
/>
<CustomCheckbox
label={"Большие картинки"}
2023-09-05 08:25:47 +00:00
checked={listQuestions[totalIndex].content.largeCheck}
2023-08-28 09:31:34 +00:00
handleChange={() =>
updateQuestionsList(totalIndex, {
content: {
...listQuestions[totalIndex].content,
2023-09-05 08:25:47 +00:00
largeCheck: !listQuestions[totalIndex].content.largeCheck,
2023-08-28 09:31:34 +00:00
},
})
}
/>
2023-04-15 09:10:59 +00:00
<CustomCheckbox label={'Вариант "свой ответ"'} />
</Box>
<Box sx={{ padding: "20px" }}>
<Typography sx={{ marginBottom: "15px" }}>Форма</Typography>
<Box
sx={{
display: "flex",
gap: "10px",
marginBottom: "20px",
}}
>
<SelectIconButton
2023-08-28 09:31:34 +00:00
onClick={() =>
updateQuestionsList(totalIndex, {
content: {
...listQuestions[totalIndex].content,
format: "carousel",
},
})
}
isActive={listQuestions[totalIndex].content.format === "carousel"}
Icon={FormatIcon2}
/>
<SelectIconButton
onClick={() =>
updateQuestionsList(totalIndex, {
content: {
...listQuestions[totalIndex].content,
format: "masonry",
},
})
}
isActive={listQuestions[totalIndex].content.format === "masonry"}
2023-04-15 09:10:59 +00:00
Icon={FormatIcon1}
/>
</Box>
2023-08-28 09:31:34 +00:00
<Typography sx={{ marginBottom: "15px" }}>
Настройки вопросов
</Typography>
2023-04-15 09:10:59 +00:00
<CustomCheckbox label={"Необязательный вопрос"} />
<CustomCheckbox label={"Внутреннее название вопроса"} /> <InfoIcon />
</Box>
</Box>
</>
);
}