@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.
Files changed (122) hide show
  1. package/dist/atoms/Avatar.d.ts +36 -9
  2. package/dist/atoms/Avatar.js +66 -27
  3. package/dist/atoms/index.d.ts +1 -1
  4. package/dist/atoms/index.js +1 -1
  5. package/dist/lib/children.d.ts +30 -0
  6. package/dist/lib/motion.d.ts +10 -0
  7. package/dist/lib/motion.js +10 -0
  8. package/dist/molecules/Accordion.d.ts +36 -15
  9. package/dist/molecules/Accordion.js +68 -45
  10. package/dist/molecules/Breadcrumb.d.ts +29 -11
  11. package/dist/molecules/Breadcrumb.js +52 -52
  12. package/dist/molecules/Collapsible.d.ts +18 -17
  13. package/dist/molecules/Collapsible.js +42 -34
  14. package/dist/molecules/Field.d.ts +66 -30
  15. package/dist/molecules/Field.js +106 -55
  16. package/dist/molecules/InputGroup.d.ts +39 -21
  17. package/dist/molecules/InputGroup.js +43 -27
  18. package/dist/molecules/InputOTP.d.ts +26 -3
  19. package/dist/molecules/InputOTP.js +109 -76
  20. package/dist/molecules/Message.js +5 -4
  21. package/dist/molecules/Pagination.d.ts +36 -11
  22. package/dist/molecules/Pagination.js +58 -74
  23. package/dist/molecules/RadioGroup.d.ts +25 -17
  24. package/dist/molecules/RadioGroup.js +47 -43
  25. package/dist/molecules/Resizable.d.ts +32 -7
  26. package/dist/molecules/Resizable.js +76 -49
  27. package/dist/molecules/Tabs.d.ts +49 -11
  28. package/dist/molecules/Tabs.js +107 -51
  29. package/dist/molecules/ToggleGroup.d.ts +16 -10
  30. package/dist/molecules/ToggleGroup.js +37 -21
  31. package/dist/molecules/index.d.ts +11 -11
  32. package/dist/molecules/index.js +11 -11
  33. package/dist/organisms/AlertDialog.d.ts +80 -28
  34. package/dist/organisms/AlertDialog.js +192 -67
  35. package/dist/organisms/Carousel.d.ts +25 -3
  36. package/dist/organisms/Carousel.js +75 -43
  37. package/dist/organisms/Combobox.d.ts +2 -1
  38. package/dist/organisms/Combobox.js +46 -16
  39. package/dist/organisms/Command.d.ts +73 -32
  40. package/dist/organisms/Command.js +209 -131
  41. package/dist/organisms/CommandDialog.js +5 -5
  42. package/dist/organisms/ContextMenu.d.ts +41 -19
  43. package/dist/organisms/ContextMenu.js +112 -71
  44. package/dist/organisms/DataTable.js +42 -8
  45. package/dist/organisms/Dialog.d.ts +97 -31
  46. package/dist/organisms/Dialog.js +193 -68
  47. package/dist/organisms/Drawer.d.ts +33 -10
  48. package/dist/organisms/Drawer.js +130 -52
  49. package/dist/organisms/DropdownMenu.d.ts +58 -11
  50. package/dist/organisms/DropdownMenu.js +137 -50
  51. package/dist/organisms/Form.js +9 -11
  52. package/dist/organisms/HoverCard.d.ts +39 -19
  53. package/dist/organisms/HoverCard.js +116 -40
  54. package/dist/organisms/Menubar.d.ts +55 -19
  55. package/dist/organisms/Menubar.js +166 -82
  56. package/dist/organisms/NavigationMenu.d.ts +77 -31
  57. package/dist/organisms/NavigationMenu.js +169 -98
  58. package/dist/organisms/Popover.d.ts +72 -12
  59. package/dist/organisms/Popover.js +132 -25
  60. package/dist/organisms/Questionnaire.js +5 -5
  61. package/dist/organisms/Select.d.ts +99 -18
  62. package/dist/organisms/Select.js +253 -111
  63. package/dist/organisms/Sheet.d.ts +57 -13
  64. package/dist/organisms/Sheet.js +141 -54
  65. package/dist/organisms/Sidebar.d.ts +146 -56
  66. package/dist/organisms/Sidebar.js +236 -128
  67. package/dist/organisms/Tooltip.d.ts +88 -14
  68. package/dist/organisms/Tooltip.js +210 -47
  69. package/dist/organisms/index.d.ts +15 -15
  70. package/dist/organisms/index.js +15 -15
  71. package/dist/primitives/floating.js +25 -0
  72. package/dist/primitives/floatingSurface.d.ts +11 -0
  73. package/dist/primitives/floatingSurface.js +8 -0
  74. package/dist/primitives/menu.d.ts +45 -1
  75. package/dist/primitives/menu.js +45 -14
  76. package/dist/primitives/menuParts.d.ts +113 -0
  77. package/dist/primitives/menuParts.js +207 -0
  78. package/nebula.css +1 -1
  79. package/package.json +3 -3
  80. package/registry.json +18 -6
  81. package/src/atoms/Avatar.ts +141 -37
  82. package/src/atoms/index.ts +13 -1
  83. package/src/lib/children.ts +31 -0
  84. package/src/lib/motion.ts +12 -0
  85. package/src/molecules/Accordion.ts +120 -60
  86. package/src/molecules/Breadcrumb.ts +77 -76
  87. package/src/molecules/Collapsible.ts +77 -41
  88. package/src/molecules/Field.ts +187 -72
  89. package/src/molecules/InputGroup.ts +88 -35
  90. package/src/molecules/InputOTP.ts +150 -86
  91. package/src/molecules/Message.ts +6 -4
  92. package/src/molecules/Pagination.ts +96 -101
  93. package/src/molecules/RadioGroup.ts +70 -59
  94. package/src/molecules/Resizable.ts +138 -75
  95. package/src/molecules/Tabs.ts +187 -74
  96. package/src/molecules/ToggleGroup.ts +77 -38
  97. package/src/molecules/index.ts +85 -8
  98. package/src/organisms/AlertDialog.ts +319 -82
  99. package/src/organisms/Carousel.ts +129 -52
  100. package/src/organisms/Combobox.ts +64 -19
  101. package/src/organisms/Command.ts +342 -159
  102. package/src/organisms/CommandDialog.ts +6 -6
  103. package/src/organisms/ContextMenu.ts +185 -83
  104. package/src/organisms/DataTable.ts +56 -10
  105. package/src/organisms/Dialog.ts +312 -102
  106. package/src/organisms/Drawer.ts +219 -71
  107. package/src/organisms/DropdownMenu.ts +219 -61
  108. package/src/organisms/Form.ts +48 -34
  109. package/src/organisms/HoverCard.ts +187 -53
  110. package/src/organisms/Menubar.ts +247 -87
  111. package/src/organisms/NavigationMenu.ts +306 -128
  112. package/src/organisms/Popover.ts +215 -39
  113. package/src/organisms/Questionnaire.ts +9 -6
  114. package/src/organisms/Select.ts +397 -130
  115. package/src/organisms/Sheet.ts +252 -83
  116. package/src/organisms/Sidebar.ts +438 -185
  117. package/src/organisms/Tooltip.ts +315 -65
  118. package/src/organisms/index.ts +284 -14
  119. package/src/primitives/floating.ts +33 -0
  120. package/src/primitives/floatingSurface.ts +19 -0
  121. package/src/primitives/menu.ts +79 -18
  122. package/src/primitives/menuParts.ts +371 -0
@@ -1,184 +1,362 @@
1
1
  /**
2
- * NavigationMenu — a site navigation bar with drop-down panels.
2
+ * NavigationMenu — a site's top-level navigation, with panels.
3
3
  *
4
- * Not a menu, despite the name Radix gave it, and the distinction changes the
5
- * markup. A menu is a list of *commands*; this is a list of *links*. So it is
6
- * a `<nav>` containing a list of anchors, with `aria-expanded` on the entries
7
- * that open a panel — never `role="menu"`, which would have a screen reader
8
- * announce a navigation bar as an application menu and offer the wrong
9
- * shortcuts for it.
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
- * Entries are either a plain link or a link with a panel. Hover opens a panel
12
- * after a short delay and keeps it open briefly on leave, because the pointer
13
- * has to travel from the trigger to the panel and a naive `mouseleave` closes
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
- * Every panel is reachable by keyboard: the trigger is a real button, Enter
17
- * and ArrowDown open it, Escape closes it and returns focus.
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 { component, html, onUnmount, signal } from "@c9up/aurora";
21
- import type { Child } from "../lib/children.js";
22
- import { type Slot, slot } from "../lib/children.js";
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 interface NavigationLink {
34
- label: Child;
35
- href: string;
36
- description?: Child;
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
- export interface NavigationItem {
40
- label: Child;
41
- /** A plain link. Mutually exclusive with `links` / `content`. */
42
- href?: string;
43
- /** A panel of links, laid out in a grid. */
44
- links?: readonly NavigationLink[];
45
- /** Arbitrary panel content, when a link grid is not enough. */
46
- content?: Slot;
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 triggerIds = props.items.map(() => uid("navigation-menu-trigger"));
88
+ const panels: PanelRegistration[] = [];
60
89
  const openIndex = signal(-1);
61
-
62
90
  let timer: ReturnType<typeof setTimeout> | undefined;
63
91
 
64
- function clear(): void {
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
- clear();
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
- clear();
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 id = triggerIds[openIndex()];
84
- return id === undefined ? null : document.getElementById(id);
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
- html`<div
92
- data-slot="navigation-menu-content"
93
- id="${contentId}"
94
- class="${cn(
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="${() => cn("relative flex max-w-max flex-1 items-center justify-center", read(props.class))}"
106
- >
107
- <ul class="flex flex-1 list-none items-center justify-center gap-1">
108
- ${props.items.map((item, index) => renderEntry(item, index))}
109
- </ul>
110
- </nav>`;
111
-
112
- function renderEntry(item: NavigationItem, index: number): Child {
113
- if (item.href !== undefined) {
114
- return html`<li>
115
- <a
116
- href="${item.href}"
117
- data-slot="navigation-menu-link"
118
- class="${triggerClasses}"
119
- @pointerenter="${() => {
120
- // Hovering a plain link while a panel is open closes it: the
121
- // pointer has left the panel's branch of the bar.
122
- if (openIndex() !== -1) schedule(-1, CLOSE_DELAY_MS);
123
- }}"
124
- >${item.label}</a>
125
- </li>`;
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`<li>
129
- <button
130
- type="button"
131
- id="${triggerIds[index]}"
132
- data-slot="navigation-menu-trigger"
133
- aria-expanded="${() => (openIndex() === index ? "true" : "false")}"
134
- aria-controls="${() => (openIndex() === index ? contentId : undefined)}"
135
- data-state="${() => (openIndex() === index ? "open" : "closed")}"
136
- class="${triggerClasses}"
137
- @click="${() => (openIndex() === index ? close() : openIndex(index))}"
138
- @pointerenter="${() => schedule(index, OPEN_DELAY_MS)}"
139
- @pointerleave="${() => schedule(-1, CLOSE_DELAY_MS)}"
140
- @keydown="${(event: KeyboardEvent) => {
141
- if (
142
- event.key === "ArrowDown" ||
143
- event.key === "Enter" ||
144
- event.key === " "
145
- ) {
146
- event.preventDefault();
147
- openIndex(index);
148
- }
149
- }}"
150
- >
151
- ${item.label}
152
- ${ChevronDownIcon({
153
- class:
154
- "relative top-px size-3 transition-transform duration-200 group-data-[state=open]:rotate-180",
155
- })}
156
- </button>
157
- </li>`;
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(item: NavigationItem | undefined): Child {
162
- if (item === undefined) return null;
163
- if (item.content !== undefined) return slot(item.content)();
164
-
165
- return html`<ul class="grid w-[400px] gap-1 md:w-[500px] md:grid-cols-2">
166
- ${(item.links ?? []).map(
167
- (link) => html`<li>
168
- <a
169
- href="${link.href}"
170
- class="hover:bg-accent hover:text-accent-foreground focus:bg-accent block select-none space-y-1 rounded-md p-3 leading-none no-underline outline-none transition-colors"
171
- >
172
- <div class="text-sm leading-none font-medium">${link.label}</div>
173
- ${
174
- link.description === undefined
175
- ? null
176
- : html`<p class="text-muted-foreground line-clamp-2 text-sm leading-snug">
177
- ${link.description}
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
  }