@rpcbase/ui 0.18.0 → 0.20.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,10 +1,13 @@
1
1
  {
2
2
  "name": "@rpcbase/ui",
3
- "version": "0.18.0",
3
+ "version": "0.20.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
- "build": "tsc --watch",
8
11
  "release": "wireit"
9
12
  },
10
13
  "wireit": {
@@ -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: 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}
81
+ </div>
82
+ </div>
83
+ )}
84
+ </div>
85
+ );
86
+ };
@@ -0,0 +1,5 @@
1
+ import { MenuPopover } from "./MenuPopover"
2
+
3
+ export const Header = {
4
+ MenuPopover
5
+ }