import { useEffect } from "react"; import { FieldCheckbox } from "./field/TypeCheckbox"; import { TypeDropdown } from "./field/TypeDropdown"; import { TypeInput } from "./field/TypeInput"; import { TypeUpload } from "./field/TypeUpload"; import { FieldUploadMulti } from "./field/TypeUploadMulti"; export const Field: React.FC = ({ fm, label, name, onLoad, type, placeholder, required, disabled, hidden_label, onChange, className, style, }) => { let result = null; const is_disable = fm.mode === "view" ? true : disabled; const error = fm.error?.[name]; useEffect(() => { if (typeof fm.fields?.[name] !== "object") { const fields = fm.fields?.[name]; fm.fields[name] = { ...fields, label, name, onLoad, type, placeholder, required, disabled, hidden_label, onChange, className, style, }; fm.render(); } }, []); return ( <>
{!hidden_label ? ( ) : ( <> )}
{["upload"].includes(type) ? ( <> ) : ["multi-upload"].includes(type) ? ( <> ) : ["dropdown"].includes(type) ? ( <> ) : ["multi-dropdown"].includes(type) ? ( <> ) : ["checkbox"].includes(type) ? ( <> ) : ["single-checkbox"].includes(type) ? ( <> ) : ( <> )}
{error ? (
{error}
) : ( <> )}
); };