@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.
- package/dist/bundle.js +1711 -1070
- package/dist/bundle.umd.cjs +17 -11
- package/dist/components/Checkbox/index.d.ts.map +1 -1
- package/dist/components/Checkbox/index.js +1 -1
- package/dist/components/Input/CpfCpnjInput/getConfig.d.ts +1 -2
- package/dist/components/Input/CpfCpnjInput/getConfig.d.ts.map +1 -1
- package/dist/components/Input/CpfCpnjInput/getConfig.js +12 -1
- package/dist/components/Input/CpfCpnjInput/index.d.ts.map +1 -1
- package/dist/components/Input/CpfCpnjInput/index.js +2 -2
- package/dist/components/Input/CurrencyInput/getConfig.d.ts +0 -1
- package/dist/components/Input/CurrencyInput/getConfig.d.ts.map +1 -1
- package/dist/components/Input/MaskInput/getConfig.d.ts +0 -1
- package/dist/components/Input/MaskInput/getConfig.d.ts.map +1 -1
- package/dist/components/Input/MaskInput/getConfig.js +1 -1
- package/dist/components/Input/SimpleInput/getConfig.d.ts +0 -1
- package/dist/components/Input/SimpleInput/getConfig.d.ts.map +1 -1
- package/dist/components/Select/getConfig.d.ts +1 -1
- package/dist/components/Select/getConfig.d.ts.map +1 -1
- package/dist/components/Select/index.d.ts.map +1 -1
- package/dist/components/Select/index.js +2 -2
- package/dist/components/Toast/index.d.ts +9 -0
- package/dist/components/Toast/index.d.ts.map +1 -0
- package/dist/components/Toast/index.js +6 -0
- package/dist/config/buildBadgeConfig.d.ts +0 -1
- package/dist/config/buildBadgeConfig.d.ts.map +1 -1
- package/dist/config/buildBreadcrumLinkConfig.d.ts +0 -1
- package/dist/config/buildBreadcrumLinkConfig.d.ts.map +1 -1
- package/dist/config/buildBreadcrumbConfig.d.ts +0 -1
- package/dist/config/buildBreadcrumbConfig.d.ts.map +1 -1
- package/dist/config/buildButtonConfig.d.ts +0 -1
- package/dist/config/buildButtonConfig.d.ts.map +1 -1
- package/dist/config/buildFormLabelConfig.d.ts +0 -1
- package/dist/config/buildFormLabelConfig.d.ts.map +1 -1
- package/dist/context/ModalContext.d.ts +5 -0
- package/dist/context/ModalContext.d.ts.map +1 -0
- package/dist/context/ModalContext.js +3 -0
- package/dist/context/ToastContext.d.ts +5 -0
- package/dist/context/ToastContext.d.ts.map +1 -0
- package/dist/context/ToastContext.js +3 -0
- package/dist/hooks/useAutomation.d.ts +3 -0
- package/dist/hooks/useAutomation.d.ts.map +1 -0
- package/dist/hooks/useAutomation.js +13 -0
- package/dist/hooks/useModal.d.ts +11 -0
- package/dist/hooks/useModal.d.ts.map +1 -0
- package/dist/hooks/useModal.js +15 -0
- package/dist/hooks/useToast.d.ts +3 -0
- package/dist/hooks/useToast.d.ts.map +1 -0
- package/dist/hooks/useToast.js +10 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/provider/ModalProvider.d.ts +4 -0
- package/dist/provider/ModalProvider.d.ts.map +1 -0
- package/dist/provider/ModalProvider.js +21 -0
- package/dist/provider/ToastProvider.d.ts +4 -0
- package/dist/provider/ToastProvider.d.ts.map +1 -0
- package/dist/provider/ToastProvider.js +19 -0
- package/dist/style.css +1 -1
- package/package.json +3 -2
- package/src/components/Checkbox/index.tsx +1 -2
- package/src/components/Input/CpfCpnjInput/getConfig.tsx +15 -0
- package/src/components/Input/CpfCpnjInput/index.tsx +3 -4
- package/src/components/Input/MaskInput/getConfig.tsx +1 -1
- package/src/components/Select/index.tsx +5 -1
- package/src/components/Select/styles.css +1 -1
- package/src/components/Toast/index.tsx +19 -0
- package/src/components/Toast/styles.css +30 -0
- package/src/context/ModalContext.ts +6 -0
- package/src/context/ToastContext.ts +6 -0
- package/src/hooks/useAutomation.ts +16 -0
- package/src/hooks/useModal.ts +29 -0
- package/src/hooks/useToast.ts +14 -0
- package/src/index.ts +7 -0
- package/src/provider/ModalProvider.tsx +35 -0
- 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 };
|