@geoinsight/react-components 0.6.8 → 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 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,14 +197,13 @@ 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 = {
203
204
  is: false,
204
205
  message: "",
205
206
  }, inputRef, styleGroup, placeholder = "Insert value", label, labelClass, icon, ...rest }) {
206
- console.log(error);
207
207
  return (jsxRuntime.jsxs("div", { className: clsx("input-group", classNameGroup), style: styleGroup, children: [jsxRuntime.jsxs("div", { className: "input__header", children: [label && jsxRuntime.jsx("label", { className: labelClass, children: label }), error && error.is && (jsxRuntime.jsx("span", { className: "input__header--error", children: error.message }))] }), jsxRuntime.jsxs("div", { className: "input-subgroup", children: [icon?.element && icon.position === "left" && (jsxRuntime.jsx("div", { className: clsx("input__icon", "input__icon--left", icon.className), children: icon.element })), jsxRuntime.jsx("input", { ref: inputRef, className: clsx("input", error.is ? "input--error" : "", icon?.position === "left" && "input--icon", inputClassName), placeholder: placeholder, ...rest }), icon?.element && icon.position !== "left" && (jsxRuntime.jsx("div", { className: clsx("input__icon", "input__icon--right",
208
208
  // `input__icon--${icon.position || "right"}`,
209
209
  icon.className), children: icon.element }))] })] }));
@@ -265,7 +265,7 @@ function FormTextArea({ name, isRequired, error, ...rest }) {
265
265
 
266
266
  function Select({ inputClassName = "", classNameGroup = "", options, styleGroup, defaultValue,
267
267
  // inputProps,
268
- setFormSelected, clearError, onFormBlur, handleSelect, ...rest }) {
268
+ setFormSelected, clearError, resetForm, onFormBlur, handleSelect, ...rest }) {
269
269
  const [isOpen, setIsOpen] = react.useState(false);
270
270
  const [value, setValue] = react.useState(defaultValue || (options && options[0]));
271
271
  const [filteredOptions, setFilteredOptions] = react.useState(options);
@@ -299,6 +299,9 @@ setFormSelected, clearError, onFormBlur, handleSelect, ...rest }) {
299
299
  if (clearError) {
300
300
  clearError(name);
301
301
  }
302
+ if (resetForm) {
303
+ resetForm();
304
+ }
302
305
  }
303
306
  else {
304
307
  setValue(value);
@@ -326,8 +329,9 @@ setFormSelected, clearError, onFormBlur, handleSelect, ...rest }) {
326
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}`))) }))] }));
327
330
  }
328
331
 
329
- function FormSelect({ name, isRequired, error, ...rest }) {
330
- 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);
331
335
  return (jsxRuntime.jsx(reactHookForm.Controller, { name: name, control: control, rules: {
332
336
  ...(isRequired
333
337
  ? {
@@ -338,7 +342,7 @@ function FormSelect({ name, isRequired, error, ...rest }) {
338
342
  return (jsxRuntime.jsx(Select, { isRequired: true, error: {
339
343
  is: !!error,
340
344
  message: error?.message,
341
- }, setFormSelected: setValue, clearError: clearErrors, onFormBlur: onBlur, ...restField, ...rest }));
345
+ }, setFormSelected: setValue, resetForm: () => fieldsToReset && fieldsToReset.map((field) => unregister(field)), clearError: clearErrors, onFormBlur: onBlur, ...restField, ...rest }));
342
346
  } }));
343
347
  }
344
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,14 +195,13 @@ 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 = {
201
202
  is: false,
202
203
  message: "",
203
204
  }, inputRef, styleGroup, placeholder = "Insert value", label, labelClass, icon, ...rest }) {
204
- console.log(error);
205
205
  return (jsxs("div", { className: clsx("input-group", classNameGroup), style: styleGroup, children: [jsxs("div", { className: "input__header", children: [label && jsx("label", { className: labelClass, children: label }), error && error.is && (jsx("span", { className: "input__header--error", children: error.message }))] }), jsxs("div", { className: "input-subgroup", children: [icon?.element && icon.position === "left" && (jsx("div", { className: clsx("input__icon", "input__icon--left", icon.className), children: icon.element })), jsx("input", { ref: inputRef, className: clsx("input", error.is ? "input--error" : "", icon?.position === "left" && "input--icon", inputClassName), placeholder: placeholder, ...rest }), icon?.element && icon.position !== "left" && (jsx("div", { className: clsx("input__icon", "input__icon--right",
206
206
  // `input__icon--${icon.position || "right"}`,
207
207
  icon.className), children: icon.element }))] })] }));
@@ -263,7 +263,7 @@ function FormTextArea({ name, isRequired, error, ...rest }) {
263
263
 
264
264
  function Select({ inputClassName = "", classNameGroup = "", options, styleGroup, defaultValue,
265
265
  // inputProps,
266
- setFormSelected, clearError, onFormBlur, handleSelect, ...rest }) {
266
+ setFormSelected, clearError, resetForm, onFormBlur, handleSelect, ...rest }) {
267
267
  const [isOpen, setIsOpen] = useState(false);
268
268
  const [value, setValue] = useState(defaultValue || (options && options[0]));
269
269
  const [filteredOptions, setFilteredOptions] = useState(options);
@@ -297,6 +297,9 @@ setFormSelected, clearError, onFormBlur, handleSelect, ...rest }) {
297
297
  if (clearError) {
298
298
  clearError(name);
299
299
  }
300
+ if (resetForm) {
301
+ resetForm();
302
+ }
300
303
  }
301
304
  else {
302
305
  setValue(value);
@@ -324,8 +327,9 @@ setFormSelected, clearError, onFormBlur, handleSelect, ...rest }) {
324
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}`))) }))] }));
325
328
  }
326
329
 
327
- function FormSelect({ name, isRequired, error, ...rest }) {
328
- const { control, setValue, clearErrors } = useFormContext();
330
+ function FormSelect({ name, isRequired, error, fieldsToReset, ...rest }) {
331
+ const { control, setValue, clearErrors, unregister } = useFormContext();
332
+ console.log(fieldsToReset);
329
333
  return (jsx(Controller, { name: name, control: control, rules: {
330
334
  ...(isRequired
331
335
  ? {
@@ -336,7 +340,7 @@ function FormSelect({ name, isRequired, error, ...rest }) {
336
340
  return (jsx(Select, { isRequired: true, error: {
337
341
  is: !!error,
338
342
  message: error?.message,
339
- }, setFormSelected: setValue, clearError: clearErrors, onFormBlur: onBlur, ...restField, ...rest }));
343
+ }, setFormSelected: setValue, resetForm: () => fieldsToReset && fieldsToReset.map((field) => unregister(field)), clearError: clearErrors, onFormBlur: onBlur, ...restField, ...rest }));
340
344
  } }));
341
345
  }
342
346
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geoinsight/react-components",
3
- "version": "0.6.8",
3
+ "version": "0.6.10",
4
4
  "description": "This library is the main UI component library for geoinsight",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",