@hrnec06/react_utils 1.7.1 → 1.7.2
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/package.json
CHANGED
|
@@ -2,6 +2,8 @@ import clsx from "clsx";
|
|
|
2
2
|
import useDialog from "./DialogContext";
|
|
3
3
|
import useTransition, { transitionDataAttributes } from "../../hooks/useTransition";
|
|
4
4
|
import { useRef } from "react";
|
|
5
|
+
import { useSyncRefAuto } from "../../hooks/useSyncRef";
|
|
6
|
+
import { Nullable } from "@hrnec06/util";
|
|
5
7
|
|
|
6
8
|
interface DialogBackdropProps extends Omit<React.HTMLProps<HTMLDivElement>, 'children'>
|
|
7
9
|
{
|
|
@@ -15,9 +17,9 @@ export default function DialogBackdrop({
|
|
|
15
17
|
{
|
|
16
18
|
const dialog = useDialog();
|
|
17
19
|
|
|
18
|
-
const
|
|
20
|
+
const { ref, value } = useSyncRefAuto<Nullable<HTMLDivElement>>(null);
|
|
19
21
|
|
|
20
|
-
const [visible, transitionData] = useTransition($transition,
|
|
22
|
+
const [visible, transitionData] = useTransition($transition, value, dialog.open);
|
|
21
23
|
|
|
22
24
|
if (!visible)
|
|
23
25
|
return undefined;
|
|
@@ -33,7 +35,7 @@ export default function DialogBackdrop({
|
|
|
33
35
|
{...props}
|
|
34
36
|
{...transitionDataAttributes(transitionData)}
|
|
35
37
|
|
|
36
|
-
ref={
|
|
38
|
+
ref={ref}
|
|
37
39
|
|
|
38
40
|
onClick={handleClick}
|
|
39
41
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import clsx from "clsx";
|
|
2
2
|
import useDialog from "./DialogContext";
|
|
3
3
|
import useTransition, { transitionDataAttributes } from "../../hooks/useTransition";
|
|
4
|
-
import { useRef } from "react";
|
|
4
|
+
import { useRef, useState } from "react";
|
|
5
|
+
import { Nullable } from "@hrnec06/util";
|
|
6
|
+
import useSyncRef, { useSyncRefAuto } from "../../hooks/useSyncRef";
|
|
5
7
|
|
|
6
8
|
interface DialogPanelProps extends React.HTMLProps<HTMLDivElement> {
|
|
7
9
|
$transition?: boolean
|
|
@@ -13,9 +15,9 @@ export default function DialogPanel({
|
|
|
13
15
|
{
|
|
14
16
|
const dialog = useDialog();
|
|
15
17
|
|
|
16
|
-
const
|
|
18
|
+
const { value, ref } = useSyncRefAuto<Nullable<HTMLDivElement>>(null);
|
|
17
19
|
|
|
18
|
-
const [visible, transitionData] = useTransition($transition,
|
|
20
|
+
const [visible, transitionData] = useTransition($transition, value, dialog.open);
|
|
19
21
|
|
|
20
22
|
if (!visible)
|
|
21
23
|
return undefined;
|
|
@@ -25,7 +27,7 @@ export default function DialogPanel({
|
|
|
25
27
|
{...props}
|
|
26
28
|
{...transitionDataAttributes(transitionData)}
|
|
27
29
|
|
|
28
|
-
ref={
|
|
30
|
+
ref={ref}
|
|
29
31
|
|
|
30
32
|
className={props.className}
|
|
31
33
|
>
|
package/src/hooks/useSyncRef.ts
CHANGED
|
@@ -14,4 +14,13 @@ export default function useSyncRef<T>(
|
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
return syncRefs;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function useSyncRefAuto<T>(value: T)
|
|
20
|
+
{
|
|
21
|
+
const ref = useRef(value);
|
|
22
|
+
const [localValue, setLocalValue] = useState(value);
|
|
23
|
+
const syncRef = useSyncRef(ref, setLocalValue);
|
|
24
|
+
|
|
25
|
+
return { value: localValue, ref: syncRef };
|
|
17
26
|
}
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,10 @@ import useFlags from "./hooks/useFlags";
|
|
|
10
10
|
import useNamespacedId from "./hooks/useNamespacedId";
|
|
11
11
|
import useTransition from "./hooks/useTransition";
|
|
12
12
|
import useLocalStorage from "./hooks/useLocalStorage";
|
|
13
|
+
import useDebounce from "./hooks/useDebounce";
|
|
14
|
+
import useEvent from "./hooks/useEvent";
|
|
15
|
+
import useLatestRef from "./hooks/useLatestRef";
|
|
16
|
+
import useSyncRef, { useSyncRefAuto } from "./hooks/useSyncRef";
|
|
13
17
|
|
|
14
18
|
import useSignal, { Signal } from "./hooks/useSignal";
|
|
15
19
|
import useLazySignal, { LazySignal } from "./hooks/useLazySignal";
|
|
@@ -22,10 +26,6 @@ import Dialog from "./components/Dialog/Dialog";
|
|
|
22
26
|
import ContextMenu from "./components/ContextMenu/ContextMenu";
|
|
23
27
|
|
|
24
28
|
import * as util from './lib/utils';
|
|
25
|
-
import useDebounce from "./hooks/useDebounce";
|
|
26
|
-
import useEvent from "./hooks/useEvent";
|
|
27
|
-
import useLatestRef from "./hooks/useLatestRef";
|
|
28
|
-
import useSyncRef from "./hooks/useSyncRef";
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
export {
|
|
@@ -42,6 +42,7 @@ export {
|
|
|
42
42
|
useLocalStorage,
|
|
43
43
|
useNamespacedId,
|
|
44
44
|
useSyncRef,
|
|
45
|
+
useSyncRefAuto,
|
|
45
46
|
useTransition,
|
|
46
47
|
useUpdateEffect,
|
|
47
48
|
useUUID,
|