@xwadex/fesd-next 0.3.24 → 0.3.26
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/components/accordions/accordions.js +16 -20
- package/dist/components/accordions/accordionsContext.d.ts +1 -1
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.js +0 -1
- package/dist/hooks/useCollapse.d.ts +7 -5
- package/dist/hooks/useCollapse.js +51 -32
- package/package.json +1 -1
- package/dist/components/myComponents/MyComponent.d.ts +0 -2
- package/dist/components/myComponents/MyComponent.js +0 -4
- package/dist/components/myComponents/MyComponent.module.scss +0 -3
- package/dist/components/myComponents/index.d.ts +0 -1
- package/dist/components/myComponents/index.js +0 -1
|
@@ -1,48 +1,44 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useCallback, useMemo, memo, useEffect } from "react";
|
|
3
|
+
import { useCallback, useMemo, memo, useEffect, startTransition } from "react";
|
|
4
4
|
import { AccordionsContext } from "./accordionsContext";
|
|
5
5
|
import { useCollapse } from "../../hooks/index.js";
|
|
6
6
|
const AccordionsBase = (props) => {
|
|
7
|
-
const { as, children, defaultActive = false, active,
|
|
7
|
+
const { as, children, defaultActive = false, active, transDuration, transTiming, transMode, transDelay, onInit, onChange, onExpand, onClose, ...othersProps } = props;
|
|
8
8
|
const RootComponent = as || "div";
|
|
9
9
|
const isActive = typeof active == "boolean";
|
|
10
10
|
const defaultOpen = isActive ? active : defaultActive;
|
|
11
|
-
const {
|
|
11
|
+
const { setOpen, open, contentRef, } = useCollapse({
|
|
12
12
|
defaultOpen,
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
transDuration,
|
|
14
|
+
transTiming,
|
|
15
|
+
transMode,
|
|
16
|
+
transDelay,
|
|
15
17
|
onInit,
|
|
16
18
|
onChange,
|
|
17
19
|
onExpand,
|
|
18
20
|
onClose
|
|
19
21
|
});
|
|
20
|
-
const
|
|
22
|
+
const isOpen = isActive ? active : open;
|
|
21
23
|
const setExpand = useCallback((state) => {
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
+
const nextOpen = typeof state === "boolean" ? state : !isOpen;
|
|
25
|
+
if (nextOpen === isOpen)
|
|
24
26
|
return;
|
|
25
27
|
if (!isActive)
|
|
26
|
-
setOpen(
|
|
27
|
-
setOpen(
|
|
28
|
-
}, [
|
|
28
|
+
return setOpen(nextOpen);
|
|
29
|
+
startTransition(() => setOpen(nextOpen));
|
|
30
|
+
}, [isOpen, isActive, setOpen]);
|
|
29
31
|
useEffect(() => {
|
|
30
32
|
if ((isActive && active) || defaultActive)
|
|
31
33
|
setOpen(true);
|
|
32
34
|
}, []);
|
|
33
35
|
useEffect(() => {
|
|
34
|
-
setOpen(
|
|
35
|
-
}, [
|
|
36
|
+
setOpen(isOpen);
|
|
37
|
+
}, [isOpen]);
|
|
36
38
|
const contextValue = useMemo(() => ({
|
|
37
39
|
contentRef,
|
|
38
|
-
time,
|
|
39
|
-
ease,
|
|
40
40
|
setExpand
|
|
41
|
-
}), [
|
|
42
|
-
time,
|
|
43
|
-
ease,
|
|
44
|
-
setExpand
|
|
45
|
-
]);
|
|
41
|
+
}), [setExpand]);
|
|
46
42
|
return (_jsx(AccordionsContext, { value: contextValue, children: _jsx(RootComponent, { ...othersProps, children: children }) }));
|
|
47
43
|
};
|
|
48
44
|
const Accordions = memo(AccordionsBase);
|
package/dist/components/index.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
export interface CollapseTypes {
|
|
2
2
|
defaultOpen?: boolean;
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
transDuration?: number;
|
|
4
|
+
transTiming?: string;
|
|
5
|
+
transMode?: "fade" | "normal";
|
|
6
|
+
transDelay?: number;
|
|
5
7
|
onInit?: (isInit: boolean) => void;
|
|
6
8
|
onChange?: (isOpen: boolean) => void;
|
|
7
9
|
onExpand?: (isOpen: boolean) => void;
|
|
8
10
|
onClose?: (isOpen: boolean) => void;
|
|
9
11
|
}
|
|
10
|
-
export declare function useCollapse({ defaultOpen,
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
export declare function useCollapse({ defaultOpen, transDuration, transTiming, transMode, transDelay, onInit, onChange, onExpand, onClose, }: CollapseTypes): {
|
|
13
|
+
setOpen: (state: boolean) => void;
|
|
14
|
+
contentRef: import("react").RefObject<HTMLDivElement | null>;
|
|
13
15
|
open: boolean;
|
|
14
16
|
};
|
|
@@ -1,55 +1,74 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useCallback, useState, useRef, useEffect } from "react";
|
|
2
|
+
import { useCallback, useState, useRef, useEffect, startTransition } from "react";
|
|
3
3
|
import { getDomTransTime, sleep } from "../utils/index.js";
|
|
4
|
-
export function useCollapse({ defaultOpen = false,
|
|
4
|
+
export function useCollapse({ defaultOpen = false, transDuration = 0.3, transTiming = "cubic-bezier(.24,0,0,.99)", transMode = "normal", transDelay = 0, onInit, onChange, onExpand, onClose, }) {
|
|
5
5
|
const contentRef = useRef(null);
|
|
6
|
-
const
|
|
6
|
+
const isMountedRef = useRef(false);
|
|
7
|
+
const isAnimatingRef = useRef(false);
|
|
8
|
+
const nextOpenRef = useRef(null);
|
|
7
9
|
const [open, setOpen] = useState(defaultOpen);
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const setOpenState = useCallback((state) => {
|
|
11
|
+
if (!isAnimatingRef.current)
|
|
12
|
+
return setOpen(state);
|
|
13
|
+
nextOpenRef.current = state;
|
|
14
|
+
}, [open]);
|
|
15
|
+
const setExpandTransition = useCallback((events) => {
|
|
12
16
|
const target = contentRef.current;
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
if (!target)
|
|
18
|
+
return;
|
|
19
|
+
if (events === "start") {
|
|
20
|
+
target.style.maxHeight = target.scrollHeight + "px";
|
|
21
|
+
target.style.opacity = transMode == "fade" ? "1" : "";
|
|
22
|
+
}
|
|
23
|
+
if (events === "open") {
|
|
24
|
+
target.style.maxHeight = "none";
|
|
25
|
+
target.style.opacity = transMode == "fade" ? "1" : "";
|
|
26
|
+
}
|
|
27
|
+
if (events === "close") {
|
|
28
|
+
target.style.maxHeight = "0";
|
|
29
|
+
target.style.opacity = transMode == "fade" ? "0" : "";
|
|
30
|
+
}
|
|
15
31
|
target.offsetHeight; // hack to force reflow
|
|
16
|
-
}, []);
|
|
17
|
-
const eventCallbacks = useCallback((state) => state
|
|
18
|
-
? onExpand?.(state)
|
|
19
|
-
: onClose?.(state), [onExpand, onClose]);
|
|
32
|
+
}, [transMode]);
|
|
20
33
|
const expandAnimate = useCallback(async (state) => {
|
|
21
|
-
if (
|
|
34
|
+
if (!contentRef?.current)
|
|
22
35
|
return;
|
|
23
|
-
|
|
36
|
+
isAnimatingRef.current = true;
|
|
24
37
|
onChange?.(state);
|
|
38
|
+
setExpandTransition("start");
|
|
25
39
|
const target = contentRef.current;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
if (!contentRef.current)
|
|
40
|
+
await sleep(state ? getDomTransTime(target) : 0);
|
|
41
|
+
setExpandTransition(state ? "open" : "close");
|
|
42
|
+
state ? onExpand?.(state) : onClose?.(state);
|
|
43
|
+
isAnimatingRef.current = false;
|
|
44
|
+
const nextState = nextOpenRef.current;
|
|
45
|
+
if (nextState == null || nextState == state)
|
|
34
46
|
return;
|
|
47
|
+
nextOpenRef.current = null;
|
|
48
|
+
setOpen(nextState);
|
|
49
|
+
}, [setExpandTransition, onChange, onExpand, onClose]);
|
|
50
|
+
useEffect(() => {
|
|
35
51
|
const target = contentRef.current;
|
|
36
|
-
target
|
|
37
|
-
target.style.transitionTimingFunction = ease;
|
|
38
|
-
if (!defaultOpen)
|
|
52
|
+
if (!target)
|
|
39
53
|
return;
|
|
40
|
-
|
|
54
|
+
target.style.overflow = "hidden";
|
|
55
|
+
target.style.transition = transDuration + "s";
|
|
56
|
+
target.style.transitionDelay = transDelay + "s";
|
|
57
|
+
target.style.transitionTimingFunction = transTiming;
|
|
58
|
+
if (defaultOpen)
|
|
59
|
+
startTransition(() => setExpandTransition("start"));
|
|
41
60
|
}, []);
|
|
42
61
|
useEffect(() => {
|
|
43
|
-
if (!
|
|
44
|
-
|
|
62
|
+
if (!isMountedRef.current) {
|
|
63
|
+
isMountedRef.current = true;
|
|
45
64
|
onInit?.(true);
|
|
46
65
|
return;
|
|
47
66
|
}
|
|
48
|
-
expandAnimate(open);
|
|
67
|
+
startTransition(() => expandAnimate(open));
|
|
49
68
|
}, [open]);
|
|
50
69
|
return {
|
|
70
|
+
setOpen: setOpenState,
|
|
51
71
|
contentRef,
|
|
52
|
-
|
|
53
|
-
open,
|
|
72
|
+
open
|
|
54
73
|
};
|
|
55
74
|
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as MyComponent } from './MyComponent';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as MyComponent } from './MyComponent';
|