@etsoo/materialui
Version:
TypeScript Material-UI Implementation
35 lines (34 loc) • 1.42 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldInput = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
const InputField_1 = require("../InputField");
const Typography_1 = __importDefault(require("@mui/material/Typography"));
/**
* Input field creator
* type: input
* @returns Component
*/
const FieldInput = ({ field, mref, onChange, defaultValue }) => {
// Ref
const inputRef = react_1.default.useRef();
const getValue = () => inputRef.current?.value;
react_1.default.useImperativeHandle(mref, () => ({
getValue,
setValue(value) {
if (inputRef.current)
inputRef.current.value = `${value ?? ""}`;
}
}));
// Name
const name = field.name;
if (!name) {
return ((0, jsx_runtime_1.jsxs)(Typography_1.default, { children: ["No name for FieldInput ", JSON.stringify(field)] }));
}
return ((0, jsx_runtime_1.jsx)(InputField_1.InputField, { label: field.label ?? "", helperText: field.helperText, inputRef: inputRef, name: name, fullWidth: true, defaultValue: defaultValue, onChange: () => onChange(name, getValue()), ...field.mainSlotProps }));
};
exports.FieldInput = FieldInput;