@rpcbase/ui 0.19.0 → 0.21.0
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
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpcbase/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.ts",
|
|
8
|
+
"./header": "./src/header/index.tsx"
|
|
9
|
+
},
|
|
6
10
|
"scripts": {
|
|
7
11
|
"release": "wireit"
|
|
8
12
|
},
|
|
@@ -11,7 +15,8 @@
|
|
|
11
15
|
"command": "../../scripts/publish.js",
|
|
12
16
|
"dependencies": [],
|
|
13
17
|
"files": [
|
|
14
|
-
"package.json"
|
|
18
|
+
"package.json",
|
|
19
|
+
"src/**/*"
|
|
15
20
|
],
|
|
16
21
|
"output": [],
|
|
17
22
|
"env": {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import clsx from "clsx";
|
|
2
|
+
import { ReactNode, useState, useRef, useEffect } from "react";
|
|
3
|
+
import { Link } from "react-router";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export const MenuPopover = ({
|
|
7
|
+
href,
|
|
8
|
+
labelClassName,
|
|
9
|
+
labelActiveClassName,
|
|
10
|
+
labelElement,
|
|
11
|
+
isActive,
|
|
12
|
+
children,
|
|
13
|
+
}: {
|
|
14
|
+
href: string;
|
|
15
|
+
labelClassName: string;
|
|
16
|
+
labelActiveClassName: string;
|
|
17
|
+
labelElement: ReactNode;
|
|
18
|
+
isActive: boolean;
|
|
19
|
+
children: (props: { setIsOpen: (isOpen: boolean) => void }) => ReactNode
|
|
20
|
+
}) => {
|
|
21
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
22
|
+
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
23
|
+
const popoverRef = useRef(null);
|
|
24
|
+
|
|
25
|
+
const handleMouseEnter = () => {
|
|
26
|
+
if (timeoutRef.current) {
|
|
27
|
+
clearTimeout(timeoutRef.current);
|
|
28
|
+
}
|
|
29
|
+
setIsOpen(true);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const handleMouseLeave = () => {
|
|
33
|
+
timeoutRef.current = setTimeout(() => {
|
|
34
|
+
setIsOpen(false);
|
|
35
|
+
}, 120);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
return () => {
|
|
40
|
+
if (timeoutRef.current) {
|
|
41
|
+
clearTimeout(timeoutRef.current);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}, []);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div
|
|
48
|
+
className="flex"
|
|
49
|
+
ref={popoverRef}
|
|
50
|
+
onMouseEnter={handleMouseEnter}
|
|
51
|
+
onMouseLeave={handleMouseLeave}
|
|
52
|
+
>
|
|
53
|
+
<div className="relative flex">
|
|
54
|
+
<Link
|
|
55
|
+
to={href}
|
|
56
|
+
onClick={() => {
|
|
57
|
+
setIsOpen(false);
|
|
58
|
+
}}
|
|
59
|
+
className={clsx(
|
|
60
|
+
"relative z-10 -mb-px flex items-center border-b-2 pt-px text-sm font-medium text-gray-700 cursor-pointer transition-colors duration-200 ease-out hover:text-gray-800",
|
|
61
|
+
labelClassName,
|
|
62
|
+
isOpen || isActive ? labelActiveClassName : "border-transparent",
|
|
63
|
+
)}
|
|
64
|
+
>
|
|
65
|
+
{labelElement}
|
|
66
|
+
</Link>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
{isOpen && (
|
|
70
|
+
<div
|
|
71
|
+
className="absolute left-0 right-0 top-full z-20 text-gray-500 sm:text-sm"
|
|
72
|
+
style={{ width: "100vw", left: "50%", transform: "translateX(-50%)" }}
|
|
73
|
+
>
|
|
74
|
+
<div
|
|
75
|
+
aria-hidden="true"
|
|
76
|
+
className="absolute inset-0 top-1/2 bg-white shadow-sm"
|
|
77
|
+
/>
|
|
78
|
+
|
|
79
|
+
<div className="relative bg-white">
|
|
80
|
+
{children({ setIsOpen })}
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
};
|