@braineet/ui
Version:
Braineet design system
43 lines • 1.9 kB
JavaScript
var _excluded = ["initialValues", "onSubmit", "onReset", "validate", "enableReinitialize", "focusOnError", "children"];
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
import React from 'react';
import { Formik, useFormikContext, getIn } from 'formik';
import FocusError from './FocusError';
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
var Form = function Form(_ref) {
var initialValues = _ref.initialValues,
onSubmit = _ref.onSubmit,
onReset = _ref.onReset,
validate = _ref.validate,
enableReinitialize = _ref.enableReinitialize,
focusOnError = _ref.focusOnError,
_children = _ref.children,
restProps = _objectWithoutPropertiesLoose(_ref, _excluded);
return /*#__PURE__*/_jsx(Formik, _extends({
initialValues: initialValues,
onSubmit: onSubmit,
onReset: onReset,
validate: validate,
enableReinitialize: enableReinitialize
}, restProps, {
children: function children(props) {
return /*#__PURE__*/_jsxs(_Fragment, {
children: [focusOnError && /*#__PURE__*/_jsx(FocusError, {}), _children(props)]
});
}
}));
};
Form.defaultProps = {
initialValues: {},
enableReinitialize: false,
focusOnError: true,
onSubmit: function onSubmit() {},
onReset: function onReset() {},
validate: function validate() {}
};
export var useForm = function useForm() {
return useFormikContext();
};
export var getFieldValue = getIn;
export default Form;