@c9up/nebula 0.1.8 → 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 +5 -4
- 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,8 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* DropdownMenu — a menu opened from a button.
|
|
3
3
|
*
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
4
|
+
* The keyboard model comes from `wireMenu`: roving focus, type-ahead, arrows,
|
|
5
|
+
* Home/End, Escape and submenu traversal. It works on the RENDERED DOM — the
|
|
6
|
+
* `[data-nebula-item]` rows and their `role` — never on a description of it,
|
|
7
|
+
* which is what lets these parts compose freely and still behave like one
|
|
8
|
+
* menu.
|
|
9
|
+
*
|
|
10
|
+
* DropdownMenu({ children: () => html`
|
|
11
|
+
* ${DropdownMenuTrigger({ children: "Open" })}
|
|
12
|
+
* ${DropdownMenuContent({ children: () => html`
|
|
13
|
+
* ${DropdownMenuLabel({ children: "Account" })}
|
|
14
|
+
* ${DropdownMenuItem({ children: "Profile", onSelect: openProfile })}
|
|
15
|
+
* ${DropdownMenuSeparator({})}
|
|
16
|
+
* ${DropdownMenuItem({ children: "Delete", variant: "destructive" })}
|
|
17
|
+
* ` })}
|
|
18
|
+
* ` })
|
|
6
19
|
*
|
|
7
20
|
* Two behaviours are specific to a button-opened menu:
|
|
8
21
|
*
|
|
@@ -12,19 +25,53 @@
|
|
|
12
25
|
* - ArrowDown on the trigger opens the menu *and* enters it, which is the
|
|
13
26
|
* behaviour of every native menu button and the one users try first.
|
|
14
27
|
*/
|
|
15
|
-
import { type
|
|
28
|
+
import { type TemplateResult } from "@c9up/aurora";
|
|
29
|
+
import type { Parts, Slot } from "../lib/children.js";
|
|
16
30
|
import { type Reactive } from "../lib/props.js";
|
|
17
|
-
import type {
|
|
18
|
-
import { type MenuEntry } from "../primitives/menu.js";
|
|
31
|
+
import type { Align, Side } from "../primitives/floating.js";
|
|
19
32
|
export interface DropdownMenuProps {
|
|
20
|
-
trigger?: Slot;
|
|
21
|
-
entries: readonly MenuEntry[];
|
|
22
33
|
open?: Reactive<boolean>;
|
|
23
34
|
defaultOpen?: boolean;
|
|
24
35
|
onOpenChange?: (open: boolean) => void;
|
|
25
|
-
|
|
36
|
+
children?: Parts;
|
|
37
|
+
}
|
|
38
|
+
export declare const DropdownMenu: (props?: DropdownMenuProps | undefined) => TemplateResult;
|
|
39
|
+
export interface DropdownMenuTriggerProps {
|
|
40
|
+
children?: Slot;
|
|
26
41
|
class?: Reactive<string>;
|
|
27
|
-
triggerClass?: Reactive<string>;
|
|
28
|
-
contentClass?: Reactive<string>;
|
|
29
42
|
}
|
|
30
|
-
export declare const
|
|
43
|
+
export declare const DropdownMenuTrigger: (props?: DropdownMenuTriggerProps | undefined) => TemplateResult;
|
|
44
|
+
export interface DropdownMenuContentProps {
|
|
45
|
+
children?: Parts;
|
|
46
|
+
side?: Side;
|
|
47
|
+
align?: Align;
|
|
48
|
+
sideOffset?: number;
|
|
49
|
+
class?: Reactive<string>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The panel.
|
|
53
|
+
*
|
|
54
|
+
* Renders nothing where it is written — the menu portals it on open — and
|
|
55
|
+
* builds its children HERE, during setup, so every row sees the context.
|
|
56
|
+
*/
|
|
57
|
+
export declare const DropdownMenuContent: (props?: DropdownMenuContentProps | undefined) => TemplateResult;
|
|
58
|
+
export declare const DropdownMenuGroup: (props?: import("./ContextMenu.js").ContextMenuGroupProps) => TemplateResult;
|
|
59
|
+
export declare const DropdownMenuItem: (props?: import("./ContextMenu.js").ContextMenuItemProps) => TemplateResult;
|
|
60
|
+
export declare const DropdownMenuCheckboxItem: (props?: import("./ContextMenu.js").ContextMenuCheckboxItemProps) => TemplateResult;
|
|
61
|
+
export declare const DropdownMenuRadioGroup: (props?: import("./ContextMenu.js").ContextMenuRadioGroupProps) => TemplateResult;
|
|
62
|
+
export declare const DropdownMenuRadioItem: (props: import("./ContextMenu.js").ContextMenuRadioItemProps) => TemplateResult;
|
|
63
|
+
export declare const DropdownMenuLabel: (props?: import("./ContextMenu.js").ContextMenuLabelProps) => TemplateResult;
|
|
64
|
+
export declare const DropdownMenuSeparator: (props?: import("./ContextMenu.js").ContextMenuSeparatorProps) => TemplateResult;
|
|
65
|
+
export declare const DropdownMenuShortcut: (props?: import("./ContextMenu.js").ContextMenuShortcutProps) => TemplateResult;
|
|
66
|
+
export declare const DropdownMenuSub: (props?: import("./ContextMenu.js").ContextMenuSubProps) => TemplateResult;
|
|
67
|
+
export declare const DropdownMenuSubTrigger: (props?: import("./ContextMenu.js").ContextMenuSubTriggerProps) => TemplateResult;
|
|
68
|
+
export declare const DropdownMenuSubContent: (props?: import("./ContextMenu.js").ContextMenuSubContentProps) => TemplateResult;
|
|
69
|
+
/**
|
|
70
|
+
* Mount children outside the component's own DOM position.
|
|
71
|
+
*
|
|
72
|
+
* `DropdownMenuContent` does not need it — the menu portals its own panel —
|
|
73
|
+
* and it is exported because upstream exports it, doing here what its name
|
|
74
|
+
* says rather than standing in as a passthrough.
|
|
75
|
+
*/
|
|
76
|
+
export declare const DropdownMenuPortal: (props?: import("./ContextMenu.js").ContextMenuPortalProps) => TemplateResult;
|
|
77
|
+
export type { MenuCheckboxItemProps as DropdownMenuCheckboxItemProps, MenuGroupProps as DropdownMenuGroupProps, MenuItemProps as DropdownMenuItemProps, MenuLabelProps as DropdownMenuLabelProps, MenuPortalProps as DropdownMenuPortalProps, MenuRadioGroupProps as DropdownMenuRadioGroupProps, MenuRadioItemProps as DropdownMenuRadioItemProps, MenuSeparatorProps as DropdownMenuSeparatorProps, MenuShortcutProps as DropdownMenuShortcutProps, MenuSubContentProps as DropdownMenuSubContentProps, MenuSubProps as DropdownMenuSubProps, MenuSubTriggerProps as DropdownMenuSubTriggerProps, } from "../primitives/menuParts.js";
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* DropdownMenu — a menu opened from a button.
|
|
3
3
|
*
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
4
|
+
* The keyboard model comes from `wireMenu`: roving focus, type-ahead, arrows,
|
|
5
|
+
* Home/End, Escape and submenu traversal. It works on the RENDERED DOM — the
|
|
6
|
+
* `[data-nebula-item]` rows and their `role` — never on a description of it,
|
|
7
|
+
* which is what lets these parts compose freely and still behave like one
|
|
8
|
+
* menu.
|
|
9
|
+
*
|
|
10
|
+
* DropdownMenu({ children: () => html`
|
|
11
|
+
* ${DropdownMenuTrigger({ children: "Open" })}
|
|
12
|
+
* ${DropdownMenuContent({ children: () => html`
|
|
13
|
+
* ${DropdownMenuLabel({ children: "Account" })}
|
|
14
|
+
* ${DropdownMenuItem({ children: "Profile", onSelect: openProfile })}
|
|
15
|
+
* ${DropdownMenuSeparator({})}
|
|
16
|
+
* ${DropdownMenuItem({ children: "Delete", variant: "destructive" })}
|
|
17
|
+
* ` })}
|
|
18
|
+
* ` })
|
|
6
19
|
*
|
|
7
20
|
* Two behaviours are specific to a button-opened menu:
|
|
8
21
|
*
|
|
@@ -12,17 +25,21 @@
|
|
|
12
25
|
* - ArrowDown on the trigger opens the menu *and* enters it, which is the
|
|
13
26
|
* behaviour of every native menu button and the one users try first.
|
|
14
27
|
*/
|
|
15
|
-
import { component, html } from "@c9up/aurora";
|
|
28
|
+
import { component, createContext, html, inject, provide, } from "@c9up/aurora";
|
|
16
29
|
import { slot } from "../lib/children.js";
|
|
17
30
|
import { cn } from "../lib/cn.js";
|
|
18
31
|
import { uid } from "../lib/id.js";
|
|
32
|
+
import { slideInFromSide, zoomInOut } from "../lib/motion.js";
|
|
19
33
|
import { read } from "../lib/props.js";
|
|
20
34
|
import { controllable } from "../primitives/controllable.js";
|
|
21
35
|
import { floatingSurface } from "../primitives/floatingSurface.js";
|
|
22
|
-
import {
|
|
36
|
+
import { menuPanelClasses, wireMenu } from "../primitives/menu.js";
|
|
37
|
+
import { createMenuParts } from "../primitives/menuParts.js";
|
|
38
|
+
const DropdownMenuContext = createContext("DropdownMenu");
|
|
23
39
|
export const DropdownMenu = component((props) => {
|
|
24
|
-
const triggerId = uid("dropdown-trigger");
|
|
25
|
-
const contentId = uid("dropdown-content");
|
|
40
|
+
const triggerId = uid("dropdown-menu-trigger");
|
|
41
|
+
const contentId = uid("dropdown-menu-content");
|
|
42
|
+
let content;
|
|
26
43
|
const state = controllable({
|
|
27
44
|
value: props.open,
|
|
28
45
|
initial: props.defaultOpen ?? false,
|
|
@@ -36,56 +53,126 @@ export const DropdownMenu = component((props) => {
|
|
|
36
53
|
function close() {
|
|
37
54
|
state.set(false);
|
|
38
55
|
}
|
|
39
|
-
|
|
40
|
-
|
|
56
|
+
provide(DropdownMenuContext, {
|
|
57
|
+
triggerId,
|
|
58
|
+
contentId,
|
|
41
59
|
open: () => state.current(),
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
id: contentId,
|
|
47
|
-
entries: props.entries,
|
|
48
|
-
onCloseAll: close,
|
|
49
|
-
labelledBy: triggerId,
|
|
50
|
-
class: read(props.contentClass),
|
|
51
|
-
}),
|
|
52
|
-
onOpened: (panel) => {
|
|
53
|
-
const enterItems = enterOnOpen;
|
|
54
|
-
enterOnOpen = false;
|
|
55
|
-
unwire = wireMenu(panel, {
|
|
56
|
-
onCloseAll: close,
|
|
57
|
-
autoFocusFirst: enterItems,
|
|
58
|
-
});
|
|
59
|
-
// The panel takes focus only when no item did — it needs to hold focus
|
|
60
|
-
// so Escape and the arrows reach it rather than the page behind, but
|
|
61
|
-
// focusing it unconditionally steals focus straight back from the item
|
|
62
|
-
// `autoFocusFirst` just landed on, and opening with the keyboard would
|
|
63
|
-
// never reach the first entry.
|
|
64
|
-
if (!enterItems)
|
|
65
|
-
panel.focus({ preventScroll: true });
|
|
60
|
+
setOpen: (next) => state.set(next),
|
|
61
|
+
openAndEnter() {
|
|
62
|
+
enterOnOpen = true;
|
|
63
|
+
state.set(true);
|
|
66
64
|
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
closeAll: close,
|
|
66
|
+
register(registered) {
|
|
67
|
+
content = registered;
|
|
70
68
|
},
|
|
71
69
|
});
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
const parts = props.children?.();
|
|
71
|
+
if (content !== undefined) {
|
|
72
|
+
const registered = content;
|
|
73
|
+
const placement = registered.align === "center"
|
|
74
|
+
? registered.side
|
|
75
|
+
: `${registered.side}-${registered.align}`;
|
|
76
|
+
floatingSurface({
|
|
77
|
+
anchor: () => document.getElementById(triggerId),
|
|
78
|
+
open: () => state.current(),
|
|
79
|
+
onClose: close,
|
|
80
|
+
placement,
|
|
81
|
+
offset: registered.sideOffset,
|
|
82
|
+
content: () => renderPanel(registered, { id: contentId, labelledBy: triggerId }),
|
|
83
|
+
onOpened: (panel) => {
|
|
84
|
+
const enterItems = enterOnOpen;
|
|
85
|
+
enterOnOpen = false;
|
|
86
|
+
unwire = wireMenu(panel, {
|
|
87
|
+
onCloseAll: close,
|
|
88
|
+
autoFocusFirst: enterItems,
|
|
89
|
+
});
|
|
90
|
+
// The panel takes focus only when no item did — it needs to hold
|
|
91
|
+
// focus so Escape and the arrows reach it rather than the page
|
|
92
|
+
// behind, but focusing it unconditionally steals focus straight back
|
|
93
|
+
// from the item `autoFocusFirst` just landed on, and opening with
|
|
94
|
+
// the keyboard would never reach the first entry.
|
|
95
|
+
if (!enterItems)
|
|
96
|
+
panel.focus({ preventScroll: true });
|
|
97
|
+
},
|
|
98
|
+
onClosed: () => {
|
|
99
|
+
unwire?.();
|
|
100
|
+
unwire = null;
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return html `${parts}`;
|
|
105
|
+
});
|
|
106
|
+
export const DropdownMenuTrigger = component((props) => {
|
|
107
|
+
const menu = inject(DropdownMenuContext);
|
|
108
|
+
function onKeyDown(event) {
|
|
109
|
+
if (event.key !== "ArrowDown" &&
|
|
110
|
+
event.key !== "Enter" &&
|
|
111
|
+
event.key !== " ") {
|
|
74
112
|
return;
|
|
113
|
+
}
|
|
75
114
|
event.preventDefault();
|
|
76
|
-
|
|
77
|
-
state.set(true);
|
|
115
|
+
menu.openAndEnter();
|
|
78
116
|
}
|
|
79
117
|
return html `<button
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
118
|
+
type="button"
|
|
119
|
+
data-slot="dropdown-menu-trigger"
|
|
120
|
+
id="${menu.triggerId}"
|
|
121
|
+
aria-haspopup="menu"
|
|
122
|
+
aria-expanded="${() => (menu.open() ? "true" : "false")}"
|
|
123
|
+
aria-controls="${() => (menu.open() ? menu.contentId : undefined)}"
|
|
124
|
+
data-state="${() => (menu.open() ? "open" : "closed")}"
|
|
125
|
+
class="${() => cn(read(props.class))}"
|
|
126
|
+
@click="${() => menu.setOpen(!menu.open())}"
|
|
127
|
+
@keydown="${onKeyDown}"
|
|
128
|
+
>${slot(props.children)}</button>`;
|
|
91
129
|
});
|
|
130
|
+
/**
|
|
131
|
+
* The panel.
|
|
132
|
+
*
|
|
133
|
+
* Renders nothing where it is written — the menu portals it on open — and
|
|
134
|
+
* builds its children HERE, during setup, so every row sees the context.
|
|
135
|
+
*/
|
|
136
|
+
export const DropdownMenuContent = component((props) => {
|
|
137
|
+
const menu = inject(DropdownMenuContext);
|
|
138
|
+
const body = props.children?.();
|
|
139
|
+
menu.register({
|
|
140
|
+
body,
|
|
141
|
+
side: props.side ?? "bottom",
|
|
142
|
+
align: props.align ?? "start",
|
|
143
|
+
sideOffset: props.sideOffset ?? 4,
|
|
144
|
+
class: props.class,
|
|
145
|
+
});
|
|
146
|
+
return html ``;
|
|
147
|
+
});
|
|
148
|
+
const parts = createMenuParts("dropdown-menu", DropdownMenuContext);
|
|
149
|
+
export const DropdownMenuGroup = parts.Group;
|
|
150
|
+
export const DropdownMenuItem = parts.Item;
|
|
151
|
+
export const DropdownMenuCheckboxItem = parts.CheckboxItem;
|
|
152
|
+
export const DropdownMenuRadioGroup = parts.RadioGroup;
|
|
153
|
+
export const DropdownMenuRadioItem = parts.RadioItem;
|
|
154
|
+
export const DropdownMenuLabel = parts.Label;
|
|
155
|
+
export const DropdownMenuSeparator = parts.Separator;
|
|
156
|
+
export const DropdownMenuShortcut = parts.Shortcut;
|
|
157
|
+
export const DropdownMenuSub = parts.Sub;
|
|
158
|
+
export const DropdownMenuSubTrigger = parts.SubTrigger;
|
|
159
|
+
export const DropdownMenuSubContent = parts.SubContent;
|
|
160
|
+
/**
|
|
161
|
+
* Mount children outside the component's own DOM position.
|
|
162
|
+
*
|
|
163
|
+
* `DropdownMenuContent` does not need it — the menu portals its own panel —
|
|
164
|
+
* and it is exported because upstream exports it, doing here what its name
|
|
165
|
+
* says rather than standing in as a passthrough.
|
|
166
|
+
*/
|
|
167
|
+
export const DropdownMenuPortal = parts.Portal;
|
|
168
|
+
function renderPanel(registered, ids) {
|
|
169
|
+
return html `<div
|
|
170
|
+
data-slot="dropdown-menu-content"
|
|
171
|
+
id="${ids.id}"
|
|
172
|
+
role="menu"
|
|
173
|
+
aria-labelledby="${ids.labelledBy}"
|
|
174
|
+
aria-orientation="vertical"
|
|
175
|
+
tabindex="-1"
|
|
176
|
+
class="${cn(menuPanelClasses, zoomInOut, slideInFromSide, read(registered.class))}"
|
|
177
|
+
>${registered.body}</div>`;
|
|
178
|
+
}
|
package/dist/organisms/Form.js
CHANGED
|
@@ -36,7 +36,7 @@ import { Textarea } from "../atoms/Textarea.js";
|
|
|
36
36
|
import { slot } from "../lib/children.js";
|
|
37
37
|
import { cn } from "../lib/cn.js";
|
|
38
38
|
import { read } from "../lib/props.js";
|
|
39
|
-
import { Field, fieldIds } from "../molecules/Field.js";
|
|
39
|
+
import { Field, FieldDescription, FieldError, FieldLabel, fieldIds, } from "../molecules/Field.js";
|
|
40
40
|
/** Bind one key of a form. Call it at the field's own call site. */
|
|
41
41
|
export function bind(form, name) {
|
|
42
42
|
return {
|
|
@@ -91,12 +91,9 @@ export const TextField = component((props) => {
|
|
|
91
91
|
const visibleError = () => field.touched() ? (field.error() ?? undefined) : undefined;
|
|
92
92
|
return Field({
|
|
93
93
|
ids,
|
|
94
|
-
label: props.label,
|
|
95
|
-
description: props.description,
|
|
96
|
-
error: visibleError,
|
|
97
94
|
required: props.required,
|
|
98
95
|
disabled: props.disabled,
|
|
99
|
-
children: Input({
|
|
96
|
+
children: () => html `${props.label === undefined ? null : FieldLabel({ children: props.label })}${Input({
|
|
100
97
|
id: ids.control,
|
|
101
98
|
name,
|
|
102
99
|
type: props.type ?? "text",
|
|
@@ -109,7 +106,9 @@ export const TextField = component((props) => {
|
|
|
109
106
|
value: () => field.value(),
|
|
110
107
|
onInput: set,
|
|
111
108
|
onBlur: () => field.markTouched(),
|
|
112
|
-
})
|
|
109
|
+
})}${props.description === undefined
|
|
110
|
+
? null
|
|
111
|
+
: FieldDescription({ children: props.description })}${FieldError({ children: visibleError })}`,
|
|
113
112
|
});
|
|
114
113
|
});
|
|
115
114
|
/** The same, with a multi-line control. */
|
|
@@ -119,12 +118,9 @@ export const TextAreaField = component((props) => {
|
|
|
119
118
|
const visibleError = () => field.touched() ? (field.error() ?? undefined) : undefined;
|
|
120
119
|
return Field({
|
|
121
120
|
ids,
|
|
122
|
-
label: props.label,
|
|
123
|
-
description: props.description,
|
|
124
|
-
error: visibleError,
|
|
125
121
|
required: props.required,
|
|
126
122
|
disabled: props.disabled,
|
|
127
|
-
children: Textarea({
|
|
123
|
+
children: () => html `${props.label === undefined ? null : FieldLabel({ children: props.label })}${Textarea({
|
|
128
124
|
id: ids.control,
|
|
129
125
|
name,
|
|
130
126
|
rows: props.rows,
|
|
@@ -136,7 +132,9 @@ export const TextAreaField = component((props) => {
|
|
|
136
132
|
value: () => field.value(),
|
|
137
133
|
onInput: set,
|
|
138
134
|
onBlur: () => field.markTouched(),
|
|
139
|
-
})
|
|
135
|
+
})}${props.description === undefined
|
|
136
|
+
? null
|
|
137
|
+
: FieldDescription({ children: props.description })}${FieldError({ children: visibleError })}`,
|
|
140
138
|
});
|
|
141
139
|
});
|
|
142
140
|
/**
|
|
@@ -1,30 +1,50 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* HoverCard — a
|
|
2
|
+
* HoverCard — a preview that appears when the pointer rests on a link.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* HoverCard({ children: () => html`
|
|
5
|
+
* ${HoverCardTrigger({ children: "@nebula" })}
|
|
6
|
+
* ${HoverCardContent({ children: "…" })}
|
|
7
|
+
* ` })
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* and touch, so a hover card must preview something a click already reaches.
|
|
9
|
+
* Longer delays than a Tooltip, in both directions, and for different reasons.
|
|
10
|
+
* Opening is slow because a hover card is a heavier interruption than a label
|
|
11
|
+
* — it covers content, so it should appear only on a deliberate rest. Closing
|
|
12
|
+
* is slow because the card is meant to be entered: it holds links.
|
|
13
13
|
*
|
|
14
|
-
* `role="dialog"
|
|
15
|
-
*
|
|
16
|
-
* something containing a link.
|
|
14
|
+
* `role="dialog"`, not `role="tooltip"`. A tooltip is a label and must contain
|
|
15
|
+
* nothing interactive; a hover card is a small window that may.
|
|
17
16
|
*/
|
|
18
|
-
import { type
|
|
17
|
+
import { type TemplateResult } from "@c9up/aurora";
|
|
18
|
+
import type { Parts, Slot } from "../lib/children.js";
|
|
19
19
|
import { type Reactive } from "../lib/props.js";
|
|
20
|
-
import type {
|
|
20
|
+
import type { Align, Side } from "../primitives/floating.js";
|
|
21
21
|
export interface HoverCardProps {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
open?: Reactive<boolean>;
|
|
23
|
+
defaultOpen?: boolean;
|
|
24
|
+
onOpenChange?: (open: boolean) => void;
|
|
25
25
|
openDelay?: number;
|
|
26
26
|
closeDelay?: number;
|
|
27
|
+
children?: Parts;
|
|
28
|
+
}
|
|
29
|
+
export declare const HoverCard: (props?: HoverCardProps | undefined) => TemplateResult;
|
|
30
|
+
export interface HoverCardTriggerProps {
|
|
31
|
+
children?: Slot;
|
|
32
|
+
href?: string;
|
|
33
|
+
class?: Reactive<string>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* What the pointer rests on.
|
|
37
|
+
*
|
|
38
|
+
* An `<a>` when given an `href`, a `<span>` otherwise — upstream is used with
|
|
39
|
+
* `asChild` around a link, and a `<span>` wrapping one would put the hover
|
|
40
|
+
* target and the link in different elements.
|
|
41
|
+
*/
|
|
42
|
+
export declare const HoverCardTrigger: (props?: HoverCardTriggerProps | undefined) => TemplateResult;
|
|
43
|
+
export interface HoverCardContentProps {
|
|
44
|
+
children?: Slot;
|
|
45
|
+
side?: Side;
|
|
46
|
+
align?: Align;
|
|
47
|
+
sideOffset?: number;
|
|
27
48
|
class?: Reactive<string>;
|
|
28
|
-
contentClass?: Reactive<string>;
|
|
29
49
|
}
|
|
30
|
-
export declare const
|
|
50
|
+
export declare const HoverCardContent: (props?: HoverCardContentProps | undefined) => TemplateResult;
|
|
@@ -1,68 +1,144 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* HoverCard — a
|
|
2
|
+
* HoverCard — a preview that appears when the pointer rests on a link.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* HoverCard({ children: () => html`
|
|
5
|
+
* ${HoverCardTrigger({ children: "@nebula" })}
|
|
6
|
+
* ${HoverCardContent({ children: "…" })}
|
|
7
|
+
* ` })
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* and touch, so a hover card must preview something a click already reaches.
|
|
9
|
+
* Longer delays than a Tooltip, in both directions, and for different reasons.
|
|
10
|
+
* Opening is slow because a hover card is a heavier interruption than a label
|
|
11
|
+
* — it covers content, so it should appear only on a deliberate rest. Closing
|
|
12
|
+
* is slow because the card is meant to be entered: it holds links.
|
|
13
13
|
*
|
|
14
|
-
* `role="dialog"
|
|
15
|
-
*
|
|
16
|
-
* something containing a link.
|
|
14
|
+
* `role="dialog"`, not `role="tooltip"`. A tooltip is a label and must contain
|
|
15
|
+
* nothing interactive; a hover card is a small window that may.
|
|
17
16
|
*/
|
|
18
|
-
import { component, html, onUnmount,
|
|
17
|
+
import { component, createContext, html, inject, onUnmount, provide, } from "@c9up/aurora";
|
|
19
18
|
import { slot } from "../lib/children.js";
|
|
20
19
|
import { cn } from "../lib/cn.js";
|
|
21
20
|
import { uid } from "../lib/id.js";
|
|
22
|
-
import { zoomInOut } from "../lib/motion.js";
|
|
21
|
+
import { slideInFromSide, zoomInOut } from "../lib/motion.js";
|
|
23
22
|
import { read } from "../lib/props.js";
|
|
23
|
+
import { controllable } from "../primitives/controllable.js";
|
|
24
24
|
import { floatingSurface } from "../primitives/floatingSurface.js";
|
|
25
25
|
const OPEN_DELAY_MS = 700;
|
|
26
26
|
const CLOSE_DELAY_MS = 300;
|
|
27
|
+
const HoverCardContext = createContext("HoverCard");
|
|
27
28
|
export const HoverCard = component((props) => {
|
|
28
29
|
const triggerId = uid("hover-card-trigger");
|
|
29
30
|
const contentId = uid("hover-card-content");
|
|
30
|
-
|
|
31
|
+
let content;
|
|
31
32
|
let timer;
|
|
32
|
-
|
|
33
|
+
const state = controllable({
|
|
34
|
+
value: props.open,
|
|
35
|
+
initial: props.defaultOpen ?? false,
|
|
36
|
+
onChange: props.onOpenChange,
|
|
37
|
+
});
|
|
38
|
+
function cancelPending() {
|
|
33
39
|
if (timer !== undefined)
|
|
34
40
|
clearTimeout(timer);
|
|
35
41
|
timer = undefined;
|
|
36
42
|
}
|
|
37
43
|
function schedule(next, delay) {
|
|
38
|
-
|
|
39
|
-
timer = setTimeout(() =>
|
|
44
|
+
cancelPending();
|
|
45
|
+
timer = setTimeout(() => state.set(next), delay);
|
|
40
46
|
}
|
|
41
|
-
onUnmount(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
onUnmount(cancelPending);
|
|
48
|
+
provide(HoverCardContext, {
|
|
49
|
+
triggerId,
|
|
50
|
+
contentId,
|
|
51
|
+
open: () => state.current(),
|
|
52
|
+
scheduleOpen: () => schedule(true, props.openDelay ?? OPEN_DELAY_MS),
|
|
53
|
+
scheduleClose: () => schedule(false, props.closeDelay ?? CLOSE_DELAY_MS),
|
|
54
|
+
cancelPending,
|
|
55
|
+
register(registered) {
|
|
56
|
+
content = registered;
|
|
48
57
|
},
|
|
49
|
-
placement: props.placement ?? "bottom",
|
|
50
|
-
offset: 8,
|
|
51
|
-
content: () => html `<div
|
|
52
|
-
data-slot="hover-card-content"
|
|
53
|
-
id="${contentId}"
|
|
54
|
-
role="dialog"
|
|
55
|
-
aria-labelledby="${triggerId}"
|
|
56
|
-
class="${cn("bg-popover text-popover-foreground z-50 w-64 rounded-md border p-4 shadow-md outline-none", zoomInOut, read(props.contentClass))}"
|
|
57
|
-
@pointerenter="${clear}"
|
|
58
|
-
@pointerleave="${() => schedule(false, props.closeDelay ?? CLOSE_DELAY_MS)}"
|
|
59
|
-
>${slot(props.children)}</div>`,
|
|
60
58
|
});
|
|
59
|
+
const parts = props.children?.();
|
|
60
|
+
if (content !== undefined) {
|
|
61
|
+
const registered = content;
|
|
62
|
+
const placement = registered.align === "center"
|
|
63
|
+
? registered.side
|
|
64
|
+
: `${registered.side}-${registered.align}`;
|
|
65
|
+
floatingSurface({
|
|
66
|
+
anchor: () => document.getElementById(triggerId),
|
|
67
|
+
open: () => state.current(),
|
|
68
|
+
onClose: () => {
|
|
69
|
+
cancelPending();
|
|
70
|
+
state.set(false);
|
|
71
|
+
},
|
|
72
|
+
placement,
|
|
73
|
+
offset: registered.sideOffset,
|
|
74
|
+
content: () => renderContent(registered, {
|
|
75
|
+
contentId,
|
|
76
|
+
triggerId,
|
|
77
|
+
enter: cancelPending,
|
|
78
|
+
leave: () => schedule(false, props.closeDelay ?? CLOSE_DELAY_MS),
|
|
79
|
+
}),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return html `${parts}`;
|
|
83
|
+
});
|
|
84
|
+
/**
|
|
85
|
+
* What the pointer rests on.
|
|
86
|
+
*
|
|
87
|
+
* An `<a>` when given an `href`, a `<span>` otherwise — upstream is used with
|
|
88
|
+
* `asChild` around a link, and a `<span>` wrapping one would put the hover
|
|
89
|
+
* target and the link in different elements.
|
|
90
|
+
*/
|
|
91
|
+
export const HoverCardTrigger = component((props) => {
|
|
92
|
+
const card = inject(HoverCardContext);
|
|
93
|
+
const shared = {
|
|
94
|
+
id: card.triggerId,
|
|
95
|
+
open: () => card.open(),
|
|
96
|
+
};
|
|
97
|
+
if (props.href !== undefined) {
|
|
98
|
+
return html `<a
|
|
99
|
+
data-slot="hover-card-trigger"
|
|
100
|
+
id="${shared.id}"
|
|
101
|
+
href="${props.href}"
|
|
102
|
+
data-state="${() => (shared.open() ? "open" : "closed")}"
|
|
103
|
+
class="${() => cn(read(props.class))}"
|
|
104
|
+
@pointerenter="${() => card.scheduleOpen()}"
|
|
105
|
+
@pointerleave="${() => card.scheduleClose()}"
|
|
106
|
+
@focusin="${() => card.scheduleOpen()}"
|
|
107
|
+
@focusout="${() => card.scheduleClose()}"
|
|
108
|
+
>${slot(props.children)}</a>`;
|
|
109
|
+
}
|
|
61
110
|
return html `<span
|
|
62
111
|
data-slot="hover-card-trigger"
|
|
63
|
-
id="${
|
|
112
|
+
id="${shared.id}"
|
|
113
|
+
data-state="${() => (shared.open() ? "open" : "closed")}"
|
|
64
114
|
class="${() => cn("inline-flex", read(props.class))}"
|
|
65
|
-
@pointerenter="${() =>
|
|
66
|
-
@pointerleave="${() =>
|
|
67
|
-
|
|
115
|
+
@pointerenter="${() => card.scheduleOpen()}"
|
|
116
|
+
@pointerleave="${() => card.scheduleClose()}"
|
|
117
|
+
@focusin="${() => card.scheduleOpen()}"
|
|
118
|
+
@focusout="${() => card.scheduleClose()}"
|
|
119
|
+
>${slot(props.children)}</span>`;
|
|
120
|
+
});
|
|
121
|
+
export const HoverCardContent = component((props) => {
|
|
122
|
+
const card = inject(HoverCardContext);
|
|
123
|
+
card.register({
|
|
124
|
+
body: slot(props.children)(),
|
|
125
|
+
side: props.side ?? "bottom",
|
|
126
|
+
align: props.align ?? "center",
|
|
127
|
+
sideOffset: props.sideOffset ?? 8,
|
|
128
|
+
class: props.class,
|
|
129
|
+
});
|
|
130
|
+
return html ``;
|
|
68
131
|
});
|
|
132
|
+
function renderContent(registered, handlers) {
|
|
133
|
+
// The card stays open while the pointer is inside it, which is the only way
|
|
134
|
+
// to reach the links it exists to show.
|
|
135
|
+
return html `<div
|
|
136
|
+
data-slot="hover-card-content"
|
|
137
|
+
id="${handlers.contentId}"
|
|
138
|
+
role="dialog"
|
|
139
|
+
aria-labelledby="${handlers.triggerId}"
|
|
140
|
+
class="${cn("bg-popover text-popover-foreground z-50 w-64 origin-(--nebula-transform-origin) rounded-md border p-4 shadow-md outline-hidden", zoomInOut, slideInFromSide, read(registered.class))}"
|
|
141
|
+
@pointerenter="${() => handlers.enter()}"
|
|
142
|
+
@pointerleave="${() => handlers.leave()}"
|
|
143
|
+
>${registered.body}</div>`;
|
|
144
|
+
}
|