@theguild/components 8.1.0 → 8.2.0-alpha-20241216161831-bea3b73cdd26b75e8efa9f75f181dd8b1ad6f2e5
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/dropdown.d.mts +22 -0
- package/dist/components/dropdown.js +141 -0
- package/dist/components/index.d.mts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/version-dropdown.d.mts +13 -0
- package/dist/components/version-dropdown.js +21 -0
- package/dist/index.d.mts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface DropdownProps extends React.ComponentPropsWithoutRef<'div'> {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
}
|
|
6
|
+
declare function Dropdown({ children, className, ...props }: DropdownProps): react_jsx_runtime.JSX.Element;
|
|
7
|
+
interface DropdownTriggerProps extends React.ComponentPropsWithoutRef<'button'> {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
declare function DropdownTrigger({ children, className, ...props }: DropdownTriggerProps): react_jsx_runtime.JSX.Element;
|
|
11
|
+
interface DropdownContentProps extends React.ComponentPropsWithoutRef<'div'> {
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
declare function DropdownContent({ children, className, ...props }: DropdownContentProps): react_jsx_runtime.JSX.Element;
|
|
15
|
+
interface DropdownItemProps extends React.HTMLAttributes<HTMLElement> {
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
onClick?: () => void;
|
|
18
|
+
href?: string;
|
|
19
|
+
}
|
|
20
|
+
declare function DropdownItem({ children, onClick, className, href, ...props }: DropdownItemProps): react_jsx_runtime.JSX.Element;
|
|
21
|
+
|
|
22
|
+
export { Dropdown, DropdownContent, DropdownItem, DropdownTrigger };
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useId, useRef, useState } from "react";
|
|
3
|
+
import { cn } from "../cn";
|
|
4
|
+
const DropdownContext = createContext(null);
|
|
5
|
+
function useDropdownContext() {
|
|
6
|
+
const context = useContext(DropdownContext);
|
|
7
|
+
if (!context) {
|
|
8
|
+
throw new Error("Dropdown components must be used within a Dropdown");
|
|
9
|
+
}
|
|
10
|
+
return context;
|
|
11
|
+
}
|
|
12
|
+
function Dropdown({ children, className, ...props }) {
|
|
13
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
14
|
+
const [isHovering, setIsHovering] = useState(false);
|
|
15
|
+
const buttonId = useId();
|
|
16
|
+
const menuId = useId();
|
|
17
|
+
const menuRef = useRef(null);
|
|
18
|
+
const buttonRef = useRef(null);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const handleClickOutside = (event) => {
|
|
21
|
+
if (!menuRef.current?.contains(event.target) && !buttonRef.current?.contains(event.target)) {
|
|
22
|
+
setIsOpen(false);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const handleEscape = (event) => {
|
|
26
|
+
if (event.key === "Escape") {
|
|
27
|
+
setIsOpen(false);
|
|
28
|
+
buttonRef.current?.focus();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const handleFocusElsewhere = (event) => {
|
|
32
|
+
if (!menuRef.current?.contains(event.target) && !buttonRef.current?.contains(event.target)) {
|
|
33
|
+
setIsOpen(false);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
if (isOpen) {
|
|
37
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
38
|
+
document.addEventListener("keydown", handleEscape);
|
|
39
|
+
document.addEventListener("focus", handleFocusElsewhere);
|
|
40
|
+
}
|
|
41
|
+
return () => {
|
|
42
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
43
|
+
document.removeEventListener("keydown", handleEscape);
|
|
44
|
+
document.removeEventListener("focus", handleFocusElsewhere);
|
|
45
|
+
};
|
|
46
|
+
}, [isOpen]);
|
|
47
|
+
const dismissDelayMs = 200;
|
|
48
|
+
const isHoveringRef = useRef(isHovering);
|
|
49
|
+
isHoveringRef.current = isHovering;
|
|
50
|
+
return /* @__PURE__ */ jsx(
|
|
51
|
+
DropdownContext.Provider,
|
|
52
|
+
{
|
|
53
|
+
value: { isOpen, setIsOpen, isHovering, setIsHovering, buttonId, menuId, buttonRef, menuRef },
|
|
54
|
+
children: /* @__PURE__ */ jsx(
|
|
55
|
+
"div",
|
|
56
|
+
{
|
|
57
|
+
className: cn("relative", className),
|
|
58
|
+
onPointerEnter: () => {
|
|
59
|
+
setIsOpen(true);
|
|
60
|
+
setIsHovering(true);
|
|
61
|
+
},
|
|
62
|
+
onPointerLeave: () => {
|
|
63
|
+
if (isHovering) {
|
|
64
|
+
setIsHovering(false);
|
|
65
|
+
setTimeout(() => {
|
|
66
|
+
if (!isHoveringRef.current) {
|
|
67
|
+
setIsOpen(false);
|
|
68
|
+
}
|
|
69
|
+
}, dismissDelayMs);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
...props,
|
|
73
|
+
children
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
function DropdownTrigger({ children, className, ...props }) {
|
|
80
|
+
const { isOpen, setIsOpen, buttonId, menuId, buttonRef, setIsHovering } = useDropdownContext();
|
|
81
|
+
return /* @__PURE__ */ jsx(
|
|
82
|
+
"button",
|
|
83
|
+
{
|
|
84
|
+
ref: buttonRef,
|
|
85
|
+
id: buttonId,
|
|
86
|
+
"aria-expanded": isOpen,
|
|
87
|
+
"aria-controls": menuId,
|
|
88
|
+
"aria-haspopup": "true",
|
|
89
|
+
onClick: () => {
|
|
90
|
+
setIsOpen(true);
|
|
91
|
+
setIsHovering(false);
|
|
92
|
+
},
|
|
93
|
+
className: cn(className),
|
|
94
|
+
...props,
|
|
95
|
+
children
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
function DropdownContent({ children, className, ...props }) {
|
|
100
|
+
const { isOpen, buttonId, menuId, menuRef } = useDropdownContext();
|
|
101
|
+
return /* @__PURE__ */ jsx(
|
|
102
|
+
"div",
|
|
103
|
+
{
|
|
104
|
+
ref: menuRef,
|
|
105
|
+
id: menuId,
|
|
106
|
+
role: "menu",
|
|
107
|
+
"aria-labelledby": buttonId,
|
|
108
|
+
tabIndex: -1,
|
|
109
|
+
className: cn(className),
|
|
110
|
+
"data-state": isOpen ? "open" : "closed",
|
|
111
|
+
...props,
|
|
112
|
+
children
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
function DropdownItem({ children, onClick, className, href, ...props }) {
|
|
117
|
+
if (href) {
|
|
118
|
+
return /* @__PURE__ */ jsx("a", { role: "menuitem", href, className, onClick, ...props, children });
|
|
119
|
+
}
|
|
120
|
+
return /* @__PURE__ */ jsx(
|
|
121
|
+
"button",
|
|
122
|
+
{
|
|
123
|
+
role: "menuitem",
|
|
124
|
+
onClick,
|
|
125
|
+
className,
|
|
126
|
+
onKeyDown: (e) => {
|
|
127
|
+
if (e.key === "Enter" || e.key === "Space") {
|
|
128
|
+
onClick?.();
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
...props,
|
|
132
|
+
children
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
export {
|
|
137
|
+
Dropdown,
|
|
138
|
+
DropdownContent,
|
|
139
|
+
DropdownItem,
|
|
140
|
+
DropdownTrigger
|
|
141
|
+
};
|
|
@@ -29,6 +29,7 @@ export { ExploreMainProductCards, ExploreMainProductCardsProps } from './explore
|
|
|
29
29
|
export { TextLink, TextLinkProps } from './text-link.mjs';
|
|
30
30
|
export { ContactButton, ContactButtonProps, ContactTextLink, ContactTextLinkProps } from './contact-us.mjs';
|
|
31
31
|
export { Giscus } from './giscus.mjs';
|
|
32
|
+
export { VersionDropdown, VersionDropdownProps } from './version-dropdown.mjs';
|
|
32
33
|
export { GraphQLConfCard, GraphQLConfCardProps } from './hive-navigation/graphql-conf-card.mjs';
|
|
33
34
|
import 'react';
|
|
34
35
|
import 'url';
|
package/dist/components/index.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
interface VersionDropdownProps {
|
|
4
|
+
currentVersion: string;
|
|
5
|
+
versions: {
|
|
6
|
+
label: string;
|
|
7
|
+
href?: string;
|
|
8
|
+
onClick?: () => void;
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
11
|
+
declare function VersionDropdown({ currentVersion, versions }: VersionDropdownProps): react_jsx_runtime.JSX.Element;
|
|
12
|
+
|
|
13
|
+
export { VersionDropdown, type VersionDropdownProps };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Dropdown, DropdownContent, DropdownItem, DropdownTrigger } from "./dropdown";
|
|
4
|
+
function VersionDropdown({ currentVersion, versions }) {
|
|
5
|
+
return /* @__PURE__ */ jsxs(Dropdown, { className: "relative", children: [
|
|
6
|
+
/* @__PURE__ */ jsx(DropdownTrigger, { className: "hive-focus cursor-default rounded p-3 font-medium leading-normal text-green-800 aria-expanded:text-green-1000 dark:text-neutral-300 dark:aria-expanded:text-neutral-100", children: currentVersion }),
|
|
7
|
+
/* @__PURE__ */ jsx(DropdownContent, { className: "absolute -left-1/2 min-w-16 translate-y-2 rounded-xl border border-beige-200 bg-white p-1 shadow-[0px_16px_32px_-12px_rgba(14,18,27,0.10)] transition ease-in-out data-[state=closed]:translate-y-0 data-[state=closed]:scale-95 data-[state=closed]:opacity-0 data-[state=open]:fade-in-90 dark:border-neutral-800 dark:bg-neutral-900", children: versions.map((version) => /* @__PURE__ */ jsx(
|
|
8
|
+
DropdownItem,
|
|
9
|
+
{
|
|
10
|
+
href: version.href,
|
|
11
|
+
onClick: version.onClick,
|
|
12
|
+
className: "block rounded p-2 text-right text-green-800 transition-colors hover:bg-beige-100 hover:text-green-1000 dark:text-neutral-300 dark:hover:bg-neutral-800/50 dark:hover:text-neutral-100",
|
|
13
|
+
children: version.label
|
|
14
|
+
},
|
|
15
|
+
version.label
|
|
16
|
+
)) })
|
|
17
|
+
] });
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
VersionDropdown
|
|
21
|
+
};
|
package/dist/index.d.mts
CHANGED
|
@@ -32,6 +32,7 @@ export { ExploreMainProductCards, ExploreMainProductCardsProps } from './compone
|
|
|
32
32
|
export { TextLink, TextLinkProps } from './components/text-link.mjs';
|
|
33
33
|
export { ContactButton, ContactButtonProps, ContactTextLink, ContactTextLinkProps } from './components/contact-us.mjs';
|
|
34
34
|
export { Giscus } from './components/giscus.mjs';
|
|
35
|
+
export { VersionDropdown, VersionDropdownProps } from './components/version-dropdown.mjs';
|
|
35
36
|
export { PRODUCTS } from './products.mjs';
|
|
36
37
|
export { IEditorProps, IFeatureListProps, IHeroGradientProps, IHeroIllustrationProps, IHeroMarketplaceProps, IHeroVideoProps, IInfoListProps, ILink, IMarketplaceItemProps, IMarketplaceItemsProps, IMarketplaceListProps, IMarketplaceSearchProps, ISchemaPageProps } from './types/components.mjs';
|
|
37
38
|
export { AngularLettermark, ConductorLettermark, ConfigLettermark, EnvelopLettermark, FetsLettermark, GraphQLESlintLettermark, HeltinLettermark, InspectorLettermark, KitQLLettermark, ModulesLettermark, SSELettermark, ScalarsLettermark, SofaLettermark, StitchingLettermark, ToolsLettermark, WSLettermark, WhatsAppLettermark } from './logos/index.mjs';
|
package/package.json
CHANGED