@c9up/nebula 0.1.9 → 0.2.1
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/configure.d.ts +6 -0
- package/dist/configure.js +4 -22
- package/dist/lib/children.d.ts +30 -0
- package/dist/lib/id.d.ts +13 -29
- package/dist/lib/id.js +13 -39
- 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/dist/stubs.d.ts +13 -0
- package/dist/stubs.js +14 -0
- package/nebula.css +1 -1
- package/package.json +4 -3
- package/registry.json +18 -6
- package/src/atoms/Avatar.ts +141 -37
- package/src/atoms/index.ts +13 -1
- package/src/configure.ts +10 -23
- package/src/lib/children.ts +31 -0
- package/src/lib/id.ts +11 -39
- 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
- package/src/stubs.ts +16 -0
- package/stubs/config/nebula.stub +21 -0
|
@@ -1,28 +1,64 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Menubar —
|
|
2
|
+
* Menubar — the application menu bar.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
25
|
-
|
|
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
|
|
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 —
|
|
2
|
+
* Menubar — the application menu bar.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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 {
|
|
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
|
|
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 (
|
|
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 =
|
|
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
|
|
50
|
-
return
|
|
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: () =>
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
|
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
|
-
import type
|
|
20
|
-
import {
|
|
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
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
content?: Slot;
|
|
65
|
+
/** The page the user is on. */
|
|
66
|
+
active?: Reactive<boolean>;
|
|
67
|
+
class?: Reactive<string>;
|
|
35
68
|
}
|
|
36
|
-
export
|
|
37
|
-
|
|
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
|
-
|
|
41
|
-
export declare const
|
|
86
|
+
/** The arrow that points at the open trigger. */
|
|
87
|
+
export declare const NavigationMenuIndicator: (props?: NavigationMenuIndicatorProps | undefined) => TemplateResult;
|