diff --git a/src/pages/Questions/Select.tsx b/src/pages/Questions/Select.tsx new file mode 100644 index 00000000..fd9dce72 --- /dev/null +++ b/src/pages/Questions/Select.tsx @@ -0,0 +1,109 @@ +import { useState } from "react"; +import { + Select as MuiSelect, + MenuItem, + FormControl, + useTheme, +} from "@mui/material"; + +import ArrowDown from "@icons/ArrowDownIcon"; + +import type { SelectChangeEvent, SxProps } from "@mui/material"; + +type SelectProps = { + items: string[]; + empty?: boolean; + onChange?: (num: number) => void; + sx?: SxProps; +}; + +export const Select = ({ items, empty, onChange, sx }: SelectProps) => { + const [activeItem, setActiveItem] = useState(empty ? -1 : 0); + + const theme = useTheme(); + + const handleChange = (event: SelectChangeEvent) => { + setActiveItem(Number(event.target.value)); + onChange?.(Number(event.target.value)); + }; + + return ( + + } + > + {items.map((item, index) => ( + + {item} + + ))} + + + ); +}; diff --git a/src/pages/Questions/branchingQuestions.tsx b/src/pages/Questions/branchingQuestions.tsx index 3f755570..83ea8230 100644 --- a/src/pages/Questions/branchingQuestions.tsx +++ b/src/pages/Questions/branchingQuestions.tsx @@ -5,26 +5,24 @@ import { FormControlLabel, IconButton, Link, - MenuItem, Modal, Radio, RadioGroup, - Select, - SelectChangeEvent, - TextField, Typography, useTheme, } from "@mui/material"; import * as React from "react"; -import ArrowDown from "@icons/ArrowDownIcon"; import { useState } from "react"; import { questionStore, resetSomeField } from "@root/questions"; +import { Select } from "./Select"; import DeleteIcon from "@icons/questionsPage/deleteIcon"; import RadioCheck from "@ui_kit/RadioCheck"; import RadioIcon from "@ui_kit/RadioIcon"; -import InfoIcon from "../../assets/icons/Info"; +import InfoIcon from "@icons/Info"; export default function BranchingQuestions() { + const [value, setValue] = useState("1"); + const [conditionSelected, setConditionSelected] = useState(false); const { openedModalSettings } = questionStore(); const theme = useTheme(); @@ -32,12 +30,6 @@ export default function BranchingQuestions() { const handleClose = () => { resetSomeField({ openedModalSettings: "" }); }; - const [display, setDisplay] = React.useState("1"); - const handleChange = (event: SelectChangeEvent) => { - setDisplay(event.target.value); - }; - - const [value, setValue] = React.useState("1"); const handleChangeRadio = (event: React.ChangeEvent) => { setValue((event.target as HTMLInputElement).value); @@ -92,90 +84,10 @@ export default function BranchingQuestions() { alignItems: "center", }} > - - - + + + )} ) : ( ""