@c9up/nebula 0.1.9 → 0.2.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/dist/atoms/Avatar.d.ts +36 -9
- package/dist/atoms/Avatar.js +66 -27
- package/dist/atoms/index.d.ts +1 -1
- package/dist/atoms/index.js +1 -1
- package/dist/lib/children.d.ts +30 -0
- package/dist/lib/motion.d.ts +10 -0
- package/dist/lib/motion.js +10 -0
- package/dist/molecules/Accordion.d.ts +36 -15
- package/dist/molecules/Accordion.js +68 -45
- package/dist/molecules/Breadcrumb.d.ts +29 -11
- package/dist/molecules/Breadcrumb.js +52 -52
- package/dist/molecules/Collapsible.d.ts +18 -17
- package/dist/molecules/Collapsible.js +42 -34
- package/dist/molecules/Field.d.ts +66 -30
- package/dist/molecules/Field.js +106 -55
- package/dist/molecules/InputGroup.d.ts +39 -21
- package/dist/molecules/InputGroup.js +43 -27
- package/dist/molecules/InputOTP.d.ts +26 -3
- package/dist/molecules/InputOTP.js +109 -76
- package/dist/molecules/Message.js +5 -4
- package/dist/molecules/Pagination.d.ts +36 -11
- package/dist/molecules/Pagination.js +58 -74
- package/dist/molecules/RadioGroup.d.ts +25 -17
- package/dist/molecules/RadioGroup.js +47 -43
- package/dist/molecules/Resizable.d.ts +32 -7
- package/dist/molecules/Resizable.js +76 -49
- package/dist/molecules/Tabs.d.ts +49 -11
- package/dist/molecules/Tabs.js +107 -51
- package/dist/molecules/ToggleGroup.d.ts +16 -10
- package/dist/molecules/ToggleGroup.js +37 -21
- package/dist/molecules/index.d.ts +11 -11
- package/dist/molecules/index.js +11 -11
- package/dist/organisms/AlertDialog.d.ts +80 -28
- package/dist/organisms/AlertDialog.js +192 -67
- package/dist/organisms/Carousel.d.ts +25 -3
- package/dist/organisms/Carousel.js +75 -43
- package/dist/organisms/Combobox.d.ts +2 -1
- package/dist/organisms/Combobox.js +46 -16
- package/dist/organisms/Command.d.ts +73 -32
- package/dist/organisms/Command.js +209 -131
- package/dist/organisms/CommandDialog.js +5 -5
- package/dist/organisms/ContextMenu.d.ts +41 -19
- package/dist/organisms/ContextMenu.js +112 -71
- package/dist/organisms/DataTable.js +42 -8
- package/dist/organisms/Dialog.d.ts +97 -31
- package/dist/organisms/Dialog.js +193 -68
- package/dist/organisms/Drawer.d.ts +33 -10
- package/dist/organisms/Drawer.js +130 -52
- package/dist/organisms/DropdownMenu.d.ts +58 -11
- package/dist/organisms/DropdownMenu.js +137 -50
- package/dist/organisms/Form.js +9 -11
- package/dist/organisms/HoverCard.d.ts +39 -19
- package/dist/organisms/HoverCard.js +116 -40
- package/dist/organisms/Menubar.d.ts +55 -19
- package/dist/organisms/Menubar.js +166 -82
- package/dist/organisms/NavigationMenu.d.ts +77 -31
- package/dist/organisms/NavigationMenu.js +169 -98
- package/dist/organisms/Popover.d.ts +72 -12
- package/dist/organisms/Popover.js +132 -25
- package/dist/organisms/Questionnaire.js +5 -5
- package/dist/organisms/Select.d.ts +99 -18
- package/dist/organisms/Select.js +253 -111
- package/dist/organisms/Sheet.d.ts +57 -13
- package/dist/organisms/Sheet.js +141 -54
- package/dist/organisms/Sidebar.d.ts +146 -56
- package/dist/organisms/Sidebar.js +236 -128
- package/dist/organisms/Tooltip.d.ts +88 -14
- package/dist/organisms/Tooltip.js +210 -47
- package/dist/organisms/index.d.ts +15 -15
- package/dist/organisms/index.js +15 -15
- package/dist/primitives/floating.js +25 -0
- package/dist/primitives/floatingSurface.d.ts +11 -0
- package/dist/primitives/floatingSurface.js +8 -0
- package/dist/primitives/menu.d.ts +45 -1
- package/dist/primitives/menu.js +45 -14
- package/dist/primitives/menuParts.d.ts +113 -0
- package/dist/primitives/menuParts.js +207 -0
- package/nebula.css +1 -1
- package/package.json +3 -3
- package/registry.json +18 -6
- package/src/atoms/Avatar.ts +141 -37
- package/src/atoms/index.ts +13 -1
- package/src/lib/children.ts +31 -0
- package/src/lib/motion.ts +12 -0
- package/src/molecules/Accordion.ts +120 -60
- package/src/molecules/Breadcrumb.ts +77 -76
- package/src/molecules/Collapsible.ts +77 -41
- package/src/molecules/Field.ts +187 -72
- package/src/molecules/InputGroup.ts +88 -35
- package/src/molecules/InputOTP.ts +150 -86
- package/src/molecules/Message.ts +6 -4
- package/src/molecules/Pagination.ts +96 -101
- package/src/molecules/RadioGroup.ts +70 -59
- package/src/molecules/Resizable.ts +138 -75
- package/src/molecules/Tabs.ts +187 -74
- package/src/molecules/ToggleGroup.ts +77 -38
- package/src/molecules/index.ts +85 -8
- package/src/organisms/AlertDialog.ts +319 -82
- package/src/organisms/Carousel.ts +129 -52
- package/src/organisms/Combobox.ts +64 -19
- package/src/organisms/Command.ts +342 -159
- package/src/organisms/CommandDialog.ts +6 -6
- package/src/organisms/ContextMenu.ts +185 -83
- package/src/organisms/DataTable.ts +56 -10
- package/src/organisms/Dialog.ts +312 -102
- package/src/organisms/Drawer.ts +219 -71
- package/src/organisms/DropdownMenu.ts +219 -61
- package/src/organisms/Form.ts +48 -34
- package/src/organisms/HoverCard.ts +187 -53
- package/src/organisms/Menubar.ts +247 -87
- package/src/organisms/NavigationMenu.ts +306 -128
- package/src/organisms/Popover.ts +215 -39
- package/src/organisms/Questionnaire.ts +9 -6
- package/src/organisms/Select.ts +397 -130
- package/src/organisms/Sheet.ts +252 -83
- package/src/organisms/Sidebar.ts +438 -185
- package/src/organisms/Tooltip.ts +315 -65
- package/src/organisms/index.ts +284 -14
- package/src/primitives/floating.ts +33 -0
- package/src/primitives/floatingSurface.ts +19 -0
- package/src/primitives/menu.ts +79 -18
- package/src/primitives/menuParts.ts +371 -0
|
@@ -1,184 +1,362 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* NavigationMenu — a site navigation
|
|
2
|
+
* NavigationMenu — a site's top-level navigation, with panels.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* NavigationMenu({ children: () => NavigationMenuList({ children: html`
|
|
5
|
+
* ${NavigationMenuItem({ children: () => html`
|
|
6
|
+
* ${NavigationMenuTrigger({ children: "Products" })}
|
|
7
|
+
* ${NavigationMenuContent({ children: () => html`
|
|
8
|
+
* ${NavigationMenuLink({ href: "/a", children: "Analytics" })}
|
|
9
|
+
* ` })}
|
|
10
|
+
* ` })}
|
|
11
|
+
* ${NavigationMenuItem({ children: () =>
|
|
12
|
+
* NavigationMenuLink({ href: "/pricing", children: "Pricing" })
|
|
13
|
+
* })}
|
|
14
|
+
* ` }) })
|
|
10
15
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* it in the gap between them.
|
|
16
|
+
* One surface for the whole bar, as in `Menubar`: only one panel is ever open,
|
|
17
|
+
* and moving between triggers is a change of anchor and contents rather than a
|
|
18
|
+
* close and an open.
|
|
15
19
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
20
|
+
* The delays are what make it usable with a pointer. Opening waits, so
|
|
21
|
+
* crossing the bar does not flash every panel on the way; closing waits
|
|
22
|
+
* longer, so travelling diagonally from a trigger into its panel does not
|
|
23
|
+
* dismiss it halfway. A plain link closes an open panel on hover, because the
|
|
24
|
+
* pointer has left that branch of the bar.
|
|
18
25
|
*/
|
|
19
26
|
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
import {
|
|
28
|
+
component,
|
|
29
|
+
createContext,
|
|
30
|
+
html,
|
|
31
|
+
inject,
|
|
32
|
+
onUnmount,
|
|
33
|
+
provide,
|
|
34
|
+
signal,
|
|
35
|
+
type TemplateResult,
|
|
36
|
+
} from "@c9up/aurora";
|
|
37
|
+
import type { Child, Parts, Slot } from "../lib/children.js";
|
|
38
|
+
import { slot } from "../lib/children.js";
|
|
23
39
|
import { cn } from "../lib/cn.js";
|
|
24
40
|
import { ChevronDownIcon } from "../lib/icons.js";
|
|
25
41
|
import { uid } from "../lib/id.js";
|
|
26
|
-
import { zoomInOut } from "../lib/motion.js";
|
|
42
|
+
import { slideInFromSide, zoomInOut } from "../lib/motion.js";
|
|
27
43
|
import { type Reactive, read } from "../lib/props.js";
|
|
28
44
|
import { floatingSurface } from "../primitives/floatingSurface.js";
|
|
29
45
|
|
|
30
46
|
const OPEN_DELAY_MS = 150;
|
|
31
47
|
const CLOSE_DELAY_MS = 250;
|
|
32
48
|
|
|
33
|
-
export
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
export const triggerClasses =
|
|
50
|
+
"group bg-background hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground focus-visible:ring-ring/50 data-[state=open]:bg-accent/50 inline-flex h-9 w-max items-center justify-center gap-1 rounded-md px-4 py-2 text-sm font-medium transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50";
|
|
51
|
+
|
|
52
|
+
interface PanelRegistration {
|
|
53
|
+
readonly triggerId: string;
|
|
54
|
+
body: Child;
|
|
55
|
+
panelClass: Reactive<string> | undefined;
|
|
37
56
|
}
|
|
38
57
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
58
|
+
interface NavigationMenuApi {
|
|
59
|
+
readonly contentId: string;
|
|
60
|
+
claim(triggerId: string): number;
|
|
61
|
+
describe(index: number, patch: Partial<PanelRegistration>): void;
|
|
62
|
+
readonly openIndex: () => number;
|
|
63
|
+
/** After the open delay, unless `immediate`. */
|
|
64
|
+
scheduleOpen(index: number, immediate: boolean): void;
|
|
65
|
+
scheduleClose(): void;
|
|
66
|
+
cancelPending(): void;
|
|
67
|
+
close(): void;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const NavigationMenuContext =
|
|
71
|
+
createContext<NavigationMenuApi>("NavigationMenu");
|
|
72
|
+
|
|
73
|
+
interface NavigationMenuItemApi {
|
|
74
|
+
readonly index: number;
|
|
75
|
+
readonly triggerId: string;
|
|
47
76
|
}
|
|
48
77
|
|
|
78
|
+
const NavigationMenuItemContext =
|
|
79
|
+
createContext<NavigationMenuItemApi>("NavigationMenuItem");
|
|
80
|
+
|
|
49
81
|
export interface NavigationMenuProps {
|
|
50
|
-
items: readonly NavigationItem[];
|
|
51
82
|
class?: Reactive<string>;
|
|
83
|
+
children?: Parts;
|
|
52
84
|
}
|
|
53
85
|
|
|
54
|
-
export const triggerClasses =
|
|
55
|
-
"group inline-flex h-9 w-max items-center justify-center gap-1 rounded-md bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground focus:outline-none disabled:pointer-events-none disabled:opacity-50 data-[state=open]:bg-accent/50";
|
|
56
|
-
|
|
57
86
|
export const NavigationMenu = component<NavigationMenuProps>((props) => {
|
|
58
87
|
const contentId = uid("navigation-menu-content");
|
|
59
|
-
const
|
|
88
|
+
const panels: PanelRegistration[] = [];
|
|
60
89
|
const openIndex = signal(-1);
|
|
61
|
-
|
|
62
90
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
63
91
|
|
|
64
|
-
function
|
|
92
|
+
function cancelPending(): void {
|
|
65
93
|
if (timer !== undefined) clearTimeout(timer);
|
|
66
94
|
timer = undefined;
|
|
67
95
|
}
|
|
68
96
|
|
|
69
97
|
function schedule(index: number, delay: number): void {
|
|
70
|
-
|
|
98
|
+
cancelPending();
|
|
99
|
+
if (delay === 0) {
|
|
100
|
+
openIndex(index);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
71
103
|
timer = setTimeout(() => openIndex(index), delay);
|
|
72
104
|
}
|
|
73
105
|
|
|
74
|
-
onUnmount(clear);
|
|
75
|
-
|
|
76
106
|
function close(): void {
|
|
77
|
-
|
|
107
|
+
cancelPending();
|
|
78
108
|
openIndex(-1);
|
|
79
109
|
}
|
|
80
110
|
|
|
111
|
+
onUnmount(cancelPending);
|
|
112
|
+
|
|
113
|
+
provide<NavigationMenuApi>(NavigationMenuContext, {
|
|
114
|
+
contentId,
|
|
115
|
+
claim(triggerId) {
|
|
116
|
+
panels.push({ triggerId, body: null, panelClass: undefined });
|
|
117
|
+
return panels.length - 1;
|
|
118
|
+
},
|
|
119
|
+
describe(index, patch) {
|
|
120
|
+
const entry = panels[index];
|
|
121
|
+
if (entry === undefined) return;
|
|
122
|
+
Object.assign(entry, patch);
|
|
123
|
+
},
|
|
124
|
+
openIndex: () => openIndex(),
|
|
125
|
+
scheduleOpen: (index, immediate) =>
|
|
126
|
+
schedule(index, immediate ? 0 : OPEN_DELAY_MS),
|
|
127
|
+
scheduleClose: () => schedule(-1, CLOSE_DELAY_MS),
|
|
128
|
+
cancelPending,
|
|
129
|
+
close,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const parts = props.children?.();
|
|
133
|
+
|
|
81
134
|
floatingSurface({
|
|
82
135
|
anchor: () => {
|
|
83
|
-
const
|
|
84
|
-
return
|
|
136
|
+
const entry = panels[openIndex()];
|
|
137
|
+
return entry === undefined
|
|
138
|
+
? null
|
|
139
|
+
: document.getElementById(entry.triggerId);
|
|
85
140
|
},
|
|
86
141
|
open: () => openIndex() !== -1,
|
|
87
142
|
onClose: close,
|
|
88
143
|
placement: "bottom-start",
|
|
89
144
|
offset: 6,
|
|
90
145
|
content: () =>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
"bg-popover text-popover-foreground z-50 rounded-md border p-4 shadow-md outline-none",
|
|
96
|
-
zoomInOut,
|
|
97
|
-
)}"
|
|
98
|
-
@pointerenter="${clear}"
|
|
99
|
-
@pointerleave="${() => schedule(-1, CLOSE_DELAY_MS)}"
|
|
100
|
-
>${renderPanel(props.items[openIndex()])}</div>`,
|
|
146
|
+
renderPanel(panels[openIndex()], contentId, {
|
|
147
|
+
enter: cancelPending,
|
|
148
|
+
leave: () => schedule(-1, CLOSE_DELAY_MS),
|
|
149
|
+
}),
|
|
101
150
|
});
|
|
102
151
|
|
|
103
152
|
return html`<nav
|
|
104
153
|
data-slot="navigation-menu"
|
|
105
|
-
class="${() =>
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
</nav>`;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
154
|
+
class="${() =>
|
|
155
|
+
cn(
|
|
156
|
+
"group/navigation-menu relative flex max-w-max flex-1 items-center justify-center",
|
|
157
|
+
read(props.class),
|
|
158
|
+
)}"
|
|
159
|
+
>${parts}</nav>`;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
export interface NavigationMenuListProps {
|
|
163
|
+
children?: Slot;
|
|
164
|
+
class?: Reactive<string>;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export const NavigationMenuList = component<NavigationMenuListProps>(
|
|
168
|
+
(props) => html`<ul
|
|
169
|
+
data-slot="navigation-menu-list"
|
|
170
|
+
class="${() =>
|
|
171
|
+
cn(
|
|
172
|
+
"group flex flex-1 list-none items-center justify-center gap-1",
|
|
173
|
+
read(props.class),
|
|
174
|
+
)}"
|
|
175
|
+
>${slot(props.children)}</ul>`,
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
export interface NavigationMenuItemProps {
|
|
179
|
+
children?: Parts;
|
|
180
|
+
class?: Reactive<string>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* One entry in the bar.
|
|
185
|
+
*
|
|
186
|
+
* Claims a panel slot as it is built, whether or not it holds one: the index
|
|
187
|
+
* is what the trigger and the content use to find each other, and an item that
|
|
188
|
+
* is only a link simply never fills its slot.
|
|
189
|
+
*/
|
|
190
|
+
export const NavigationMenuItem = component<NavigationMenuItemProps>(
|
|
191
|
+
(props) => {
|
|
192
|
+
const menu = inject(NavigationMenuContext);
|
|
193
|
+
const triggerId = uid("navigation-menu-trigger");
|
|
194
|
+
const index = menu.claim(triggerId);
|
|
195
|
+
provide<NavigationMenuItemApi>(NavigationMenuItemContext, {
|
|
196
|
+
index,
|
|
197
|
+
triggerId,
|
|
198
|
+
});
|
|
199
|
+
return html`<li
|
|
200
|
+
data-slot="navigation-menu-item"
|
|
201
|
+
class="${() => cn("relative", read(props.class))}"
|
|
202
|
+
>${props.children?.()}</li>`;
|
|
203
|
+
},
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
export interface NavigationMenuTriggerProps {
|
|
207
|
+
children?: Slot;
|
|
208
|
+
class?: Reactive<string>;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export const NavigationMenuTrigger = component<NavigationMenuTriggerProps>(
|
|
212
|
+
(props) => {
|
|
213
|
+
const menu = inject(NavigationMenuContext);
|
|
214
|
+
const item = inject(NavigationMenuItemContext);
|
|
215
|
+
const open = (): boolean => menu.openIndex() === item.index;
|
|
216
|
+
|
|
217
|
+
function onKeyDown(event: KeyboardEvent): void {
|
|
218
|
+
if (
|
|
219
|
+
event.key === "ArrowDown" ||
|
|
220
|
+
event.key === "Enter" ||
|
|
221
|
+
event.key === " "
|
|
222
|
+
) {
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
menu.scheduleOpen(item.index, true);
|
|
225
|
+
}
|
|
126
226
|
}
|
|
127
227
|
|
|
128
|
-
return html`<
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
228
|
+
return html`<button
|
|
229
|
+
type="button"
|
|
230
|
+
data-slot="navigation-menu-trigger"
|
|
231
|
+
id="${item.triggerId}"
|
|
232
|
+
aria-expanded="${() => (open() ? "true" : "false")}"
|
|
233
|
+
aria-controls="${() => (open() ? menu.contentId : undefined)}"
|
|
234
|
+
data-state="${() => (open() ? "open" : "closed")}"
|
|
235
|
+
class="${() => cn(triggerClasses, read(props.class))}"
|
|
236
|
+
@click="${() =>
|
|
237
|
+
open() ? menu.close() : menu.scheduleOpen(item.index, true)}"
|
|
238
|
+
@pointerenter="${() => menu.scheduleOpen(item.index, false)}"
|
|
239
|
+
@pointerleave="${() => menu.scheduleClose()}"
|
|
240
|
+
@keydown="${onKeyDown}"
|
|
241
|
+
>${slot(props.children)}${ChevronDownIcon({
|
|
242
|
+
class:
|
|
243
|
+
"relative top-px size-3 transition-transform duration-200 group-data-[state=open]:rotate-180",
|
|
244
|
+
})}</button>`;
|
|
245
|
+
},
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
export interface NavigationMenuContentProps {
|
|
249
|
+
children?: Parts;
|
|
250
|
+
class?: Reactive<string>;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export const NavigationMenuContent = component<NavigationMenuContentProps>(
|
|
254
|
+
(props) => {
|
|
255
|
+
const menu = inject(NavigationMenuContext);
|
|
256
|
+
const item = inject(NavigationMenuItemContext);
|
|
257
|
+
menu.describe(item.index, {
|
|
258
|
+
body: props.children?.(),
|
|
259
|
+
panelClass: props.class,
|
|
260
|
+
});
|
|
261
|
+
return html``;
|
|
262
|
+
},
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
export interface NavigationMenuLinkProps {
|
|
266
|
+
children?: Slot;
|
|
267
|
+
href?: string;
|
|
268
|
+
/** The page the user is on. */
|
|
269
|
+
active?: Reactive<boolean>;
|
|
270
|
+
class?: Reactive<string>;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export const NavigationMenuLink = component<NavigationMenuLinkProps>(
|
|
274
|
+
(props) => {
|
|
275
|
+
const menu = inject(NavigationMenuContext);
|
|
276
|
+
return html`<a
|
|
277
|
+
data-slot="navigation-menu-link"
|
|
278
|
+
href="${props.href}"
|
|
279
|
+
data-active="${() => (read(props.active) === true ? "true" : undefined)}"
|
|
280
|
+
aria-current="${() => (read(props.active) === true ? "page" : undefined)}"
|
|
281
|
+
class="${() =>
|
|
282
|
+
cn(
|
|
283
|
+
"hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground focus-visible:ring-ring/50 data-[active=true]:bg-accent/50 data-[active=true]:focus:bg-accent data-[active=true]:hover:bg-accent flex flex-col gap-1 rounded-sm p-2 text-sm transition-all outline-none focus-visible:ring-[3px] focus-visible:outline-1 [&_svg:not([class*='size-'])]:size-4",
|
|
284
|
+
read(props.class),
|
|
285
|
+
)}"
|
|
286
|
+
@pointerenter="${() => {
|
|
287
|
+
// Hovering a link in the BAR while a panel is open closes it: the
|
|
288
|
+
// pointer has left that branch. A link inside the panel is harmless
|
|
289
|
+
// — the panel's own `pointerenter` has already cancelled the close.
|
|
290
|
+
if (menu.openIndex() !== -1) menu.scheduleClose();
|
|
291
|
+
}}"
|
|
292
|
+
>${slot(props.children)}</a>`;
|
|
293
|
+
},
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
export interface NavigationMenuViewportProps {
|
|
297
|
+
class?: Reactive<string>;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Where the panel is drawn.
|
|
302
|
+
*
|
|
303
|
+
* NAMED DEVIATION — inert here. Radix renders every panel into one viewport
|
|
304
|
+
* element positioned under the bar, which is what its width and height
|
|
305
|
+
* animations interpolate against. The panel is portalled and positioned by
|
|
306
|
+
* `floatingSurface` instead, so this exists for a layout copied from upstream
|
|
307
|
+
* to keep its shape rather than to hold anything.
|
|
308
|
+
*/
|
|
309
|
+
export const NavigationMenuViewport = component<NavigationMenuViewportProps>(
|
|
310
|
+
(props) => html`<div
|
|
311
|
+
data-slot="navigation-menu-viewport"
|
|
312
|
+
class="${() =>
|
|
313
|
+
cn(
|
|
314
|
+
"absolute top-full left-0 isolate z-50 flex justify-center",
|
|
315
|
+
read(props.class),
|
|
316
|
+
)}"
|
|
317
|
+
></div>`,
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
export interface NavigationMenuIndicatorProps {
|
|
321
|
+
class?: Reactive<string>;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** The arrow that points at the open trigger. */
|
|
325
|
+
export const NavigationMenuIndicator = component<NavigationMenuIndicatorProps>(
|
|
326
|
+
(props) => {
|
|
327
|
+
const menu = inject(NavigationMenuContext);
|
|
328
|
+
return html`<div
|
|
329
|
+
data-slot="navigation-menu-indicator"
|
|
330
|
+
data-state="${() => (menu.openIndex() === -1 ? "hidden" : "visible")}"
|
|
331
|
+
class="${() =>
|
|
332
|
+
cn(
|
|
333
|
+
"top-full z-[1] flex h-1.5 items-end justify-center overflow-hidden data-[state=hidden]:animate-out data-[state=hidden]:fade-out data-[state=visible]:animate-in data-[state=visible]:fade-in",
|
|
334
|
+
read(props.class),
|
|
335
|
+
)}"
|
|
336
|
+
><div class="bg-border relative top-[60%] h-2 w-2 rotate-45 rounded-tl-sm shadow-md"></div></div>`;
|
|
337
|
+
},
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
interface PanelHandlers {
|
|
341
|
+
enter(): void;
|
|
342
|
+
leave(): void;
|
|
343
|
+
}
|
|
160
344
|
|
|
161
|
-
function renderPanel(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
</p>`
|
|
179
|
-
}
|
|
180
|
-
</a>
|
|
181
|
-
</li>`,
|
|
182
|
-
)}
|
|
183
|
-
</ul>`;
|
|
345
|
+
function renderPanel(
|
|
346
|
+
entry: PanelRegistration | undefined,
|
|
347
|
+
contentId: string,
|
|
348
|
+
handlers: PanelHandlers,
|
|
349
|
+
): TemplateResult {
|
|
350
|
+
return html`<div
|
|
351
|
+
data-slot="navigation-menu-content"
|
|
352
|
+
id="${contentId}"
|
|
353
|
+
class="${cn(
|
|
354
|
+
"bg-popover text-popover-foreground z-50 origin-(--nebula-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
|
|
355
|
+
zoomInOut,
|
|
356
|
+
slideInFromSide,
|
|
357
|
+
read(entry?.panelClass),
|
|
358
|
+
)}"
|
|
359
|
+
@pointerenter="${() => handlers.enter()}"
|
|
360
|
+
@pointerleave="${() => handlers.leave()}"
|
|
361
|
+
>${entry?.body}</div>`;
|
|
184
362
|
}
|