@arkyn/components 1.3.0 → 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 +1700 -1074
- 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 +0 -1
- package/dist/components/Input/CpfCpnjInput/getConfig.d.ts.map +1 -1
- 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/SimpleInput/getConfig.d.ts +0 -1
- package/dist/components/Input/SimpleInput/getConfig.d.ts.map +1 -1
- package/dist/components/Select/getConfig.d.ts +0 -1
- package/dist/components/Select/getConfig.d.ts.map +1 -1
- 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/package.json +3 -2
- package/src/components/Checkbox/index.tsx +1 -2
- 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 @@
|
|
1
|
+
{"version":3,"file":"ToastContext.d.ts","sourceRoot":"","sources":["../../src/context/ToastContext.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGjD,QAAA,MAAM,YAAY,4CAAyC,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useAutomation.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutomation.ts"],"names":[],"mappings":"AAKA,iBAAS,aAAa,SAQrB;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { useActionData } from "@remix-run/react";
|
2
|
+
import { useContext, useEffect } from "react";
|
3
|
+
import { ModalContext } from "../context/ModalContext";
|
4
|
+
function useAutomation() {
|
5
|
+
const actionData = useActionData();
|
6
|
+
const { closeModal } = useContext(ModalContext);
|
7
|
+
useEffect(() => {
|
8
|
+
const closeModalKey = actionData?.closeModalKey;
|
9
|
+
if (closeModalKey)
|
10
|
+
closeModal(closeModalKey);
|
11
|
+
}, [actionData]);
|
12
|
+
}
|
13
|
+
export { useAutomation };
|
@@ -0,0 +1,11 @@
|
|
1
|
+
type OpenModalProps = (e?: {
|
2
|
+
data: any;
|
3
|
+
}) => void;
|
4
|
+
declare function useModal(key: string): {
|
5
|
+
modalIsOpen: boolean;
|
6
|
+
modalData: any;
|
7
|
+
openModal: OpenModalProps;
|
8
|
+
closeModal: () => void;
|
9
|
+
};
|
10
|
+
export { useModal };
|
11
|
+
//# sourceMappingURL=useModal.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useModal.d.ts","sourceRoot":"","sources":["../../src/hooks/useModal.ts"],"names":[],"mappings":"AAGA,KAAK,cAAc,GAAG,CAAC,CAAC,CAAC,EAAE;IAAE,IAAI,EAAE,GAAG,CAAA;CAAE,KAAK,IAAI,CAAC;AAElD,iBAAS,QAAQ,CAAC,GAAG,EAAE,MAAM;;;;;EAqB5B;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { useContext } from "react";
|
2
|
+
import { ModalContext } from "../context/ModalContext";
|
3
|
+
function useModal(key) {
|
4
|
+
const contextData = useContext(ModalContext);
|
5
|
+
if (Object.entries(contextData).length === 0) {
|
6
|
+
throw new Error("useModal must be used within a Provider");
|
7
|
+
}
|
8
|
+
const { modalData: contextModalData, modalIsOpen: contextModalIsOpen, openModal: contextOpenModal, closeModal: contextCloseModal, } = contextData;
|
9
|
+
const modalIsOpen = contextModalIsOpen(key);
|
10
|
+
const modalData = contextModalData(key);
|
11
|
+
const openModal = (data) => contextOpenModal(key, data?.data);
|
12
|
+
const closeModal = () => contextCloseModal(key);
|
13
|
+
return { modalIsOpen, modalData, openModal, closeModal };
|
14
|
+
}
|
15
|
+
export { useModal };
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useToast.d.ts","sourceRoot":"","sources":["../../src/hooks/useToast.ts"],"names":[],"mappings":"AAGA,iBAAS,QAAQ,6CAQhB;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { useContext } from "react";
|
2
|
+
import { ToastContext } from "../context/ToastContext";
|
3
|
+
function useToast() {
|
4
|
+
const contextData = useContext(ToastContext);
|
5
|
+
if (Object.entries(contextData).length === 0) {
|
6
|
+
throw new Error("useToast must be used within a Provider");
|
7
|
+
}
|
8
|
+
return contextData;
|
9
|
+
}
|
10
|
+
export { useToast };
|
package/dist/index.d.ts
CHANGED
@@ -10,5 +10,10 @@ export { Select } from "./components/Select";
|
|
10
10
|
export { Breadcrumb, BreadcrumbLink } from "./components/Breadcrumb";
|
11
11
|
export { Modal } from "./components/Modal";
|
12
12
|
export { Tooltip } from "./components/Tooltip";
|
13
|
+
export { useAutomation } from "./hooks/useAutomation";
|
14
|
+
export { useModal } from "./hooks/useModal";
|
13
15
|
export { useScopedParams } from "./hooks/useScopedParams";
|
16
|
+
export { useToast } from "./hooks/useToast";
|
17
|
+
export { ModalProvider } from "./provider/ModalProvider";
|
18
|
+
export { ToastProvider } from "./provider/ToastProvider";
|
14
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGrE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGrE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAG/C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
@@ -15,4 +15,10 @@ export { Breadcrumb, BreadcrumbLink } from "./components/Breadcrumb";
|
|
15
15
|
export { Modal } from "./components/Modal";
|
16
16
|
export { Tooltip } from "./components/Tooltip";
|
17
17
|
// Hooks
|
18
|
+
export { useAutomation } from "./hooks/useAutomation";
|
19
|
+
export { useModal } from "./hooks/useModal";
|
18
20
|
export { useScopedParams } from "./hooks/useScopedParams";
|
21
|
+
export { useToast } from "./hooks/useToast";
|
22
|
+
// Providers
|
23
|
+
export { ModalProvider } from "./provider/ModalProvider";
|
24
|
+
export { ToastProvider } from "./provider/ToastProvider";
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ModalProvider.d.ts","sourceRoot":"","sources":["../../src/provider/ModalProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAgB,MAAM,cAAc,CAAC;AAKhE,iBAAS,aAAa,CAAC,IAAI,EAAE,kBAAkB,2CA2B9C;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { useState } from "react";
|
3
|
+
import { ModalContext } from "../context/ModalContext";
|
4
|
+
function ModalProvider(args) {
|
5
|
+
const { children = false } = args;
|
6
|
+
const [openedModals, setOpenedModals] = useState([]);
|
7
|
+
function modalIsOpen(key) {
|
8
|
+
return !!openedModals.some((modal) => modal.key === key);
|
9
|
+
}
|
10
|
+
function modalData(key) {
|
11
|
+
return openedModals.find((modal) => modal.key === key)?.data;
|
12
|
+
}
|
13
|
+
function openModal(key, data) {
|
14
|
+
setOpenedModals([...openedModals, { key, data }]);
|
15
|
+
}
|
16
|
+
function closeModal(key) {
|
17
|
+
setOpenedModals(openedModals.filter((modal) => modal.key !== key));
|
18
|
+
}
|
19
|
+
return (_jsx(ModalContext.Provider, { value: { modalIsOpen, modalData, openModal, closeModal }, children: children }));
|
20
|
+
}
|
21
|
+
export { ModalProvider };
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ToastProvider.d.ts","sourceRoot":"","sources":["../../src/provider/ToastProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAKlD,iBAAS,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,kBAAkB,2CAyBtD;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
+
import { Toaster, toast } from "sonner";
|
3
|
+
import { ToastContext } from "../context/ToastContext";
|
4
|
+
function ToastProvider({ children }) {
|
5
|
+
function successToast(message) {
|
6
|
+
toast.success(message);
|
7
|
+
}
|
8
|
+
function infoToast(message) {
|
9
|
+
toast.info(message);
|
10
|
+
}
|
11
|
+
function errorToast(message) {
|
12
|
+
toast.error(message);
|
13
|
+
}
|
14
|
+
function warningToast(message) {
|
15
|
+
toast.warning(message);
|
16
|
+
}
|
17
|
+
return (_jsxs(ToastContext.Provider, { value: { errorToast, warningToast, successToast, infoToast }, children: [_jsx(Toaster, { richColors: true }), children] }));
|
18
|
+
}
|
19
|
+
export { ToastProvider };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arkyn/components",
|
3
|
-
"version": "1.3.
|
3
|
+
"version": "1.3.1",
|
4
4
|
"main": "./dist/bundle.js",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"author": "Lucas Gonçalves",
|
@@ -13,7 +13,8 @@
|
|
13
13
|
"dependencies": {
|
14
14
|
"@react-input/mask": ">=1.2.4",
|
15
15
|
"framer-motion": ">=11.2.4",
|
16
|
-
"lucide-react": ">=0.378.0"
|
16
|
+
"lucide-react": ">=0.378.0",
|
17
|
+
"sonner": ">=1.4.41"
|
17
18
|
},
|
18
19
|
"peerDependencies": {
|
19
20
|
"@remix-run/react": ">=2.0.1",
|
@@ -36,11 +36,10 @@ function Checkbox(props: CheckboxProps) {
|
|
36
36
|
}
|
37
37
|
|
38
38
|
return (
|
39
|
-
<div className={className} onClick={handleCheck} {...rest}>
|
39
|
+
<div id={id} className={className} onClick={handleCheck} {...rest}>
|
40
40
|
<input
|
41
41
|
type="hidden"
|
42
42
|
name={name}
|
43
|
-
id={id}
|
44
43
|
ref={inputRef}
|
45
44
|
value={currentChecked ? value || "checked" : ""}
|
46
45
|
/>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
type ToastProps = {
|
2
|
+
title?: string;
|
3
|
+
message: string;
|
4
|
+
type: "success" | "warning" | "error" | "info";
|
5
|
+
};
|
6
|
+
|
7
|
+
import "./styles.css";
|
8
|
+
|
9
|
+
function Toast({ message, type, title }: ToastProps) {
|
10
|
+
return (
|
11
|
+
<div className={"arkyn_toast " + type}>
|
12
|
+
{title && <strong>{title}</strong>}
|
13
|
+
<strong>Sucesso</strong>
|
14
|
+
<p>{message}</p>
|
15
|
+
</div>
|
16
|
+
);
|
17
|
+
}
|
18
|
+
|
19
|
+
export { Toast };
|
@@ -0,0 +1,30 @@
|
|
1
|
+
.arkyn_toast {
|
2
|
+
display: flex;
|
3
|
+
flex-direction: column;
|
4
|
+
|
5
|
+
padding: 8px 16px;
|
6
|
+
min-width: 200px;
|
7
|
+
|
8
|
+
border-radius: 6px;
|
9
|
+
border: 1px solid transparent;
|
10
|
+
}
|
11
|
+
|
12
|
+
.arkyn_toast strong {
|
13
|
+
font-size: 14px;
|
14
|
+
font-weight: 600;
|
15
|
+
}
|
16
|
+
|
17
|
+
.arkyn_toast p {
|
18
|
+
font-size: 16px;
|
19
|
+
font-weight: 500;
|
20
|
+
}
|
21
|
+
|
22
|
+
/* SCHEME */
|
23
|
+
.arkyn_toast.success {
|
24
|
+
background-color: var(--success-200);
|
25
|
+
}
|
26
|
+
|
27
|
+
.arkyn_toast strong,
|
28
|
+
.arkyn_toast p {
|
29
|
+
color: var(--success-600);
|
30
|
+
}
|
@@ -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 };
|