@arkyn/components 1.2.5 → 1.3.1

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.
Files changed (75) hide show
  1. package/dist/bundle.js +1711 -1070
  2. package/dist/bundle.umd.cjs +17 -11
  3. package/dist/components/Checkbox/index.d.ts.map +1 -1
  4. package/dist/components/Checkbox/index.js +1 -1
  5. package/dist/components/Input/CpfCpnjInput/getConfig.d.ts +1 -2
  6. package/dist/components/Input/CpfCpnjInput/getConfig.d.ts.map +1 -1
  7. package/dist/components/Input/CpfCpnjInput/getConfig.js +12 -1
  8. package/dist/components/Input/CpfCpnjInput/index.d.ts.map +1 -1
  9. package/dist/components/Input/CpfCpnjInput/index.js +2 -2
  10. package/dist/components/Input/CurrencyInput/getConfig.d.ts +0 -1
  11. package/dist/components/Input/CurrencyInput/getConfig.d.ts.map +1 -1
  12. package/dist/components/Input/MaskInput/getConfig.d.ts +0 -1
  13. package/dist/components/Input/MaskInput/getConfig.d.ts.map +1 -1
  14. package/dist/components/Input/MaskInput/getConfig.js +1 -1
  15. package/dist/components/Input/SimpleInput/getConfig.d.ts +0 -1
  16. package/dist/components/Input/SimpleInput/getConfig.d.ts.map +1 -1
  17. package/dist/components/Select/getConfig.d.ts +1 -1
  18. package/dist/components/Select/getConfig.d.ts.map +1 -1
  19. package/dist/components/Select/index.d.ts.map +1 -1
  20. package/dist/components/Select/index.js +2 -2
  21. package/dist/components/Toast/index.d.ts +9 -0
  22. package/dist/components/Toast/index.d.ts.map +1 -0
  23. package/dist/components/Toast/index.js +6 -0
  24. package/dist/config/buildBadgeConfig.d.ts +0 -1
  25. package/dist/config/buildBadgeConfig.d.ts.map +1 -1
  26. package/dist/config/buildBreadcrumLinkConfig.d.ts +0 -1
  27. package/dist/config/buildBreadcrumLinkConfig.d.ts.map +1 -1
  28. package/dist/config/buildBreadcrumbConfig.d.ts +0 -1
  29. package/dist/config/buildBreadcrumbConfig.d.ts.map +1 -1
  30. package/dist/config/buildButtonConfig.d.ts +0 -1
  31. package/dist/config/buildButtonConfig.d.ts.map +1 -1
  32. package/dist/config/buildFormLabelConfig.d.ts +0 -1
  33. package/dist/config/buildFormLabelConfig.d.ts.map +1 -1
  34. package/dist/context/ModalContext.d.ts +5 -0
  35. package/dist/context/ModalContext.d.ts.map +1 -0
  36. package/dist/context/ModalContext.js +3 -0
  37. package/dist/context/ToastContext.d.ts +5 -0
  38. package/dist/context/ToastContext.d.ts.map +1 -0
  39. package/dist/context/ToastContext.js +3 -0
  40. package/dist/hooks/useAutomation.d.ts +3 -0
  41. package/dist/hooks/useAutomation.d.ts.map +1 -0
  42. package/dist/hooks/useAutomation.js +13 -0
  43. package/dist/hooks/useModal.d.ts +11 -0
  44. package/dist/hooks/useModal.d.ts.map +1 -0
  45. package/dist/hooks/useModal.js +15 -0
  46. package/dist/hooks/useToast.d.ts +3 -0
  47. package/dist/hooks/useToast.d.ts.map +1 -0
  48. package/dist/hooks/useToast.js +10 -0
  49. package/dist/index.d.ts +5 -0
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +6 -0
  52. package/dist/provider/ModalProvider.d.ts +4 -0
  53. package/dist/provider/ModalProvider.d.ts.map +1 -0
  54. package/dist/provider/ModalProvider.js +21 -0
  55. package/dist/provider/ToastProvider.d.ts +4 -0
  56. package/dist/provider/ToastProvider.d.ts.map +1 -0
  57. package/dist/provider/ToastProvider.js +19 -0
  58. package/dist/style.css +1 -1
  59. package/package.json +3 -2
  60. package/src/components/Checkbox/index.tsx +1 -2
  61. package/src/components/Input/CpfCpnjInput/getConfig.tsx +15 -0
  62. package/src/components/Input/CpfCpnjInput/index.tsx +3 -4
  63. package/src/components/Input/MaskInput/getConfig.tsx +1 -1
  64. package/src/components/Select/index.tsx +5 -1
  65. package/src/components/Select/styles.css +1 -1
  66. package/src/components/Toast/index.tsx +19 -0
  67. package/src/components/Toast/styles.css +30 -0
  68. package/src/context/ModalContext.ts +6 -0
  69. package/src/context/ToastContext.ts +6 -0
  70. package/src/hooks/useAutomation.ts +16 -0
  71. package/src/hooks/useModal.ts +29 -0
  72. package/src/hooks/useToast.ts +14 -0
  73. package/src/index.ts +7 -0
  74. package/src/provider/ModalProvider.tsx +35 -0
  75. package/src/provider/ToastProvider.tsx +33 -0
@@ -0,0 +1,16 @@
1
+ import { useActionData } from "@remix-run/react";
2
+ import { useContext, useEffect } from "react";
3
+
4
+ import { ModalContext } from "../context/ModalContext";
5
+
6
+ function useAutomation() {
7
+ const actionData = useActionData<any>();
8
+ const { closeModal } = useContext(ModalContext);
9
+
10
+ useEffect(() => {
11
+ const closeModalKey = actionData?.closeModalKey;
12
+ if (closeModalKey) closeModal(closeModalKey);
13
+ }, [actionData]);
14
+ }
15
+
16
+ export { useAutomation };
@@ -0,0 +1,29 @@
1
+ import { useContext } from "react";
2
+ import { ModalContext } from "../context/ModalContext";
3
+
4
+ type OpenModalProps = (e?: { data: any }) => void;
5
+
6
+ function useModal(key: string) {
7
+ const contextData = useContext(ModalContext);
8
+
9
+ if (Object.entries(contextData).length === 0) {
10
+ throw new Error("useModal must be used within a Provider");
11
+ }
12
+
13
+ const {
14
+ modalData: contextModalData,
15
+ modalIsOpen: contextModalIsOpen,
16
+ openModal: contextOpenModal,
17
+ closeModal: contextCloseModal,
18
+ } = contextData;
19
+
20
+ const modalIsOpen = contextModalIsOpen(key);
21
+ const modalData = contextModalData(key);
22
+
23
+ const openModal: OpenModalProps = (data) => contextOpenModal(key, data?.data);
24
+ const closeModal = () => contextCloseModal(key);
25
+
26
+ return { modalIsOpen, modalData, openModal, closeModal };
27
+ }
28
+
29
+ export { useModal };
@@ -0,0 +1,14 @@
1
+ import { useContext } from "react";
2
+ import { ToastContext } from "../context/ToastContext";
3
+
4
+ function useToast() {
5
+ const contextData = useContext(ToastContext);
6
+
7
+ if (Object.entries(contextData).length === 0) {
8
+ throw new Error("useToast must be used within a Provider");
9
+ }
10
+
11
+ return contextData;
12
+ }
13
+
14
+ export { useToast };
package/src/index.ts CHANGED
@@ -19,4 +19,11 @@ export { Modal } from "./components/Modal";
19
19
  export { Tooltip } from "./components/Tooltip";
20
20
 
21
21
  // Hooks
22
+ export { useAutomation } from "./hooks/useAutomation";
23
+ export { useModal } from "./hooks/useModal";
22
24
  export { useScopedParams } from "./hooks/useScopedParams";
25
+ export { useToast } from "./hooks/useToast";
26
+
27
+ // Providers
28
+ export { ModalProvider } from "./provider/ModalProvider";
29
+ export { ToastProvider } from "./provider/ToastProvider";
@@ -0,0 +1,35 @@
1
+ import { ModalProviderProps, OpenedModals } from "@arkyn/types";
2
+ import { useState } from "react";
3
+
4
+ import { ModalContext } from "../context/ModalContext";
5
+
6
+ function ModalProvider(args: ModalProviderProps) {
7
+ const { children = false } = args;
8
+ const [openedModals, setOpenedModals] = useState<OpenedModals>([]);
9
+
10
+ function modalIsOpen(key: string) {
11
+ return !!openedModals.some((modal) => modal.key === key);
12
+ }
13
+
14
+ function modalData(key: string) {
15
+ return openedModals.find((modal) => modal.key === key)?.data;
16
+ }
17
+
18
+ function openModal(key: string, data?: any) {
19
+ setOpenedModals([...openedModals, { key, data }]);
20
+ }
21
+
22
+ function closeModal(key: string) {
23
+ setOpenedModals(openedModals.filter((modal) => modal.key !== key));
24
+ }
25
+
26
+ return (
27
+ <ModalContext.Provider
28
+ value={{ modalIsOpen, modalData, openModal, closeModal }}
29
+ >
30
+ {children}
31
+ </ModalContext.Provider>
32
+ );
33
+ }
34
+
35
+ export { ModalProvider };
@@ -0,0 +1,33 @@
1
+ import { ToastProviderProps } from "@arkyn/types";
2
+ import { Toaster, toast } from "sonner";
3
+
4
+ import { ToastContext } from "../context/ToastContext";
5
+
6
+ function ToastProvider({ children }: ToastProviderProps) {
7
+ function successToast(message: string) {
8
+ toast.success(message);
9
+ }
10
+
11
+ function infoToast(message: string) {
12
+ toast.info(message);
13
+ }
14
+
15
+ function errorToast(message: string) {
16
+ toast.error(message);
17
+ }
18
+
19
+ function warningToast(message: string) {
20
+ toast.warning(message);
21
+ }
22
+
23
+ return (
24
+ <ToastContext.Provider
25
+ value={{ errorToast, warningToast, successToast, infoToast }}
26
+ >
27
+ <Toaster richColors />
28
+ {children}
29
+ </ToastContext.Provider>
30
+ );
31
+ }
32
+
33
+ export { ToastProvider };