import { ToggleButton, ToggleButtonGroup } from "@mui/material"; import { CheckboxOption } from "interface/CheckboxOptions"; import React, { memo, useCallback } from "react"; import { makeStylesEdt } from "../../theme"; import { important } from "../../utils"; export type CheckboxOneProps = { handleChange(response: { [name: string]: string }, value: boolean): void; id?: string; label?: string; options: CheckboxOption[]; value: { [key: string]: boolean }; className?: string; }; const CheckboxOne = memo((props: CheckboxOneProps) => { const { id, value, label, options, className, handleChange } = props; const { classes } = useStyles(); const preSelectedValue: string | undefined = Object.keys(value).find(i => value[i] === true); const [currentOption, setCurrentOption] = React.useState(preSelectedValue); const handleOptions = useCallback( (_event: React.MouseEvent, selectedOption: string) => { setCurrentOption(selectedOption); value[selectedOption] = !value[selectedOption]; handleChange({ name: selectedOption }, value[selectedOption]); }, [], ); return ( {options.map(option => ( {option.label} ))} ); }); const useStyles = makeStylesEdt({ "name": { CheckboxOne } })(theme => ({ "MuiToggleButton": { marginBottom: "0.5rem", border: important("2px solid #FFFFFF"), borderRadius: important("6px"), backgroundColor: "#FFFFFF", color: theme.palette.primary.main, "&.Mui-selected": { borderColor: important(theme.palette.primary.main), fontWeight: "bold", backgroundColor: "#FFFFFF", color: theme.palette.primary.main, }, }, })); export default CheckboxOne;