@xwadex/fesd-next 0.3.25 → 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.
@@ -1,6 +1,6 @@
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) => {
@@ -19,22 +19,22 @@ const AccordionsBase = (props) => {
19
19
  onExpand,
20
20
  onClose
21
21
  });
22
- const isExpand = isActive ? active : open;
22
+ const isOpen = isActive ? active : open;
23
23
  const setExpand = useCallback((state) => {
24
- const nextState = typeof state === "boolean" ? state : !isExpand;
25
- if (nextState === isExpand)
24
+ const nextOpen = typeof state === "boolean" ? state : !isOpen;
25
+ if (nextOpen === isOpen)
26
26
  return;
27
27
  if (!isActive)
28
- setOpen(nextState);
29
- setOpen(nextState);
30
- }, [isExpand, isActive, setOpen]);
28
+ return setOpen(nextOpen);
29
+ startTransition(() => setOpen(nextOpen));
30
+ }, [isOpen, isActive, setOpen]);
31
31
  useEffect(() => {
32
32
  if ((isActive && active) || defaultActive)
33
33
  setOpen(true);
34
34
  }, []);
35
35
  useEffect(() => {
36
- setOpen(isExpand);
37
- }, [isExpand,]);
36
+ setOpen(isOpen);
37
+ }, [isOpen]);
38
38
  const contextValue = useMemo(() => ({
39
39
  contentRef,
40
40
  setExpand
@@ -1,16 +1,16 @@
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
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 nextStateRef = useRef(null);
7
6
  const isMountedRef = useRef(false);
8
7
  const isAnimatingRef = useRef(false);
8
+ const nextOpenRef = useRef(null);
9
9
  const [open, setOpen] = useState(defaultOpen);
10
10
  const setOpenState = useCallback((state) => {
11
11
  if (!isAnimatingRef.current)
12
12
  return setOpen(state);
13
- nextStateRef.current = state;
13
+ nextOpenRef.current = state;
14
14
  }, [open]);
15
15
  const setExpandTransition = useCallback((events) => {
16
16
  const target = contentRef.current;
@@ -41,10 +41,10 @@ export function useCollapse({ defaultOpen = false, transDuration = 0.3, transTim
41
41
  setExpandTransition(state ? "open" : "close");
42
42
  state ? onExpand?.(state) : onClose?.(state);
43
43
  isAnimatingRef.current = false;
44
- const nextState = nextStateRef.current;
44
+ const nextState = nextOpenRef.current;
45
45
  if (nextState == null || nextState == state)
46
46
  return;
47
- nextStateRef.current = null;
47
+ nextOpenRef.current = null;
48
48
  setOpen(nextState);
49
49
  }, [setExpandTransition, onChange, onExpand, onClose]);
50
50
  useEffect(() => {
@@ -56,7 +56,7 @@ export function useCollapse({ defaultOpen = false, transDuration = 0.3, transTim
56
56
  target.style.transitionDelay = transDelay + "s";
57
57
  target.style.transitionTimingFunction = transTiming;
58
58
  if (defaultOpen)
59
- setExpandTransition("start");
59
+ startTransition(() => setExpandTransition("start"));
60
60
  }, []);
61
61
  useEffect(() => {
62
62
  if (!isMountedRef.current) {
@@ -64,11 +64,11 @@ export function useCollapse({ defaultOpen = false, transDuration = 0.3, transTim
64
64
  onInit?.(true);
65
65
  return;
66
66
  }
67
- expandAnimate(open);
67
+ startTransition(() => expandAnimate(open));
68
68
  }, [open]);
69
69
  return {
70
70
  setOpen: setOpenState,
71
71
  contentRef,
72
- open,
72
+ open
73
73
  };
74
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xwadex/fesd-next",
3
- "version": "0.3.25",
3
+ "version": "0.3.26",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",