import React, { useEffect, useRef, useState } from "react"; import classnames from "classnames"; import "./index.scss"; import useOutsideClick from "../../../_helpers/customHook/useOutsideClick"; import { PresentToAllSharp } from "@material-ui/icons"; // interface Props { // value: OptionInputRadio; // setValue: (..._args: any[]) => void; // label: string; // className?: string; // options: OptionInputRadio[]; // inputEditable?: boolean; // placeholder: string; // isWarning?: boolean; // setIsWarning?: (..._args: any[]) => void; // disabledClick?: boolean; // } const InputRadio = (props) => { const [isOpen, setIsOpen] = useState(false); const $selectRef = useRef(null); const isOpenCached = useRef(null); useEffect(() => { isOpenCached.current = isOpen; }, [isOpen]); useOutsideClick($selectRef, () => { if (isOpenCached.current) { setIsOpen(false); } }); // console.log(props.value); return (
{props.errorText && props?.typeErrText != "underAbsolute" ? (
{props.errorText}
) : null}
{ props.isWarning && props.setIsWarning(false); props.setErrorText && props.setErrorText(""); if (!props.disabledClick) { setIsOpen(!isOpen); } else { props.onClickDisable && props.onClickDisable(); } }} >
{props.label ? {props.label} : null}
{props.renderLabelIcon ? props.renderLabelIcon() : null}
{ if (props.inputEditable) { props.setValue({ value: e.target?.value, title: e.target?.value, }); } }} style={props.inputEditable ? {} : { pointerEvents: "none" }} >
{props.options.map((option) => { return (
{ props.setValue(option); setIsOpen(false); }} > {option.title}
); })}
{props.errorText && props?.typeErrText == "underAbsolute" ? (
{props.errorText}
) : null}
); }; export default InputRadio;