formik-mui
Version:
36 lines (35 loc) • 852 B
JavaScript
import { jsx } from "react/jsx-runtime";
import MuiSwitch from "@mui/material/Switch";
import invariant from "tiny-warning";
function fieldToSwitch({
disabled,
field: { onBlur: fieldOnBlur, ...field },
form: { isSubmitting },
type,
onBlur,
...props
}) {
if (process.env.NODE_ENV !== "production") {
invariant(
type === "checkbox",
`property type=checkbox is missing from field ${field.name}, this can caused unexpected behaviour`
);
}
return {
disabled: disabled ?? isSubmitting,
onBlur: onBlur ?? function(e) {
fieldOnBlur(e ?? field.name);
},
...field,
...props
};
}
function Switch(props) {
return /* @__PURE__ */ jsx(MuiSwitch, { ...fieldToSwitch(props) });
}
Switch.displayName = "FormikMaterialUISwitch";
export {
Switch,
fieldToSwitch
};
//# sourceMappingURL=Switch.js.map