@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,28 +1,64 @@
1
1
  /**
2
- * Menubar — an application menu bar.
2
+ * Menubar — the application menu bar.
3
3
  *
4
- * A row of menu buttons where at most one menu is open. The behaviour that
5
- * makes it a menubar rather than a row of independent dropdowns is the
6
- * handover: once a menu is open, moving the pointer onto a neighbouring button
7
- * switches to it without a click, and ArrowLeft/ArrowRight do the same from
8
- * the keyboard. That is how every desktop menu bar behaves, and a row of
9
- * dropdowns that each need their own click is the thing users notice.
4
+ * Menubar({ children: () => html`
5
+ * ${MenubarMenu({ children: () => html`
6
+ * ${MenubarTrigger({ children: "File" })}
7
+ * ${MenubarContent({ children: () => html`
8
+ * ${MenubarItem({ children: "New", onSelect: create })}
9
+ * ` })}
10
+ * ` })}
11
+ * ` })
10
12
  *
11
- * One `floatingSurface` for the bar, not one per menu. The open menu is an
12
- * index, so switching moves the same surface to a new anchor instead of
13
- * closing one and opening another — which would flash, and would lose the
14
- * exit animation into the entry animation.
13
+ * One surface for the whole bar, not one per menu: only one menu is ever open,
14
+ * and moving between them is a change of anchor and contents rather than a
15
+ * close and an open. That is what makes left/right feel like walking a bar
16
+ * instead of dismissing and summoning.
17
+ *
18
+ * Each `MenubarMenu` claims an index as it is built, which is the order the
19
+ * arrows walk. The rows themselves come from `createMenuParts`, so a menu in
20
+ * the bar and a dropdown menu cannot drift apart.
15
21
  */
16
- import type { Child } from "../lib/children.js";
22
+ import { type TemplateResult } from "@c9up/aurora";
23
+ import type { Parts, Slot } from "../lib/children.js";
17
24
  import { type Reactive } from "../lib/props.js";
18
- import { type MenuEntry } from "../primitives/menu.js";
19
- export interface MenubarMenu {
20
- label: Child;
21
- entries: readonly MenuEntry[];
25
+ export interface MenubarProps {
26
+ class?: Reactive<string>;
27
+ children?: Parts;
28
+ }
29
+ export declare const Menubar: (props?: MenubarProps | undefined) => TemplateResult;
30
+ export interface MenubarMenuProps {
31
+ children?: Parts;
32
+ }
33
+ /**
34
+ * One menu in the bar.
35
+ *
36
+ * Claims its index as it is built, and provides it to the trigger and the
37
+ * content inside — neither of which then has to be told which menu it belongs
38
+ * to.
39
+ */
40
+ export declare const MenubarMenu: (props?: MenubarMenuProps | undefined) => TemplateResult;
41
+ export interface MenubarTriggerProps {
42
+ children?: Slot;
22
43
  disabled?: boolean;
44
+ class?: Reactive<string>;
23
45
  }
24
- export interface MenubarProps {
25
- menus: readonly MenubarMenu[];
46
+ export declare const MenubarTrigger: (props?: MenubarTriggerProps | undefined) => TemplateResult;
47
+ export interface MenubarContentProps {
48
+ children?: Parts;
26
49
  class?: Reactive<string>;
27
50
  }
28
- export declare const Menubar: (props?: MenubarProps | undefined) => import("@c9up/aurora").TemplateResult;
51
+ export declare const MenubarContent: (props?: MenubarContentProps | undefined) => TemplateResult;
52
+ export declare const MenubarGroup: (props?: import("./ContextMenu.js").ContextMenuGroupProps) => TemplateResult;
53
+ export declare const MenubarItem: (props?: import("./ContextMenu.js").ContextMenuItemProps) => TemplateResult;
54
+ export declare const MenubarCheckboxItem: (props?: import("./ContextMenu.js").ContextMenuCheckboxItemProps) => TemplateResult;
55
+ export declare const MenubarRadioGroup: (props?: import("./ContextMenu.js").ContextMenuRadioGroupProps) => TemplateResult;
56
+ export declare const MenubarRadioItem: (props: import("./ContextMenu.js").ContextMenuRadioItemProps) => TemplateResult;
57
+ export declare const MenubarLabel: (props?: import("./ContextMenu.js").ContextMenuLabelProps) => TemplateResult;
58
+ export declare const MenubarSeparator: (props?: import("./ContextMenu.js").ContextMenuSeparatorProps) => TemplateResult;
59
+ export declare const MenubarShortcut: (props?: import("./ContextMenu.js").ContextMenuShortcutProps) => TemplateResult;
60
+ export declare const MenubarSub: (props?: import("./ContextMenu.js").ContextMenuSubProps) => TemplateResult;
61
+ export declare const MenubarSubTrigger: (props?: import("./ContextMenu.js").ContextMenuSubTriggerProps) => TemplateResult;
62
+ export declare const MenubarSubContent: (props?: import("./ContextMenu.js").ContextMenuSubContentProps) => TemplateResult;
63
+ export declare const MenubarPortal: (props?: import("./ContextMenu.js").ContextMenuPortalProps) => TemplateResult;
64
+ export type { MenuCheckboxItemProps as MenubarCheckboxItemProps, MenuGroupProps as MenubarGroupProps, MenuItemProps as MenubarItemProps, MenuLabelProps as MenubarLabelProps, MenuPortalProps as MenubarPortalProps, MenuRadioGroupProps as MenubarRadioGroupProps, MenuRadioItemProps as MenubarRadioItemProps, MenuSeparatorProps as MenubarSeparatorProps, MenuShortcutProps as MenubarShortcutProps, MenuSubContentProps as MenubarSubContentProps, MenuSubProps as MenubarSubProps, MenuSubTriggerProps as MenubarSubTriggerProps, } from "../primitives/menuParts.js";
@@ -1,28 +1,39 @@
1
1
  /**
2
- * Menubar — an application menu bar.
2
+ * Menubar — the application menu bar.
3
3
  *
4
- * A row of menu buttons where at most one menu is open. The behaviour that
5
- * makes it a menubar rather than a row of independent dropdowns is the
6
- * handover: once a menu is open, moving the pointer onto a neighbouring button
7
- * switches to it without a click, and ArrowLeft/ArrowRight do the same from
8
- * the keyboard. That is how every desktop menu bar behaves, and a row of
9
- * dropdowns that each need their own click is the thing users notice.
4
+ * Menubar({ children: () => html`
5
+ * ${MenubarMenu({ children: () => html`
6
+ * ${MenubarTrigger({ children: "File" })}
7
+ * ${MenubarContent({ children: () => html`
8
+ * ${MenubarItem({ children: "New", onSelect: create })}
9
+ * ` })}
10
+ * ` })}
11
+ * ` })
10
12
  *
11
- * One `floatingSurface` for the bar, not one per menu. The open menu is an
12
- * index, so switching moves the same surface to a new anchor instead of
13
- * closing one and opening another — which would flash, and would lose the
14
- * exit animation into the entry animation.
13
+ * One surface for the whole bar, not one per menu: only one menu is ever open,
14
+ * and moving between them is a change of anchor and contents rather than a
15
+ * close and an open. That is what makes left/right feel like walking a bar
16
+ * instead of dismissing and summoning.
17
+ *
18
+ * Each `MenubarMenu` claims an index as it is built, which is the order the
19
+ * arrows walk. The rows themselves come from `createMenuParts`, so a menu in
20
+ * the bar and a dropdown menu cannot drift apart.
15
21
  */
16
- import { component, html, signal } from "@c9up/aurora";
22
+ import { component, createContext, html, inject, provide, signal, } from "@c9up/aurora";
23
+ import { slot } from "../lib/children.js";
17
24
  import { cn } from "../lib/cn.js";
18
25
  import { uid } from "../lib/id.js";
26
+ import { slideInFromSide, zoomInOut } from "../lib/motion.js";
19
27
  import { read } from "../lib/props.js";
20
28
  import { floatingSurface } from "../primitives/floatingSurface.js";
21
- import { menuPanel, wireMenu } from "../primitives/menu.js";
29
+ import { menuPanelClasses, wireMenu } from "../primitives/menu.js";
30
+ import { createMenuParts } from "../primitives/menuParts.js";
31
+ const triggerClasses = "focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex items-center rounded-sm px-2 py-1 text-sm font-medium outline-hidden select-none disabled:pointer-events-none disabled:opacity-50";
32
+ const MenubarContext = createContext("Menubar");
33
+ const MenubarMenuContext = createContext("MenubarMenu");
22
34
  export const Menubar = component((props) => {
23
35
  const contentId = uid("menubar-content");
24
- const triggerIds = props.menus.map(() => uid("menubar-trigger"));
25
- /** Index of the open menu, or `-1`. */
36
+ const menus = [];
26
37
  const openIndex = signal(-1);
27
38
  let unwire = null;
28
39
  let focusFirstOnOpen = false;
@@ -30,13 +41,22 @@ export const Menubar = component((props) => {
30
41
  openIndex(-1);
31
42
  }
32
43
  function openAt(index, withKeyboard) {
33
- if (props.menus[index]?.disabled === true)
44
+ if (menus[index]?.disabled === true)
34
45
  return;
35
46
  focusFirstOnOpen = withKeyboard;
36
47
  openIndex(index);
37
48
  }
49
+ function focusTrigger(index) {
50
+ const count = menus.length;
51
+ if (count === 0)
52
+ return;
53
+ const entry = menus[(index + count) % count];
54
+ if (entry === undefined)
55
+ return;
56
+ document.getElementById(entry.triggerId)?.focus({ preventScroll: true });
57
+ }
38
58
  function move(delta) {
39
- const count = props.menus.length;
59
+ const count = menus.length;
40
60
  if (count === 0)
41
61
  return;
42
62
  const from = openIndex();
@@ -44,21 +64,52 @@ export const Menubar = component((props) => {
44
64
  return;
45
65
  openAt((from + delta + count) % count, true);
46
66
  }
67
+ function onPanelKeyDown(event) {
68
+ if (event.key === "ArrowRight") {
69
+ event.preventDefault();
70
+ move(1);
71
+ }
72
+ else if (event.key === "ArrowLeft") {
73
+ event.preventDefault();
74
+ move(-1);
75
+ }
76
+ }
77
+ provide(MenubarContext, {
78
+ contentId,
79
+ claim(triggerId) {
80
+ menus.push({
81
+ triggerId,
82
+ disabled: false,
83
+ body: null,
84
+ panelClass: undefined,
85
+ });
86
+ return menus.length - 1;
87
+ },
88
+ describe(index, patch) {
89
+ const entry = menus[index];
90
+ if (entry === undefined)
91
+ return;
92
+ Object.assign(entry, patch);
93
+ },
94
+ openIndex: () => openIndex(),
95
+ openAt,
96
+ close,
97
+ focusTrigger,
98
+ closeAll: close,
99
+ });
100
+ const parts = props.children?.();
47
101
  floatingSurface({
48
102
  anchor: () => {
49
- const id = triggerIds[openIndex()];
50
- return id === undefined ? null : document.getElementById(id);
103
+ const entry = menus[openIndex()];
104
+ return entry === undefined
105
+ ? null
106
+ : document.getElementById(entry.triggerId);
51
107
  },
52
108
  open: () => openIndex() !== -1,
53
109
  onClose: close,
54
110
  placement: "bottom-start",
55
111
  offset: 4,
56
- content: () => menuPanel({
57
- id: contentId,
58
- entries: props.menus[openIndex()]?.entries ?? [],
59
- onCloseAll: close,
60
- labelledBy: triggerIds[openIndex()],
61
- }),
112
+ content: () => renderPanel(menus[openIndex()], contentId),
62
113
  onOpened: (panel) => {
63
114
  const enterItems = focusFirstOnOpen;
64
115
  focusFirstOnOpen = false;
@@ -81,67 +132,100 @@ export const Menubar = component((props) => {
81
132
  unwire = null;
82
133
  },
83
134
  });
84
- function onPanelKeyDown(event) {
85
- if (event.key === "ArrowRight") {
86
- event.preventDefault();
87
- move(1);
88
- }
89
- else if (event.key === "ArrowLeft") {
90
- event.preventDefault();
91
- move(-1);
92
- }
93
- }
94
135
  return html `<div
95
136
  data-slot="menubar"
96
137
  role="menubar"
97
138
  class="${() => cn("bg-background flex h-9 items-center gap-1 rounded-md border p-1 shadow-xs", read(props.class))}"
98
- >
99
- ${props.menus.map((menu, index) => renderTrigger(menu, index))}
100
- </div>`;
101
- function renderTrigger(menu, index) {
102
- return html `<button
103
- type="button"
104
- role="menuitem"
105
- data-slot="menubar-trigger"
106
- id="${triggerIds[index]}"
107
- aria-haspopup="menu"
108
- aria-expanded="${() => (openIndex() === index ? "true" : "false")}"
109
- aria-controls="${() => (openIndex() === index ? contentId : undefined)}"
110
- data-state="${() => (openIndex() === index ? "open" : "closed")}"
111
- ?disabled="${menu.disabled === true}"
112
- class="focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex select-none items-center rounded-sm px-2 py-1 text-sm font-medium outline-none disabled:pointer-events-none disabled:opacity-50"
113
- @click="${() => (openIndex() === index ? close() : openAt(index, false))}"
114
- @pointerenter="${() => {
115
- // Hover switches menus only while one is already open — otherwise
116
- // the bar would spring menus at a pointer merely passing over it.
117
- if (openIndex() !== -1)
118
- openAt(index, false);
119
- }}"
120
- @keydown="${(event) => {
121
- if (event.key === "ArrowDown" ||
122
- event.key === "Enter" ||
123
- event.key === " ") {
124
- event.preventDefault();
125
- openAt(index, true);
126
- }
127
- else if (event.key === "ArrowRight") {
128
- event.preventDefault();
129
- focusTrigger(index + 1);
130
- }
131
- else if (event.key === "ArrowLeft") {
132
- event.preventDefault();
133
- focusTrigger(index - 1);
134
- }
135
- }}"
136
- >${menu.label}</button>`;
139
+ >${parts}</div>`;
140
+ });
141
+ /**
142
+ * One menu in the bar.
143
+ *
144
+ * Claims its index as it is built, and provides it to the trigger and the
145
+ * content inside — neither of which then has to be told which menu it belongs
146
+ * to.
147
+ */
148
+ export const MenubarMenu = component((props) => {
149
+ const bar = inject(MenubarContext);
150
+ const triggerId = uid("menubar-trigger");
151
+ const index = bar.claim(triggerId);
152
+ provide(MenubarMenuContext, { index, triggerId });
153
+ return html `${props.children?.()}`;
154
+ });
155
+ export const MenubarTrigger = component((props) => {
156
+ const bar = inject(MenubarContext);
157
+ const menu = inject(MenubarMenuContext);
158
+ if (props.disabled === true) {
159
+ bar.describe(menu.index, { disabled: true });
137
160
  }
138
- function focusTrigger(index) {
139
- const count = props.menus.length;
140
- if (count === 0)
141
- return;
142
- const id = triggerIds[(index + count) % count];
143
- if (id === undefined)
144
- return;
145
- document.getElementById(id)?.focus({ preventScroll: true });
161
+ const open = () => bar.openIndex() === menu.index;
162
+ function onKeyDown(event) {
163
+ if (event.key === "ArrowDown" ||
164
+ event.key === "Enter" ||
165
+ event.key === " ") {
166
+ event.preventDefault();
167
+ bar.openAt(menu.index, true);
168
+ }
169
+ else if (event.key === "ArrowRight") {
170
+ event.preventDefault();
171
+ bar.focusTrigger(menu.index + 1);
172
+ }
173
+ else if (event.key === "ArrowLeft") {
174
+ event.preventDefault();
175
+ bar.focusTrigger(menu.index - 1);
176
+ }
146
177
  }
178
+ return html `<button
179
+ type="button"
180
+ data-slot="menubar-trigger"
181
+ id="${menu.triggerId}"
182
+ role="menuitem"
183
+ aria-haspopup="menu"
184
+ aria-expanded="${() => (open() ? "true" : "false")}"
185
+ aria-controls="${() => (open() ? bar.contentId : undefined)}"
186
+ data-state="${() => (open() ? "open" : "closed")}"
187
+ ?disabled="${props.disabled === true}"
188
+ class="${() => cn(triggerClasses, read(props.class))}"
189
+ @click="${() => (open() ? bar.close() : bar.openAt(menu.index, false))}"
190
+ @pointerenter="${() => {
191
+ // Hover switches menus only while one is already open — otherwise the
192
+ // bar would spring menus at a pointer merely passing over it.
193
+ if (bar.openIndex() !== -1)
194
+ bar.openAt(menu.index, false);
195
+ }}"
196
+ @keydown="${onKeyDown}"
197
+ >${slot(props.children)}</button>`;
147
198
  });
199
+ export const MenubarContent = component((props) => {
200
+ const bar = inject(MenubarContext);
201
+ const menu = inject(MenubarMenuContext);
202
+ bar.describe(menu.index, {
203
+ body: props.children?.(),
204
+ panelClass: props.class,
205
+ });
206
+ return html ``;
207
+ });
208
+ const parts = createMenuParts("menubar", MenubarContext);
209
+ export const MenubarGroup = parts.Group;
210
+ export const MenubarItem = parts.Item;
211
+ export const MenubarCheckboxItem = parts.CheckboxItem;
212
+ export const MenubarRadioGroup = parts.RadioGroup;
213
+ export const MenubarRadioItem = parts.RadioItem;
214
+ export const MenubarLabel = parts.Label;
215
+ export const MenubarSeparator = parts.Separator;
216
+ export const MenubarShortcut = parts.Shortcut;
217
+ export const MenubarSub = parts.Sub;
218
+ export const MenubarSubTrigger = parts.SubTrigger;
219
+ export const MenubarSubContent = parts.SubContent;
220
+ export const MenubarPortal = parts.Portal;
221
+ function renderPanel(entry, contentId) {
222
+ return html `<div
223
+ data-slot="menubar-content"
224
+ id="${contentId}"
225
+ role="menu"
226
+ aria-labelledby="${entry?.triggerId}"
227
+ aria-orientation="vertical"
228
+ tabindex="-1"
229
+ class="${cn(menuPanelClasses, zoomInOut, slideInFromSide, read(entry?.panelClass))}"
230
+ >${entry?.body}</div>`;
231
+ }
@@ -1,41 +1,87 @@
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
- import type { Child } from "../lib/children.js";
20
- import { type Slot } from "../lib/children.js";
26
+ import { type TemplateResult } from "@c9up/aurora";
27
+ import type { Parts, Slot } from "../lib/children.js";
21
28
  import { type Reactive } from "../lib/props.js";
22
- export interface NavigationLink {
23
- label: Child;
24
- href: string;
25
- description?: Child;
26
- }
27
- export interface NavigationItem {
28
- label: Child;
29
- /** A plain link. Mutually exclusive with `links` / `content`. */
29
+ export declare const triggerClasses = "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";
30
+ export interface NavigationMenuProps {
31
+ class?: Reactive<string>;
32
+ children?: Parts;
33
+ }
34
+ export declare const NavigationMenu: (props?: NavigationMenuProps | undefined) => TemplateResult;
35
+ export interface NavigationMenuListProps {
36
+ children?: Slot;
37
+ class?: Reactive<string>;
38
+ }
39
+ export declare const NavigationMenuList: (props?: NavigationMenuListProps | undefined) => TemplateResult;
40
+ export interface NavigationMenuItemProps {
41
+ children?: Parts;
42
+ class?: Reactive<string>;
43
+ }
44
+ /**
45
+ * One entry in the bar.
46
+ *
47
+ * Claims a panel slot as it is built, whether or not it holds one: the index
48
+ * is what the trigger and the content use to find each other, and an item that
49
+ * is only a link simply never fills its slot.
50
+ */
51
+ export declare const NavigationMenuItem: (props?: NavigationMenuItemProps | undefined) => TemplateResult;
52
+ export interface NavigationMenuTriggerProps {
53
+ children?: Slot;
54
+ class?: Reactive<string>;
55
+ }
56
+ export declare const NavigationMenuTrigger: (props?: NavigationMenuTriggerProps | undefined) => TemplateResult;
57
+ export interface NavigationMenuContentProps {
58
+ children?: Parts;
59
+ class?: Reactive<string>;
60
+ }
61
+ export declare const NavigationMenuContent: (props?: NavigationMenuContentProps | undefined) => TemplateResult;
62
+ export interface NavigationMenuLinkProps {
63
+ children?: Slot;
30
64
  href?: string;
31
- /** A panel of links, laid out in a grid. */
32
- links?: readonly NavigationLink[];
33
- /** Arbitrary panel content, when a link grid is not enough. */
34
- content?: Slot;
65
+ /** The page the user is on. */
66
+ active?: Reactive<boolean>;
67
+ class?: Reactive<string>;
35
68
  }
36
- export interface NavigationMenuProps {
37
- items: readonly NavigationItem[];
69
+ export declare const NavigationMenuLink: (props?: NavigationMenuLinkProps | undefined) => TemplateResult;
70
+ export interface NavigationMenuViewportProps {
71
+ class?: Reactive<string>;
72
+ }
73
+ /**
74
+ * Where the panel is drawn.
75
+ *
76
+ * NAMED DEVIATION — inert here. Radix renders every panel into one viewport
77
+ * element positioned under the bar, which is what its width and height
78
+ * animations interpolate against. The panel is portalled and positioned by
79
+ * `floatingSurface` instead, so this exists for a layout copied from upstream
80
+ * to keep its shape rather than to hold anything.
81
+ */
82
+ export declare const NavigationMenuViewport: (props?: NavigationMenuViewportProps | undefined) => TemplateResult;
83
+ export interface NavigationMenuIndicatorProps {
38
84
  class?: Reactive<string>;
39
85
  }
40
- export declare const triggerClasses = "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";
41
- export declare const NavigationMenu: (props?: NavigationMenuProps | undefined) => import("@c9up/aurora").TemplateResult;
86
+ /** The arrow that points at the open trigger. */
87
+ export declare const NavigationMenuIndicator: (props?: NavigationMenuIndicatorProps | undefined) => TemplateResult;