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

139 lines
3.7 KiB
TypeScript
Raw Normal View History

2023-09-18 12:34:41 +00:00
import {
2023-12-31 02:53:25 +00:00
Box,
Button,
Typography,
useMediaQuery,
useTheme,
2023-09-18 12:34:41 +00:00
} from "@mui/material";
import { updateQuestion } from "@root/questions/actions";
import CustomCheckbox from "@ui_kit/CustomCheckbox";
import ProportionsIcon11 from "../../../assets/icons/questionsPage/ProportionsIcon11";
import ProportionsIcon12 from "../../../assets/icons/questionsPage/ProportionsIcon12";
import ProportionsIcon21 from "../../../assets/icons/questionsPage/ProportionsIcon21";
2023-10-03 14:03:57 +00:00
import type { QuizQuestionImages } from "../../../model/questionTypes/images";
import { memo } from "react";
2023-10-03 14:03:57 +00:00
2023-10-04 11:35:02 +00:00
type Proportion = "1:1" | "2:1" | "1:2";
type ProportionItem = {
2023-12-31 02:53:25 +00:00
value: Proportion;
icon: (props: { color: string }) => JSX.Element;
2023-10-04 11:35:02 +00:00
};
const PROPORTIONS: ProportionItem[] = [
2023-12-31 02:53:25 +00:00
{ value: "1:1", icon: ProportionsIcon11 },
{ value: "2:1", icon: ProportionsIcon21 },
{ value: "1:2", icon: ProportionsIcon12 },
2023-08-28 09:31:34 +00:00
];
type SettingOpytionsPictProps = {
questionId: string;
isRequired: boolean;
};
const SettingOptionsPict = memo<SettingOpytionsPictProps>(function ({
questionId,
isRequired,
}) {
2023-12-31 02:53:25 +00:00
const theme = useTheme();
const isTablet = useMediaQuery(theme.breakpoints.down(985));
const isMobile = useMediaQuery(theme.breakpoints.down(790));
const isFigmaTablte = useMediaQuery(theme.breakpoints.down(990));
2023-09-25 13:43:15 +00:00
2023-12-31 02:53:25 +00:00
return (
<Box
sx={{
display: "flex",
justifyContent: "space-between",
flexDirection: isTablet ? "column" : null,
marginRight: isFigmaTablte ? (isMobile ? "0" : "0px") : "30px",
}}
>
2023-12-31 02:53:25 +00:00
<Box
sx={{
pt: isMobile ? "25px" : "20px",
pb: isMobile ? "25px" : "20px",
pl: "20px",
pr: isFigmaTablte ? (isMobile ? "20px" : "0px") : "28px",
2023-12-31 02:53:25 +00:00
display: "flex",
flexDirection: "column",
gap: "14px",
width: "100%",
2023-12-31 02:53:25 +00:00
}}
>
<Typography
sx={{ fontWeight: "500", fontSize: "18px", color: " #4D4D4D" }}
2023-12-31 02:53:25 +00:00
>
Настройки вопросов
</Typography>
<CustomCheckbox
dataCy="checkbox-optional-question"
sx={{ alignItems: isMobile ? "flex-start" : "" }}
label={"Необязательный вопрос"}
checked={!isRequired}
handleChange={({ target }) =>
updateQuestion<QuizQuestionImages>(questionId, (question) => {
if (question.type !== "images") return;
question.content.required = !target.checked;
})
}
/>
2023-12-31 02:53:25 +00:00
</Box>
</Box>
2023-12-31 02:53:25 +00:00
);
});
SettingOptionsPict.displayName = "SettingOptionsPict";
export default SettingOptionsPict;
interface Props {
2023-12-31 02:53:25 +00:00
Icon: (props: { color: string }) => JSX.Element;
isActive?: boolean;
onClick: () => void;
}
2023-09-15 12:37:12 +00:00
export function SelectIconButton({ Icon, isActive = false, onClick }: Props) {
2023-12-31 02:53:25 +00:00
const theme = useTheme();
2023-08-28 09:31:34 +00:00
2023-12-31 02:53:25 +00:00
return (
<Button
onClick={onClick}
variant="outlined"
startIcon={
<Icon
color={
isActive
? theme.palette.navbarbg.main
: theme.palette.brightPurple.main
}
/>
2023-12-31 02:53:25 +00:00
}
sx={{
backgroundColor: isActive ? theme.palette.brightPurple.main : "#eee4fc",
borderRadius: 0,
border: "none",
color: isActive
? theme.palette.brightPurple.main
: theme.palette.grey2.main,
p: "7px",
width: "40px",
height: "40px",
minWidth: 0,
"& .MuiButton-startIcon": {
mr: 0,
ml: 0,
},
"&:hover": {
border: "none",
borderColor: isActive
? theme.palette.brightPurple.main
: theme.palette.grey2.main,
},
}}
/>
);
2023-04-15 09:10:59 +00:00
}