UNPKG

@undermuz/react-json-form

Version:
89 lines (88 loc) 2.73 kB
// src/flat-form/form-input/input.tsx import { noop } from "underscore"; import { EnumSchemeItemType } from "../../types.mjs"; import { useJsonFormUi } from "../../contexts/ui.mjs"; import InputWidget from "../../inputs/inputWIdget.mjs"; import { useJsonFormCustomComponents } from "../../custom-components/context.mjs"; import { InputSelect } from "./input-select.mjs"; import { jsx } from "react/jsx-runtime"; var Input = (props) => { const { name, value = "", type, title, settings = {}, children, onFormsRef } = props; const { onChange = noop, onError = noop } = props; const Ui = useJsonFormUi(); const customComponents = useJsonFormCustomComponents(); try { if (type == EnumSchemeItemType.Files) { if (!Ui?.Controls?.FileInput) { console.error("No Ui.Controls.FileInput provided"); return null; } return /* @__PURE__ */ jsx(Ui.Controls.FileInput, { ...props }); } if (type == EnumSchemeItemType.Widget) { return /* @__PURE__ */ jsx( InputWidget, { name, value, title, settings, onRef: onFormsRef, onChange, onError, children } ); } if (type == EnumSchemeItemType.Select) { return /* @__PURE__ */ jsx(InputSelect, { ...props }); } if (type === EnumSchemeItemType.Date) { if (!Ui?.Controls?.Date) { console.error("No Ui.Controls.Date provided"); return null; } return /* @__PURE__ */ jsx(Ui.Controls.Date, { ...props }); } if (type === EnumSchemeItemType.Checkbox) { if (!Ui?.Controls?.CheckBox) { console.error("No Ui.Controls.CheckBox provided"); return null; } return /* @__PURE__ */ jsx(Ui.Controls.CheckBox, { ...props }); } if (type == EnumSchemeItemType.TextBlock) { if (!Ui?.Controls?.TextBlock) { console.error("No Ui.Controls.TextBlock provided"); return null; } return /* @__PURE__ */ jsx(Ui.Controls.TextBlock, { ...props }); } if (customComponents && customComponents[type]) { const CustomCmp = customComponents[type]; if (CustomCmp) return /* @__PURE__ */ jsx(CustomCmp, { ...props }); } if (!Ui?.Controls?.Input) { console.error("No Ui.Controls.Input provided"); return null; } return /* @__PURE__ */ jsx(Ui.Controls.Input, { ...props }); } catch (e) { console.error(`Error <Input {...${JSON.stringify(props)} }>:`); console.error(e); return /* @__PURE__ */ jsx("div", { className: "alert alert-danger", children: e.message }); } }; var input_default = Input; export { input_default as default };