formik-mui
Version:
49 lines (48 loc) • 1.59 kB
JavaScript
import { jsxs, jsx } from "react/jsx-runtime";
import { getIn } from "formik";
import FormControl from "@mui/material/FormControl";
import InputLabel from "@mui/material/InputLabel";
import Input from "@mui/material/Input";
import FormHelperText from "@mui/material/FormHelperText";
const SimpleFileUpload = ({
field,
form: { isSubmitting, touched, errors, setFieldValue },
label,
accept,
disabled = false,
InputProps: inputProps,
InputLabelProps: inputLabelProps,
FormControlProps: formControlProps
}) => {
const error = getIn(touched, field.name) && getIn(errors, field.name);
return /* @__PURE__ */ jsxs(FormControl, { ...formControlProps, children: [
label && /* @__PURE__ */ jsx(InputLabel, { shrink: true, error: !!error, ...inputLabelProps, children: label }),
/* @__PURE__ */ jsx(
Input,
{
error: !!error,
inputProps: {
type: "file",
accept,
disabled: disabled || isSubmitting,
name: field.name,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onChange: (event) => {
if (inputProps == null ? void 0 : inputProps.onChange) {
inputProps.onChange(event);
} else {
const file = event.currentTarget.files[0];
setFieldValue(field.name, file);
}
}
},
...inputProps
}
),
error && /* @__PURE__ */ jsx(FormHelperText, { error: true, children: error })
] });
};
export {
SimpleFileUpload
};
//# sourceMappingURL=SimpleFileUpload.js.map