@geoinsight/react-components 0.6.9 → 0.6.11
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 +16 -9
- package/dist/esm/index.js +16 -9
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -187,16 +187,17 @@ 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
|
-
}, ...rest }) {
|
|
193
|
-
const methods = reactHookForm.useForm();
|
|
193
|
+
}, initialState, ...rest }) {
|
|
194
|
+
const methods = reactHookForm.useForm(initialState);
|
|
194
195
|
const { formState: { isValid }, } = methods;
|
|
195
196
|
const [result, setResult] = react.useState({
|
|
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 = {
|
|
@@ -208,7 +209,7 @@ function Input({ inputClassName = "", classNameGroup = "", error = {
|
|
|
208
209
|
icon.className), children: icon.element }))] })] }));
|
|
209
210
|
}
|
|
210
211
|
|
|
211
|
-
function FormInput({ name, isRequired, error, ...rest }) {
|
|
212
|
+
function FormInput({ name, isRequired, error, defaultValue, ...rest }) {
|
|
212
213
|
const { control } = reactHookForm.useFormContext();
|
|
213
214
|
return (jsxRuntime.jsx(reactHookForm.Controller, { name: name, control: control, rules: {
|
|
214
215
|
...(isRequired
|
|
@@ -220,7 +221,7 @@ function FormInput({ name, isRequired, error, ...rest }) {
|
|
|
220
221
|
return (jsxRuntime.jsx(Input, { isRequired: true, error: {
|
|
221
222
|
is: !!error,
|
|
222
223
|
message: error?.message,
|
|
223
|
-
}, ...field, ...rest }));
|
|
224
|
+
}, defaultValue: defaultValue, ...field, ...rest }));
|
|
224
225
|
} }));
|
|
225
226
|
}
|
|
226
227
|
|
|
@@ -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,8 @@ 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, resetField } = reactHookForm.useFormContext();
|
|
330
334
|
return (jsxRuntime.jsx(reactHookForm.Controller, { name: name, control: control, rules: {
|
|
331
335
|
...(isRequired
|
|
332
336
|
? {
|
|
@@ -337,7 +341,10 @@ function FormSelect({ name, isRequired, error, ...rest }) {
|
|
|
337
341
|
return (jsxRuntime.jsx(Select, { isRequired: true, error: {
|
|
338
342
|
is: !!error,
|
|
339
343
|
message: error?.message,
|
|
340
|
-
}, setFormSelected: setValue,
|
|
344
|
+
}, setFormSelected: setValue, resetForm: () => fieldsToReset && fieldsToReset.map((field) => {
|
|
345
|
+
setValue(field, undefined);
|
|
346
|
+
unregister(field);
|
|
347
|
+
}), clearError: clearErrors, onFormBlur: onBlur, ...restField, ...rest }));
|
|
341
348
|
} }));
|
|
342
349
|
}
|
|
343
350
|
|
package/dist/esm/index.js
CHANGED
|
@@ -185,16 +185,17 @@ 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
|
-
}, ...rest }) {
|
|
191
|
-
const methods = useForm();
|
|
191
|
+
}, initialState, ...rest }) {
|
|
192
|
+
const methods = useForm(initialState);
|
|
192
193
|
const { formState: { isValid }, } = methods;
|
|
193
194
|
const [result, setResult] = useState({
|
|
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 = {
|
|
@@ -206,7 +207,7 @@ function Input({ inputClassName = "", classNameGroup = "", error = {
|
|
|
206
207
|
icon.className), children: icon.element }))] })] }));
|
|
207
208
|
}
|
|
208
209
|
|
|
209
|
-
function FormInput({ name, isRequired, error, ...rest }) {
|
|
210
|
+
function FormInput({ name, isRequired, error, defaultValue, ...rest }) {
|
|
210
211
|
const { control } = useFormContext();
|
|
211
212
|
return (jsx(Controller, { name: name, control: control, rules: {
|
|
212
213
|
...(isRequired
|
|
@@ -218,7 +219,7 @@ function FormInput({ name, isRequired, error, ...rest }) {
|
|
|
218
219
|
return (jsx(Input, { isRequired: true, error: {
|
|
219
220
|
is: !!error,
|
|
220
221
|
message: error?.message,
|
|
221
|
-
}, ...field, ...rest }));
|
|
222
|
+
}, defaultValue: defaultValue, ...field, ...rest }));
|
|
222
223
|
} }));
|
|
223
224
|
}
|
|
224
225
|
|
|
@@ -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,8 @@ 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, resetField } = useFormContext();
|
|
328
332
|
return (jsx(Controller, { name: name, control: control, rules: {
|
|
329
333
|
...(isRequired
|
|
330
334
|
? {
|
|
@@ -335,7 +339,10 @@ function FormSelect({ name, isRequired, error, ...rest }) {
|
|
|
335
339
|
return (jsx(Select, { isRequired: true, error: {
|
|
336
340
|
is: !!error,
|
|
337
341
|
message: error?.message,
|
|
338
|
-
}, setFormSelected: setValue,
|
|
342
|
+
}, setFormSelected: setValue, resetForm: () => fieldsToReset && fieldsToReset.map((field) => {
|
|
343
|
+
setValue(field, undefined);
|
|
344
|
+
unregister(field);
|
|
345
|
+
}), clearError: clearErrors, onFormBlur: onBlur, ...restField, ...rest }));
|
|
339
346
|
} }));
|
|
340
347
|
}
|
|
341
348
|
|