@geoinsight/react-components 0.6.9 → 0.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +10 -5
- package/dist/esm/index.js +10 -5
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -187,6 +187,7 @@ const AccordionContent = function AccordionContent({ children, label, toggle, })
|
|
|
187
187
|
toggle[label].isToggle && (jsxRuntime.jsx("div", { className: "accordion-content", children: children })));
|
|
188
188
|
};
|
|
189
189
|
|
|
190
|
+
// how do I solve reseting the form outside the form
|
|
190
191
|
function Form({ children, onSubmit, submitButton = {
|
|
191
192
|
label: "Submit",
|
|
192
193
|
}, ...rest }) {
|
|
@@ -196,7 +197,7 @@ function Form({ children, onSubmit, submitButton = {
|
|
|
196
197
|
message: "",
|
|
197
198
|
isSuccess: false,
|
|
198
199
|
});
|
|
199
|
-
return (jsxRuntime.jsx(reactHookForm.FormProvider, { ...methods, children: jsxRuntime.jsxs("form", { className: "form", onSubmit: methods.handleSubmit((data) => onSubmit(data, setResult)), ...rest, children: [children, result.message && (jsxRuntime.jsxs("div", { className: "form__message", children: [result.isSuccess ? (jsxRuntime.jsx(bs.BsCheckCircleFill, { color: "var(--color-success)", size: 48 })) : (jsxRuntime.jsx(bs.BsXCircleFill, { color: "var(--color-danger)", size: 48 })), result.message] })), jsxRuntime.jsx(Button, { type: "submit", disabled: !isValid, children: submitButton.label })] }) }));
|
|
200
|
+
return (jsxRuntime.jsx(reactHookForm.FormProvider, { ...methods, children: jsxRuntime.jsxs("form", { className: "form", onSubmit: methods.handleSubmit((data) => onSubmit(data, methods, setResult)), ...rest, children: [children, result.message && (jsxRuntime.jsxs("div", { className: "form__message", children: [result.isSuccess ? (jsxRuntime.jsx(bs.BsCheckCircleFill, { color: "var(--color-success)", size: 48 })) : (jsxRuntime.jsx(bs.BsXCircleFill, { color: "var(--color-danger)", size: 48 })), result.message] })), jsxRuntime.jsx(Button, { type: "submit", disabled: !isValid, children: submitButton.label })] }) }));
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
function Input({ inputClassName = "", classNameGroup = "", error = {
|
|
@@ -264,7 +265,7 @@ function FormTextArea({ name, isRequired, error, ...rest }) {
|
|
|
264
265
|
|
|
265
266
|
function Select({ inputClassName = "", classNameGroup = "", options, styleGroup, defaultValue,
|
|
266
267
|
// inputProps,
|
|
267
|
-
setFormSelected, clearError, onFormBlur, handleSelect, ...rest }) {
|
|
268
|
+
setFormSelected, clearError, resetForm, onFormBlur, handleSelect, ...rest }) {
|
|
268
269
|
const [isOpen, setIsOpen] = react.useState(false);
|
|
269
270
|
const [value, setValue] = react.useState(defaultValue || (options && options[0]));
|
|
270
271
|
const [filteredOptions, setFilteredOptions] = react.useState(options);
|
|
@@ -298,6 +299,9 @@ setFormSelected, clearError, onFormBlur, handleSelect, ...rest }) {
|
|
|
298
299
|
if (clearError) {
|
|
299
300
|
clearError(name);
|
|
300
301
|
}
|
|
302
|
+
if (resetForm) {
|
|
303
|
+
resetForm();
|
|
304
|
+
}
|
|
301
305
|
}
|
|
302
306
|
else {
|
|
303
307
|
setValue(value);
|
|
@@ -325,8 +329,9 @@ setFormSelected, clearError, onFormBlur, handleSelect, ...rest }) {
|
|
|
325
329
|
}, onFocus: handleOpen, onBlur: handleInputClose, onChange: handleValueChange, autoComplete: "off", ...rest }), isOpen && (jsxRuntime.jsx("div", { className: "select__box", children: filteredOptions.map((option, index) => (jsxRuntime.jsx(Button, { type: "button", mode: "secondary", className: "select__option", name: option, onMouseDown: handleSelectChange, children: option }, `index-${index}`))) }))] }));
|
|
326
330
|
}
|
|
327
331
|
|
|
328
|
-
function FormSelect({ name, isRequired, error, ...rest }) {
|
|
329
|
-
const { control, setValue, clearErrors } = reactHookForm.useFormContext();
|
|
332
|
+
function FormSelect({ name, isRequired, error, fieldsToReset, ...rest }) {
|
|
333
|
+
const { control, setValue, clearErrors, unregister } = reactHookForm.useFormContext();
|
|
334
|
+
console.log(fieldsToReset);
|
|
330
335
|
return (jsxRuntime.jsx(reactHookForm.Controller, { name: name, control: control, rules: {
|
|
331
336
|
...(isRequired
|
|
332
337
|
? {
|
|
@@ -337,7 +342,7 @@ function FormSelect({ name, isRequired, error, ...rest }) {
|
|
|
337
342
|
return (jsxRuntime.jsx(Select, { isRequired: true, error: {
|
|
338
343
|
is: !!error,
|
|
339
344
|
message: error?.message,
|
|
340
|
-
}, setFormSelected: setValue, clearError: clearErrors, onFormBlur: onBlur, ...restField, ...rest }));
|
|
345
|
+
}, setFormSelected: setValue, resetForm: () => fieldsToReset && fieldsToReset.map((field) => unregister(field)), clearError: clearErrors, onFormBlur: onBlur, ...restField, ...rest }));
|
|
341
346
|
} }));
|
|
342
347
|
}
|
|
343
348
|
|
package/dist/esm/index.js
CHANGED
|
@@ -185,6 +185,7 @@ const AccordionContent = function AccordionContent({ children, label, toggle, })
|
|
|
185
185
|
toggle[label].isToggle && (jsx("div", { className: "accordion-content", children: children })));
|
|
186
186
|
};
|
|
187
187
|
|
|
188
|
+
// how do I solve reseting the form outside the form
|
|
188
189
|
function Form({ children, onSubmit, submitButton = {
|
|
189
190
|
label: "Submit",
|
|
190
191
|
}, ...rest }) {
|
|
@@ -194,7 +195,7 @@ function Form({ children, onSubmit, submitButton = {
|
|
|
194
195
|
message: "",
|
|
195
196
|
isSuccess: false,
|
|
196
197
|
});
|
|
197
|
-
return (jsx(FormProvider, { ...methods, children: jsxs("form", { className: "form", onSubmit: methods.handleSubmit((data) => onSubmit(data, setResult)), ...rest, children: [children, result.message && (jsxs("div", { className: "form__message", children: [result.isSuccess ? (jsx(BsCheckCircleFill, { color: "var(--color-success)", size: 48 })) : (jsx(BsXCircleFill, { color: "var(--color-danger)", size: 48 })), result.message] })), jsx(Button, { type: "submit", disabled: !isValid, children: submitButton.label })] }) }));
|
|
198
|
+
return (jsx(FormProvider, { ...methods, children: jsxs("form", { className: "form", onSubmit: methods.handleSubmit((data) => onSubmit(data, methods, setResult)), ...rest, children: [children, result.message && (jsxs("div", { className: "form__message", children: [result.isSuccess ? (jsx(BsCheckCircleFill, { color: "var(--color-success)", size: 48 })) : (jsx(BsXCircleFill, { color: "var(--color-danger)", size: 48 })), result.message] })), jsx(Button, { type: "submit", disabled: !isValid, children: submitButton.label })] }) }));
|
|
198
199
|
}
|
|
199
200
|
|
|
200
201
|
function Input({ inputClassName = "", classNameGroup = "", error = {
|
|
@@ -262,7 +263,7 @@ function FormTextArea({ name, isRequired, error, ...rest }) {
|
|
|
262
263
|
|
|
263
264
|
function Select({ inputClassName = "", classNameGroup = "", options, styleGroup, defaultValue,
|
|
264
265
|
// inputProps,
|
|
265
|
-
setFormSelected, clearError, onFormBlur, handleSelect, ...rest }) {
|
|
266
|
+
setFormSelected, clearError, resetForm, onFormBlur, handleSelect, ...rest }) {
|
|
266
267
|
const [isOpen, setIsOpen] = useState(false);
|
|
267
268
|
const [value, setValue] = useState(defaultValue || (options && options[0]));
|
|
268
269
|
const [filteredOptions, setFilteredOptions] = useState(options);
|
|
@@ -296,6 +297,9 @@ setFormSelected, clearError, onFormBlur, handleSelect, ...rest }) {
|
|
|
296
297
|
if (clearError) {
|
|
297
298
|
clearError(name);
|
|
298
299
|
}
|
|
300
|
+
if (resetForm) {
|
|
301
|
+
resetForm();
|
|
302
|
+
}
|
|
299
303
|
}
|
|
300
304
|
else {
|
|
301
305
|
setValue(value);
|
|
@@ -323,8 +327,9 @@ setFormSelected, clearError, onFormBlur, handleSelect, ...rest }) {
|
|
|
323
327
|
}, onFocus: handleOpen, onBlur: handleInputClose, onChange: handleValueChange, autoComplete: "off", ...rest }), isOpen && (jsx("div", { className: "select__box", children: filteredOptions.map((option, index) => (jsx(Button, { type: "button", mode: "secondary", className: "select__option", name: option, onMouseDown: handleSelectChange, children: option }, `index-${index}`))) }))] }));
|
|
324
328
|
}
|
|
325
329
|
|
|
326
|
-
function FormSelect({ name, isRequired, error, ...rest }) {
|
|
327
|
-
const { control, setValue, clearErrors } = useFormContext();
|
|
330
|
+
function FormSelect({ name, isRequired, error, fieldsToReset, ...rest }) {
|
|
331
|
+
const { control, setValue, clearErrors, unregister } = useFormContext();
|
|
332
|
+
console.log(fieldsToReset);
|
|
328
333
|
return (jsx(Controller, { name: name, control: control, rules: {
|
|
329
334
|
...(isRequired
|
|
330
335
|
? {
|
|
@@ -335,7 +340,7 @@ function FormSelect({ name, isRequired, error, ...rest }) {
|
|
|
335
340
|
return (jsx(Select, { isRequired: true, error: {
|
|
336
341
|
is: !!error,
|
|
337
342
|
message: error?.message,
|
|
338
|
-
}, setFormSelected: setValue, clearError: clearErrors, onFormBlur: onBlur, ...restField, ...rest }));
|
|
343
|
+
}, setFormSelected: setValue, resetForm: () => fieldsToReset && fieldsToReset.map((field) => unregister(field)), clearError: clearErrors, onFormBlur: onBlur, ...restField, ...rest }));
|
|
339
344
|
} }));
|
|
340
345
|
}
|
|
341
346
|
|