@arkyn/components 1.3.129 → 1.3.131
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/bundle.js +1862 -1851
- package/dist/bundle.umd.cjs +40 -40
- package/dist/components/Form/FormController/index.d.ts.map +1 -1
- package/dist/components/Form/FormController/index.js +11 -3
- package/dist/hooks/useAutomation.d.ts.map +1 -1
- package/dist/hooks/useAutomation.js +13 -2
- package/dist/provider/ModalProvider.d.ts.map +1 -1
- package/dist/provider/ModalProvider.js +4 -1
- package/package.json +1 -1
- package/src/components/Form/FormController/index.tsx +14 -3
- package/src/hooks/useAutomation.ts +16 -2
- package/src/provider/ModalProvider.tsx +5 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Form/FormController/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAI/E,OAAO,cAAc,CAAC;AAItB,iBAAS,cAAc,CAAC,KAAK,EAAE,mBAAmB,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Form/FormController/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAI/E,OAAO,cAAc,CAAC;AAItB,iBAAS,cAAc,CAAC,KAAK,EAAE,mBAAmB,2CAuCjD;AAED,iBAAS,iBAAiB,+BAEzB;AAED,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAC"}
|
@@ -1,14 +1,22 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import { useActionData } from "@remix-run/react";
|
2
|
+
import { useActionData, useFetchers } from "@remix-run/react";
|
3
3
|
import { createContext, useContext, useId, useRef } from "react";
|
4
4
|
import "./styles.css";
|
5
5
|
const FormControllerContext = createContext({});
|
6
6
|
function FormController(props) {
|
7
|
-
const actionData = useActionData();
|
8
7
|
const { children, className: baseClassName, id: formControllerId, ...rest } = props;
|
8
|
+
const actionData = useActionData();
|
9
|
+
const fetchers = useFetchers();
|
10
|
+
let fieldErrors = {};
|
11
|
+
fieldErrors = { ...actionData?.fieldErrors };
|
12
|
+
fetchers.forEach((fetcher) => {
|
13
|
+
if (fetcher.data?.fieldErrors) {
|
14
|
+
fieldErrors = { ...fieldErrors, ...fetcher.data.fieldErrors };
|
15
|
+
}
|
16
|
+
});
|
9
17
|
const inputRef = useRef(null);
|
10
18
|
const name = inputRef.current?.name || "";
|
11
|
-
const error =
|
19
|
+
const error = fieldErrors?.[name] || null;
|
12
20
|
const id = useId();
|
13
21
|
const className = `arkynFormController ${baseClassName}`;
|
14
22
|
return (_jsx(FormControllerContext.Provider, { value: { error, id, inputRef }, children: _jsx("section", { id: formControllerId || name || undefined, className: className.trim(), ...rest, children: children }) }));
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useAutomation.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutomation.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"useAutomation.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutomation.ts"],"names":[],"mappings":"AAsBA,iBAAS,aAAa,SA2CrB;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
@@ -1,7 +1,8 @@
|
|
1
|
-
import { useActionData } from "@remix-run/react";
|
1
|
+
import { useActionData, useLocation, useNavigate } from "@remix-run/react";
|
2
2
|
import { useContext, useEffect } from "react";
|
3
3
|
import { animateScroll } from "react-scroll";
|
4
4
|
import { ModalContext } from "../context/ModalContext";
|
5
|
+
import { useScopedParams } from "./useScopedParams";
|
5
6
|
import { useToast } from "./useToast";
|
6
7
|
function isToastProps(obj) {
|
7
8
|
return (obj &&
|
@@ -15,8 +16,18 @@ function isToastProps(obj) {
|
|
15
16
|
}
|
16
17
|
function useAutomation() {
|
17
18
|
const actionData = useActionData();
|
18
|
-
const { closeModal } = useContext(ModalContext);
|
19
|
+
const { closeModal, closeAll } = useContext(ModalContext);
|
19
20
|
const { showToast } = useToast();
|
21
|
+
const { getParam } = useScopedParams();
|
22
|
+
const { pathname } = useLocation();
|
23
|
+
const navigate = useNavigate();
|
24
|
+
const closeAllModals = getParam("closeAllModals");
|
25
|
+
useEffect(() => {
|
26
|
+
if (closeAllModals === "true") {
|
27
|
+
closeAll();
|
28
|
+
navigate(pathname);
|
29
|
+
}
|
30
|
+
}, [closeAllModals]);
|
20
31
|
useEffect(() => {
|
21
32
|
const closeModalKey = actionData?.closeModalKey;
|
22
33
|
if (closeModalKey)
|
@@ -1 +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,
|
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,2CAqC9C;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
@@ -24,6 +24,9 @@ function ModalProvider(args) {
|
|
24
24
|
function closeModal(key) {
|
25
25
|
setOpenedModals(openedModals.filter((modal) => modal.key !== key));
|
26
26
|
}
|
27
|
-
|
27
|
+
function closeAll() {
|
28
|
+
setOpenedModals([]);
|
29
|
+
}
|
30
|
+
return (_jsx(ModalContext.Provider, { value: { modalIsOpen, modalData, openModal, closeModal, closeAll }, children: children }));
|
28
31
|
}
|
29
32
|
export { ModalProvider };
|
package/package.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { FormControllerContextProps, FormControllerProps } from "@arkyn/types";
|
2
|
-
import { useActionData } from "@remix-run/react";
|
2
|
+
import { useActionData, useFetchers } from "@remix-run/react";
|
3
3
|
import { createContext, useContext, useId, useRef } from "react";
|
4
4
|
|
5
5
|
import "./styles.css";
|
@@ -7,7 +7,6 @@ import "./styles.css";
|
|
7
7
|
const FormControllerContext = createContext({} as FormControllerContextProps);
|
8
8
|
|
9
9
|
function FormController(props: FormControllerProps) {
|
10
|
-
const actionData = useActionData<any>();
|
11
10
|
const {
|
12
11
|
children,
|
13
12
|
className: baseClassName,
|
@@ -15,10 +14,22 @@ function FormController(props: FormControllerProps) {
|
|
15
14
|
...rest
|
16
15
|
} = props;
|
17
16
|
|
17
|
+
const actionData = useActionData<any>();
|
18
|
+
const fetchers = useFetchers();
|
19
|
+
|
20
|
+
let fieldErrors: { [x: string]: string } = {};
|
21
|
+
|
22
|
+
fieldErrors = { ...actionData?.fieldErrors };
|
23
|
+
fetchers.forEach((fetcher) => {
|
24
|
+
if (fetcher.data?.fieldErrors) {
|
25
|
+
fieldErrors = { ...fieldErrors, ...fetcher.data.fieldErrors };
|
26
|
+
}
|
27
|
+
});
|
28
|
+
|
18
29
|
const inputRef = useRef<HTMLInputElement>(null);
|
19
30
|
|
20
31
|
const name = inputRef.current?.name || "";
|
21
|
-
const error =
|
32
|
+
const error = fieldErrors?.[name] || null;
|
22
33
|
|
23
34
|
const id = useId();
|
24
35
|
const className = `arkynFormController ${baseClassName}`;
|
@@ -1,9 +1,10 @@
|
|
1
1
|
import { ToastProps } from "@arkyn/types";
|
2
|
-
import { useActionData } from "@remix-run/react";
|
2
|
+
import { useActionData, useLocation, useNavigate } from "@remix-run/react";
|
3
3
|
import { useContext, useEffect } from "react";
|
4
4
|
import { animateScroll } from "react-scroll";
|
5
5
|
|
6
6
|
import { ModalContext } from "../context/ModalContext";
|
7
|
+
import { useScopedParams } from "./useScopedParams";
|
7
8
|
import { useToast } from "./useToast";
|
8
9
|
|
9
10
|
function isToastProps(obj: any): obj is ToastProps {
|
@@ -21,9 +22,22 @@ function isToastProps(obj: any): obj is ToastProps {
|
|
21
22
|
|
22
23
|
function useAutomation() {
|
23
24
|
const actionData = useActionData<any>();
|
24
|
-
const { closeModal } = useContext(ModalContext);
|
25
|
+
const { closeModal, closeAll } = useContext(ModalContext);
|
25
26
|
const { showToast } = useToast();
|
26
27
|
|
28
|
+
const { getParam } = useScopedParams();
|
29
|
+
const { pathname } = useLocation();
|
30
|
+
const navigate = useNavigate();
|
31
|
+
|
32
|
+
const closeAllModals = getParam("closeAllModals");
|
33
|
+
|
34
|
+
useEffect(() => {
|
35
|
+
if (closeAllModals === "true") {
|
36
|
+
closeAll();
|
37
|
+
navigate(pathname);
|
38
|
+
}
|
39
|
+
}, [closeAllModals]);
|
40
|
+
|
27
41
|
useEffect(() => {
|
28
42
|
const closeModalKey = actionData?.closeModalKey;
|
29
43
|
if (closeModalKey) closeModal(closeModalKey);
|
@@ -29,9 +29,13 @@ function ModalProvider(args: ModalProviderProps) {
|
|
29
29
|
setOpenedModals(openedModals.filter((modal) => modal.key !== key));
|
30
30
|
}
|
31
31
|
|
32
|
+
function closeAll() {
|
33
|
+
setOpenedModals([]);
|
34
|
+
}
|
35
|
+
|
32
36
|
return (
|
33
37
|
<ModalContext.Provider
|
34
|
-
value={{ modalIsOpen, modalData, openModal, closeModal }}
|
38
|
+
value={{ modalIsOpen, modalData, openModal, closeModal, closeAll }}
|
35
39
|
>
|
36
40
|
{children}
|
37
41
|
</ModalContext.Provider>
|