@arkyn/components 1.3.9 → 1.3.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.
@@ -1,13 +1,25 @@
1
1
  import { useActionData } from "@remix-run/react";
2
2
  import { useContext, useEffect } from "react";
3
3
  import { ModalContext } from "../context/ModalContext";
4
+ import { useToast } from "./useToast";
4
5
  function useAutomation() {
5
6
  const actionData = useActionData();
6
7
  const { closeModal } = useContext(ModalContext);
8
+ const { successToast, errorToast } = useToast();
7
9
  useEffect(() => {
8
10
  const closeModalKey = actionData?.closeModalKey;
9
11
  if (closeModalKey)
10
12
  closeModal(closeModalKey);
11
13
  }, [actionData]);
14
+ useEffect(() => {
15
+ const showToast = typeof actionData?.message === "string" &&
16
+ typeof actionData?.success === "boolean";
17
+ if (showToast) {
18
+ if (actionData?.success)
19
+ successToast(actionData?.message);
20
+ else
21
+ errorToast(actionData?.message);
22
+ }
23
+ }, [actionData]);
12
24
  }
13
25
  export { useAutomation };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/components",
3
- "version": "1.3.9",
3
+ "version": "1.3.11",
4
4
  "main": "./dist/bundle.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Lucas Gonçalves",
@@ -10,7 +10,7 @@ import "./styles.css";
10
10
  function Input(props: InputProps) {
11
11
  if (props.type === "currency") return <CurrencyInput {...props} />;
12
12
  if (props.type === "masked") return <MaskedInput {...props} />;
13
- if (props.type === "cpf-cpnj") return <CpfCnpjInput {...props} />;
13
+ if (props.type === "cpf-cnpj") return <CpfCnpjInput {...props} />;
14
14
  return <SimpleInput {...props} />;
15
15
  }
16
16
 
@@ -19,6 +19,7 @@ function getConfig(props: SelectProps, isFocused: boolean) {
19
19
  title,
20
20
  style,
21
21
  isSearchable = false,
22
+ closeOnSelect = true,
22
23
  ...rest
23
24
  } = props;
24
25
 
@@ -41,6 +42,7 @@ function getConfig(props: SelectProps, isFocused: boolean) {
41
42
  onFocus,
42
43
  onBlur,
43
44
  title,
45
+ closeOnSelect,
44
46
  style,
45
47
  isSearchable,
46
48
  iconSize: iconSize,
@@ -39,6 +39,7 @@ function Select(props: SelectProps) {
39
39
  onSelect,
40
40
  options,
41
41
  optionMaxHeight,
42
+ closeOnSelect,
42
43
  ...rest
43
44
  } = getConfig({ ...props, id, isError }, isFocused);
44
45
 
@@ -136,6 +137,7 @@ function Select(props: SelectProps) {
136
137
  if (selectedValue !== value) setSelectedValue(value);
137
138
  else setSelectedValue("");
138
139
  onSelect && onSelect({ label, value });
140
+ closeOnSelect && setTimeout(() => handleBlur(), 100);
139
141
  }}
140
142
  >
141
143
  {label} <Check />
@@ -2,15 +2,28 @@ import { useActionData } from "@remix-run/react";
2
2
  import { useContext, useEffect } from "react";
3
3
 
4
4
  import { ModalContext } from "../context/ModalContext";
5
+ import { useToast } from "./useToast";
5
6
 
6
7
  function useAutomation() {
7
8
  const actionData = useActionData<any>();
8
9
  const { closeModal } = useContext(ModalContext);
10
+ const { successToast, errorToast } = useToast();
9
11
 
10
12
  useEffect(() => {
11
13
  const closeModalKey = actionData?.closeModalKey;
12
14
  if (closeModalKey) closeModal(closeModalKey);
13
15
  }, [actionData]);
16
+
17
+ useEffect(() => {
18
+ const showToast =
19
+ typeof actionData?.message === "string" &&
20
+ typeof actionData?.success === "boolean";
21
+
22
+ if (showToast) {
23
+ if (actionData?.success) successToast(actionData?.message);
24
+ else errorToast(actionData?.message);
25
+ }
26
+ }, [actionData]);
14
27
  }
15
28
 
16
29
  export { useAutomation };