@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,139 +1,210 @@
|
|
|
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 { component, html, onUnmount, signal } from "@c9up/aurora";
|
|
26
|
+
import { component, createContext, html, inject, onUnmount, provide, signal, } from "@c9up/aurora";
|
|
20
27
|
import { slot } from "../lib/children.js";
|
|
21
28
|
import { cn } from "../lib/cn.js";
|
|
22
29
|
import { ChevronDownIcon } from "../lib/icons.js";
|
|
23
30
|
import { uid } from "../lib/id.js";
|
|
24
|
-
import { zoomInOut } from "../lib/motion.js";
|
|
31
|
+
import { slideInFromSide, zoomInOut } from "../lib/motion.js";
|
|
25
32
|
import { read } from "../lib/props.js";
|
|
26
33
|
import { floatingSurface } from "../primitives/floatingSurface.js";
|
|
27
34
|
const OPEN_DELAY_MS = 150;
|
|
28
35
|
const CLOSE_DELAY_MS = 250;
|
|
29
|
-
export const triggerClasses = "group inline-flex h-9 w-max items-center justify-center gap-1 rounded-md
|
|
36
|
+
export 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";
|
|
37
|
+
const NavigationMenuContext = createContext("NavigationMenu");
|
|
38
|
+
const NavigationMenuItemContext = createContext("NavigationMenuItem");
|
|
30
39
|
export const NavigationMenu = component((props) => {
|
|
31
40
|
const contentId = uid("navigation-menu-content");
|
|
32
|
-
const
|
|
41
|
+
const panels = [];
|
|
33
42
|
const openIndex = signal(-1);
|
|
34
43
|
let timer;
|
|
35
|
-
function
|
|
44
|
+
function cancelPending() {
|
|
36
45
|
if (timer !== undefined)
|
|
37
46
|
clearTimeout(timer);
|
|
38
47
|
timer = undefined;
|
|
39
48
|
}
|
|
40
49
|
function schedule(index, delay) {
|
|
41
|
-
|
|
50
|
+
cancelPending();
|
|
51
|
+
if (delay === 0) {
|
|
52
|
+
openIndex(index);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
42
55
|
timer = setTimeout(() => openIndex(index), delay);
|
|
43
56
|
}
|
|
44
|
-
onUnmount(clear);
|
|
45
57
|
function close() {
|
|
46
|
-
|
|
58
|
+
cancelPending();
|
|
47
59
|
openIndex(-1);
|
|
48
60
|
}
|
|
61
|
+
onUnmount(cancelPending);
|
|
62
|
+
provide(NavigationMenuContext, {
|
|
63
|
+
contentId,
|
|
64
|
+
claim(triggerId) {
|
|
65
|
+
panels.push({ triggerId, body: null, panelClass: undefined });
|
|
66
|
+
return panels.length - 1;
|
|
67
|
+
},
|
|
68
|
+
describe(index, patch) {
|
|
69
|
+
const entry = panels[index];
|
|
70
|
+
if (entry === undefined)
|
|
71
|
+
return;
|
|
72
|
+
Object.assign(entry, patch);
|
|
73
|
+
},
|
|
74
|
+
openIndex: () => openIndex(),
|
|
75
|
+
scheduleOpen: (index, immediate) => schedule(index, immediate ? 0 : OPEN_DELAY_MS),
|
|
76
|
+
scheduleClose: () => schedule(-1, CLOSE_DELAY_MS),
|
|
77
|
+
cancelPending,
|
|
78
|
+
close,
|
|
79
|
+
});
|
|
80
|
+
const parts = props.children?.();
|
|
49
81
|
floatingSurface({
|
|
50
82
|
anchor: () => {
|
|
51
|
-
const
|
|
52
|
-
return
|
|
83
|
+
const entry = panels[openIndex()];
|
|
84
|
+
return entry === undefined
|
|
85
|
+
? null
|
|
86
|
+
: document.getElementById(entry.triggerId);
|
|
53
87
|
},
|
|
54
88
|
open: () => openIndex() !== -1,
|
|
55
89
|
onClose: close,
|
|
56
90
|
placement: "bottom-start",
|
|
57
91
|
offset: 6,
|
|
58
|
-
content: () =>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
@pointerenter="${clear}"
|
|
63
|
-
@pointerleave="${() => schedule(-1, CLOSE_DELAY_MS)}"
|
|
64
|
-
>${renderPanel(props.items[openIndex()])}</div>`,
|
|
92
|
+
content: () => renderPanel(panels[openIndex()], contentId, {
|
|
93
|
+
enter: cancelPending,
|
|
94
|
+
leave: () => schedule(-1, CLOSE_DELAY_MS),
|
|
95
|
+
}),
|
|
65
96
|
});
|
|
66
97
|
return html `<nav
|
|
67
98
|
data-slot="navigation-menu"
|
|
68
|
-
class="${() => cn("relative flex max-w-max flex-1 items-center justify-center", read(props.class))}"
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
99
|
+
class="${() => cn("group/navigation-menu relative flex max-w-max flex-1 items-center justify-center", read(props.class))}"
|
|
100
|
+
>${parts}</nav>`;
|
|
101
|
+
});
|
|
102
|
+
export const NavigationMenuList = component((props) => html `<ul
|
|
103
|
+
data-slot="navigation-menu-list"
|
|
104
|
+
class="${() => cn("group flex flex-1 list-none items-center justify-center gap-1", read(props.class))}"
|
|
105
|
+
>${slot(props.children)}</ul>`);
|
|
106
|
+
/**
|
|
107
|
+
* One entry in the bar.
|
|
108
|
+
*
|
|
109
|
+
* Claims a panel slot as it is built, whether or not it holds one: the index
|
|
110
|
+
* is what the trigger and the content use to find each other, and an item that
|
|
111
|
+
* is only a link simply never fills its slot.
|
|
112
|
+
*/
|
|
113
|
+
export const NavigationMenuItem = component((props) => {
|
|
114
|
+
const menu = inject(NavigationMenuContext);
|
|
115
|
+
const triggerId = uid("navigation-menu-trigger");
|
|
116
|
+
const index = menu.claim(triggerId);
|
|
117
|
+
provide(NavigationMenuItemContext, {
|
|
118
|
+
index,
|
|
119
|
+
triggerId,
|
|
120
|
+
});
|
|
121
|
+
return html `<li
|
|
122
|
+
data-slot="navigation-menu-item"
|
|
123
|
+
class="${() => cn("relative", read(props.class))}"
|
|
124
|
+
>${props.children?.()}</li>`;
|
|
125
|
+
});
|
|
126
|
+
export const NavigationMenuTrigger = component((props) => {
|
|
127
|
+
const menu = inject(NavigationMenuContext);
|
|
128
|
+
const item = inject(NavigationMenuItemContext);
|
|
129
|
+
const open = () => menu.openIndex() === item.index;
|
|
130
|
+
function onKeyDown(event) {
|
|
131
|
+
if (event.key === "ArrowDown" ||
|
|
132
|
+
event.key === "Enter" ||
|
|
133
|
+
event.key === " ") {
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
menu.scheduleOpen(item.index, true);
|
|
89
136
|
}
|
|
90
|
-
return html `<li>
|
|
91
|
-
<button
|
|
92
|
-
type="button"
|
|
93
|
-
id="${triggerIds[index]}"
|
|
94
|
-
data-slot="navigation-menu-trigger"
|
|
95
|
-
aria-expanded="${() => (openIndex() === index ? "true" : "false")}"
|
|
96
|
-
aria-controls="${() => (openIndex() === index ? contentId : undefined)}"
|
|
97
|
-
data-state="${() => (openIndex() === index ? "open" : "closed")}"
|
|
98
|
-
class="${triggerClasses}"
|
|
99
|
-
@click="${() => (openIndex() === index ? close() : openIndex(index))}"
|
|
100
|
-
@pointerenter="${() => schedule(index, OPEN_DELAY_MS)}"
|
|
101
|
-
@pointerleave="${() => schedule(-1, CLOSE_DELAY_MS)}"
|
|
102
|
-
@keydown="${(event) => {
|
|
103
|
-
if (event.key === "ArrowDown" ||
|
|
104
|
-
event.key === "Enter" ||
|
|
105
|
-
event.key === " ") {
|
|
106
|
-
event.preventDefault();
|
|
107
|
-
openIndex(index);
|
|
108
|
-
}
|
|
109
|
-
}}"
|
|
110
|
-
>
|
|
111
|
-
${item.label}
|
|
112
|
-
${ChevronDownIcon({
|
|
113
|
-
class: "relative top-px size-3 transition-transform duration-200 group-data-[state=open]:rotate-180",
|
|
114
|
-
})}
|
|
115
|
-
</button>
|
|
116
|
-
</li>`;
|
|
117
137
|
}
|
|
138
|
+
return html `<button
|
|
139
|
+
type="button"
|
|
140
|
+
data-slot="navigation-menu-trigger"
|
|
141
|
+
id="${item.triggerId}"
|
|
142
|
+
aria-expanded="${() => (open() ? "true" : "false")}"
|
|
143
|
+
aria-controls="${() => (open() ? menu.contentId : undefined)}"
|
|
144
|
+
data-state="${() => (open() ? "open" : "closed")}"
|
|
145
|
+
class="${() => cn(triggerClasses, read(props.class))}"
|
|
146
|
+
@click="${() => open() ? menu.close() : menu.scheduleOpen(item.index, true)}"
|
|
147
|
+
@pointerenter="${() => menu.scheduleOpen(item.index, false)}"
|
|
148
|
+
@pointerleave="${() => menu.scheduleClose()}"
|
|
149
|
+
@keydown="${onKeyDown}"
|
|
150
|
+
>${slot(props.children)}${ChevronDownIcon({
|
|
151
|
+
class: "relative top-px size-3 transition-transform duration-200 group-data-[state=open]:rotate-180",
|
|
152
|
+
})}</button>`;
|
|
153
|
+
});
|
|
154
|
+
export const NavigationMenuContent = component((props) => {
|
|
155
|
+
const menu = inject(NavigationMenuContext);
|
|
156
|
+
const item = inject(NavigationMenuItemContext);
|
|
157
|
+
menu.describe(item.index, {
|
|
158
|
+
body: props.children?.(),
|
|
159
|
+
panelClass: props.class,
|
|
160
|
+
});
|
|
161
|
+
return html ``;
|
|
162
|
+
});
|
|
163
|
+
export const NavigationMenuLink = component((props) => {
|
|
164
|
+
const menu = inject(NavigationMenuContext);
|
|
165
|
+
return html `<a
|
|
166
|
+
data-slot="navigation-menu-link"
|
|
167
|
+
href="${props.href}"
|
|
168
|
+
data-active="${() => (read(props.active) === true ? "true" : undefined)}"
|
|
169
|
+
aria-current="${() => (read(props.active) === true ? "page" : undefined)}"
|
|
170
|
+
class="${() => cn("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", read(props.class))}"
|
|
171
|
+
@pointerenter="${() => {
|
|
172
|
+
// Hovering a link in the BAR while a panel is open closes it: the
|
|
173
|
+
// pointer has left that branch. A link inside the panel is harmless
|
|
174
|
+
// — the panel's own `pointerenter` has already cancelled the close.
|
|
175
|
+
if (menu.openIndex() !== -1)
|
|
176
|
+
menu.scheduleClose();
|
|
177
|
+
}}"
|
|
178
|
+
>${slot(props.children)}</a>`;
|
|
179
|
+
});
|
|
180
|
+
/**
|
|
181
|
+
* Where the panel is drawn.
|
|
182
|
+
*
|
|
183
|
+
* NAMED DEVIATION — inert here. Radix renders every panel into one viewport
|
|
184
|
+
* element positioned under the bar, which is what its width and height
|
|
185
|
+
* animations interpolate against. The panel is portalled and positioned by
|
|
186
|
+
* `floatingSurface` instead, so this exists for a layout copied from upstream
|
|
187
|
+
* to keep its shape rather than to hold anything.
|
|
188
|
+
*/
|
|
189
|
+
export const NavigationMenuViewport = component((props) => html `<div
|
|
190
|
+
data-slot="navigation-menu-viewport"
|
|
191
|
+
class="${() => cn("absolute top-full left-0 isolate z-50 flex justify-center", read(props.class))}"
|
|
192
|
+
></div>`);
|
|
193
|
+
/** The arrow that points at the open trigger. */
|
|
194
|
+
export const NavigationMenuIndicator = component((props) => {
|
|
195
|
+
const menu = inject(NavigationMenuContext);
|
|
196
|
+
return html `<div
|
|
197
|
+
data-slot="navigation-menu-indicator"
|
|
198
|
+
data-state="${() => (menu.openIndex() === -1 ? "hidden" : "visible")}"
|
|
199
|
+
class="${() => cn("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", read(props.class))}"
|
|
200
|
+
><div class="bg-border relative top-[60%] h-2 w-2 rotate-45 rounded-tl-sm shadow-md"></div></div>`;
|
|
118
201
|
});
|
|
119
|
-
function renderPanel(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
${(
|
|
126
|
-
|
|
127
|
-
href="${link.href}"
|
|
128
|
-
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"
|
|
129
|
-
>
|
|
130
|
-
<div class="text-sm leading-none font-medium">${link.label}</div>
|
|
131
|
-
${link.description === undefined
|
|
132
|
-
? null
|
|
133
|
-
: html `<p class="text-muted-foreground line-clamp-2 text-sm leading-snug">
|
|
134
|
-
${link.description}
|
|
135
|
-
</p>`}
|
|
136
|
-
</a>
|
|
137
|
-
</li>`)}
|
|
138
|
-
</ul>`;
|
|
202
|
+
function renderPanel(entry, contentId, handlers) {
|
|
203
|
+
return html `<div
|
|
204
|
+
data-slot="navigation-menu-content"
|
|
205
|
+
id="${contentId}"
|
|
206
|
+
class="${cn("bg-popover text-popover-foreground z-50 origin-(--nebula-transform-origin) rounded-md border p-4 shadow-md outline-hidden", zoomInOut, slideInFromSide, read(entry?.panelClass))}"
|
|
207
|
+
@pointerenter="${() => handlers.enter()}"
|
|
208
|
+
@pointerleave="${() => handlers.leave()}"
|
|
209
|
+
>${entry?.body}</div>`;
|
|
139
210
|
}
|
|
@@ -5,29 +5,89 @@
|
|
|
5
5
|
* anchored overlays in this directory are this component with a different
|
|
6
6
|
* opening gesture and different contents.
|
|
7
7
|
*
|
|
8
|
+
* Popover({ children: () => html`
|
|
9
|
+
* ${PopoverTrigger({ children: "Open" })}
|
|
10
|
+
* ${PopoverContent({ children: () => html`
|
|
11
|
+
* ${PopoverHeader({ children: () => html`
|
|
12
|
+
* ${PopoverTitle({ children: "Dimensions" })}
|
|
13
|
+
* ${PopoverDescription({ children: "Set the box size." })}
|
|
14
|
+
* ` })}
|
|
15
|
+
* ` })}
|
|
16
|
+
* ` })
|
|
17
|
+
*
|
|
18
|
+
* The `() =>` on a part that provides context is load-bearing — see `Parts`.
|
|
19
|
+
* The purely presentational parts below take ordinary children.
|
|
20
|
+
*
|
|
8
21
|
* `modal` decides whether focus is trapped. A popover holding a form should
|
|
9
22
|
* trap — tabbing out of a half-filled form into the page behind loses the
|
|
10
23
|
* user's place. A popover holding a paragraph of help should not, because
|
|
11
24
|
* trapping focus in something the user can only read is a dead end.
|
|
12
25
|
*/
|
|
13
|
-
import { type
|
|
26
|
+
import { type TemplateResult } from "@c9up/aurora";
|
|
27
|
+
import type { Parts, Slot } from "../lib/children.js";
|
|
14
28
|
import { type Reactive } from "../lib/props.js";
|
|
15
|
-
import type {
|
|
16
|
-
export declare const popoverContentClasses = "bg-popover text-popover-foreground z-50 w-72 rounded-md border p-4 shadow-md outline-
|
|
29
|
+
import type { Align, Side } from "../primitives/floating.js";
|
|
30
|
+
export declare const popoverContentClasses = "bg-popover text-popover-foreground z-50 w-72 origin-(--nebula-transform-origin) rounded-md border p-4 shadow-md outline-hidden";
|
|
17
31
|
export interface PopoverProps {
|
|
18
|
-
/** Rendered inside the trigger button. */
|
|
19
|
-
trigger?: Slot;
|
|
20
|
-
/** The panel's contents. */
|
|
21
|
-
children?: Slot;
|
|
22
32
|
open?: Reactive<boolean>;
|
|
23
33
|
defaultOpen?: boolean;
|
|
24
34
|
onOpenChange?: (open: boolean) => void;
|
|
25
|
-
|
|
26
|
-
|
|
35
|
+
children?: Parts;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The state its trigger and its content both read.
|
|
39
|
+
*
|
|
40
|
+
* Renders no element of its own, as upstream does not: a wrapper would put a
|
|
41
|
+
* box into a layout that did not ask for one, and `data-slot="popover"` is
|
|
42
|
+
* inert upstream for the same reason.
|
|
43
|
+
*/
|
|
44
|
+
export declare const Popover: (props?: PopoverProps | undefined) => TemplateResult;
|
|
45
|
+
export interface PopoverTriggerProps {
|
|
46
|
+
children?: Slot;
|
|
47
|
+
class?: Reactive<string>;
|
|
48
|
+
}
|
|
49
|
+
export declare const PopoverTrigger: (props?: PopoverTriggerProps | undefined) => TemplateResult;
|
|
50
|
+
export interface PopoverAnchorProps {
|
|
51
|
+
children?: Slot;
|
|
52
|
+
class?: Reactive<string>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Position the panel against something other than the trigger.
|
|
56
|
+
*
|
|
57
|
+
* A cell menu whose button sits in the corner but whose panel should line up
|
|
58
|
+
* with the whole cell, or a mention popover anchored to a caret marker rather
|
|
59
|
+
* than to any control.
|
|
60
|
+
*/
|
|
61
|
+
export declare const PopoverAnchor: (props?: PopoverAnchorProps | undefined) => TemplateResult;
|
|
62
|
+
export interface PopoverContentProps {
|
|
63
|
+
children?: Slot;
|
|
64
|
+
/** Which edge of the anchor to sit on. Flips when there is no room. */
|
|
65
|
+
side?: Side;
|
|
66
|
+
align?: Align;
|
|
67
|
+
sideOffset?: number;
|
|
27
68
|
/** Trap focus inside. Use for panels holding form controls. */
|
|
28
69
|
modal?: boolean;
|
|
29
70
|
class?: Reactive<string>;
|
|
30
|
-
triggerClass?: Reactive<string>;
|
|
31
|
-
contentClass?: Reactive<string>;
|
|
32
71
|
}
|
|
33
|
-
|
|
72
|
+
/**
|
|
73
|
+
* The panel.
|
|
74
|
+
*
|
|
75
|
+
* Renders nothing where it is written: the popover portals its content out of
|
|
76
|
+
* the tree when it opens, so this registers what to build and returns an empty
|
|
77
|
+
* template.
|
|
78
|
+
*/
|
|
79
|
+
export declare const PopoverContent: (props?: PopoverContentProps | undefined) => TemplateResult;
|
|
80
|
+
export interface PopoverSectionProps {
|
|
81
|
+
children?: Slot;
|
|
82
|
+
class?: Reactive<string>;
|
|
83
|
+
}
|
|
84
|
+
export declare const PopoverHeader: (props?: PopoverSectionProps | undefined) => TemplateResult;
|
|
85
|
+
/**
|
|
86
|
+
* NAMED DEVIATION — a `<div>`, matching what upstream RENDERS rather than what
|
|
87
|
+
* it types. shadcn declares `PopoverTitle` as `ComponentProps<"h2">` and then
|
|
88
|
+
* returns a `<div>`; a heading here would land inside a `role="dialog"` and
|
|
89
|
+
* change how a screen reader announces the panel, which is not a difference to
|
|
90
|
+
* introduce silently. The panel is already named by its trigger.
|
|
91
|
+
*/
|
|
92
|
+
export declare const PopoverTitle: (props?: PopoverSectionProps | undefined) => TemplateResult;
|
|
93
|
+
export declare const PopoverDescription: (props?: PopoverSectionProps | undefined) => TemplateResult;
|
|
@@ -5,54 +5,161 @@
|
|
|
5
5
|
* anchored overlays in this directory are this component with a different
|
|
6
6
|
* opening gesture and different contents.
|
|
7
7
|
*
|
|
8
|
+
* Popover({ children: () => html`
|
|
9
|
+
* ${PopoverTrigger({ children: "Open" })}
|
|
10
|
+
* ${PopoverContent({ children: () => html`
|
|
11
|
+
* ${PopoverHeader({ children: () => html`
|
|
12
|
+
* ${PopoverTitle({ children: "Dimensions" })}
|
|
13
|
+
* ${PopoverDescription({ children: "Set the box size." })}
|
|
14
|
+
* ` })}
|
|
15
|
+
* ` })}
|
|
16
|
+
* ` })
|
|
17
|
+
*
|
|
18
|
+
* The `() =>` on a part that provides context is load-bearing — see `Parts`.
|
|
19
|
+
* The purely presentational parts below take ordinary children.
|
|
20
|
+
*
|
|
8
21
|
* `modal` decides whether focus is trapped. A popover holding a form should
|
|
9
22
|
* trap — tabbing out of a half-filled form into the page behind loses the
|
|
10
23
|
* user's place. A popover holding a paragraph of help should not, because
|
|
11
24
|
* trapping focus in something the user can only read is a dead end.
|
|
12
25
|
*/
|
|
13
|
-
import { component, html } from "@c9up/aurora";
|
|
26
|
+
import { component, createContext, html, inject, provide, } from "@c9up/aurora";
|
|
14
27
|
import { slot } from "../lib/children.js";
|
|
15
28
|
import { cn } from "../lib/cn.js";
|
|
16
29
|
import { uid } from "../lib/id.js";
|
|
17
|
-
import { zoomInOut } from "../lib/motion.js";
|
|
30
|
+
import { slideInFromSide, zoomInOut } from "../lib/motion.js";
|
|
18
31
|
import { read } from "../lib/props.js";
|
|
19
32
|
import { controllable } from "../primitives/controllable.js";
|
|
20
33
|
import { floatingSurface } from "../primitives/floatingSurface.js";
|
|
21
|
-
export const popoverContentClasses = "bg-popover text-popover-foreground z-50 w-72 rounded-md border p-4 shadow-md outline-
|
|
34
|
+
export const popoverContentClasses = "bg-popover text-popover-foreground z-50 w-72 origin-(--nebula-transform-origin) rounded-md border p-4 shadow-md outline-hidden";
|
|
35
|
+
const PopoverContext = createContext("Popover");
|
|
36
|
+
/**
|
|
37
|
+
* The state its trigger and its content both read.
|
|
38
|
+
*
|
|
39
|
+
* Renders no element of its own, as upstream does not: a wrapper would put a
|
|
40
|
+
* box into a layout that did not ask for one, and `data-slot="popover"` is
|
|
41
|
+
* inert upstream for the same reason.
|
|
42
|
+
*/
|
|
22
43
|
export const Popover = component((props) => {
|
|
23
44
|
const triggerId = uid("popover-trigger");
|
|
24
45
|
const contentId = uid("popover-content");
|
|
46
|
+
let anchorId = triggerId;
|
|
47
|
+
let content;
|
|
25
48
|
const state = controllable({
|
|
26
49
|
value: props.open,
|
|
27
50
|
initial: props.defaultOpen ?? false,
|
|
28
51
|
onChange: props.onOpenChange,
|
|
29
52
|
});
|
|
30
|
-
|
|
31
|
-
|
|
53
|
+
provide(PopoverContext, {
|
|
54
|
+
triggerId,
|
|
55
|
+
contentId,
|
|
32
56
|
open: () => state.current(),
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
role="dialog"
|
|
42
|
-
aria-labelledby="${triggerId}"
|
|
43
|
-
tabindex="-1"
|
|
44
|
-
class="${cn(popoverContentClasses, zoomInOut, read(props.contentClass))}"
|
|
45
|
-
>${slot(props.children)}</div>`,
|
|
57
|
+
toggle: () => state.set(!state.current()),
|
|
58
|
+
setOpen: (next) => state.set(next),
|
|
59
|
+
useAnchor(id) {
|
|
60
|
+
anchorId = id;
|
|
61
|
+
},
|
|
62
|
+
register(registered) {
|
|
63
|
+
content = registered;
|
|
64
|
+
},
|
|
46
65
|
});
|
|
66
|
+
// Built HERE so the parts see the context, and so the content has
|
|
67
|
+
// registered by the time the surface below needs it.
|
|
68
|
+
const parts = props.children?.();
|
|
69
|
+
if (content !== undefined) {
|
|
70
|
+
const registered = content;
|
|
71
|
+
const placement = registered.align === "center"
|
|
72
|
+
? registered.side
|
|
73
|
+
: `${registered.side}-${registered.align}`;
|
|
74
|
+
floatingSurface({
|
|
75
|
+
anchor: () => document.getElementById(anchorId),
|
|
76
|
+
open: () => state.current(),
|
|
77
|
+
onClose: () => state.set(false),
|
|
78
|
+
placement,
|
|
79
|
+
offset: registered.sideOffset,
|
|
80
|
+
trapFocus: registered.modal,
|
|
81
|
+
autoFocus: !registered.modal,
|
|
82
|
+
content: () => renderContent(registered, contentId, triggerId),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return html `${parts}`;
|
|
86
|
+
});
|
|
87
|
+
export const PopoverTrigger = component((props) => {
|
|
88
|
+
const popover = inject(PopoverContext);
|
|
47
89
|
return html `<button
|
|
48
90
|
type="button"
|
|
49
91
|
data-slot="popover-trigger"
|
|
50
|
-
id="${triggerId}"
|
|
92
|
+
id="${popover.triggerId}"
|
|
51
93
|
aria-haspopup="dialog"
|
|
52
|
-
aria-expanded="${() => (
|
|
53
|
-
aria-controls="${() => (
|
|
54
|
-
data-state="${() => (
|
|
55
|
-
class="${() => cn(read(props.
|
|
56
|
-
@click="${() =>
|
|
57
|
-
>${slot(props.
|
|
94
|
+
aria-expanded="${() => (popover.open() ? "true" : "false")}"
|
|
95
|
+
aria-controls="${() => (popover.open() ? popover.contentId : undefined)}"
|
|
96
|
+
data-state="${() => (popover.open() ? "open" : "closed")}"
|
|
97
|
+
class="${() => cn(read(props.class))}"
|
|
98
|
+
@click="${() => popover.toggle()}"
|
|
99
|
+
>${slot(props.children)}</button>`;
|
|
58
100
|
});
|
|
101
|
+
/**
|
|
102
|
+
* Position the panel against something other than the trigger.
|
|
103
|
+
*
|
|
104
|
+
* A cell menu whose button sits in the corner but whose panel should line up
|
|
105
|
+
* with the whole cell, or a mention popover anchored to a caret marker rather
|
|
106
|
+
* than to any control.
|
|
107
|
+
*/
|
|
108
|
+
export const PopoverAnchor = component((props) => {
|
|
109
|
+
const popover = inject(PopoverContext);
|
|
110
|
+
const anchorId = uid("popover-anchor");
|
|
111
|
+
popover.useAnchor(anchorId);
|
|
112
|
+
return html `<span
|
|
113
|
+
data-slot="popover-anchor"
|
|
114
|
+
id="${anchorId}"
|
|
115
|
+
class="${() => cn(read(props.class))}"
|
|
116
|
+
>${slot(props.children)}</span>`;
|
|
117
|
+
});
|
|
118
|
+
/**
|
|
119
|
+
* The panel.
|
|
120
|
+
*
|
|
121
|
+
* Renders nothing where it is written: the popover portals its content out of
|
|
122
|
+
* the tree when it opens, so this registers what to build and returns an empty
|
|
123
|
+
* template.
|
|
124
|
+
*/
|
|
125
|
+
export const PopoverContent = component((props) => {
|
|
126
|
+
const popover = inject(PopoverContext);
|
|
127
|
+
popover.register({
|
|
128
|
+
render: () => slot(props.children)(),
|
|
129
|
+
side: props.side ?? "bottom",
|
|
130
|
+
align: props.align ?? "center",
|
|
131
|
+
sideOffset: props.sideOffset ?? 4,
|
|
132
|
+
modal: props.modal === true,
|
|
133
|
+
class: props.class,
|
|
134
|
+
});
|
|
135
|
+
return html ``;
|
|
136
|
+
});
|
|
137
|
+
export const PopoverHeader = component((props) => html `<div
|
|
138
|
+
data-slot="popover-header"
|
|
139
|
+
class="${() => cn("flex flex-col gap-1 text-sm", read(props.class))}"
|
|
140
|
+
>${slot(props.children)}</div>`);
|
|
141
|
+
/**
|
|
142
|
+
* NAMED DEVIATION — a `<div>`, matching what upstream RENDERS rather than what
|
|
143
|
+
* it types. shadcn declares `PopoverTitle` as `ComponentProps<"h2">` and then
|
|
144
|
+
* returns a `<div>`; a heading here would land inside a `role="dialog"` and
|
|
145
|
+
* change how a screen reader announces the panel, which is not a difference to
|
|
146
|
+
* introduce silently. The panel is already named by its trigger.
|
|
147
|
+
*/
|
|
148
|
+
export const PopoverTitle = component((props) => html `<div
|
|
149
|
+
data-slot="popover-title"
|
|
150
|
+
class="${() => cn("font-medium", read(props.class))}"
|
|
151
|
+
>${slot(props.children)}</div>`);
|
|
152
|
+
export const PopoverDescription = component((props) => html `<p
|
|
153
|
+
data-slot="popover-description"
|
|
154
|
+
class="${() => cn("text-muted-foreground", read(props.class))}"
|
|
155
|
+
>${slot(props.children)}</p>`);
|
|
156
|
+
function renderContent(registered, contentId, triggerId) {
|
|
157
|
+
return html `<div
|
|
158
|
+
data-slot="popover-content"
|
|
159
|
+
id="${contentId}"
|
|
160
|
+
role="dialog"
|
|
161
|
+
aria-labelledby="${triggerId}"
|
|
162
|
+
tabindex="-1"
|
|
163
|
+
class="${cn(popoverContentClasses, zoomInOut, slideInFromSide, read(registered.class))}"
|
|
164
|
+
>${registered.render()}</div>`;
|
|
165
|
+
}
|
|
@@ -31,7 +31,7 @@ import { Textarea } from "../atoms/Textarea.js";
|
|
|
31
31
|
import { cn } from "../lib/cn.js";
|
|
32
32
|
import { uid } from "../lib/id.js";
|
|
33
33
|
import { read } from "../lib/props.js";
|
|
34
|
-
import { RadioGroup } from "../molecules/RadioGroup.js";
|
|
34
|
+
import { RadioGroup, RadioGroupItem } from "../molecules/RadioGroup.js";
|
|
35
35
|
function isSingle(question) {
|
|
36
36
|
return question.type === "single";
|
|
37
37
|
}
|
|
@@ -187,13 +187,13 @@ export const Questionnaire = component((props) => {
|
|
|
187
187
|
if (isSingle(question)) {
|
|
188
188
|
return RadioGroup({
|
|
189
189
|
name: question.id,
|
|
190
|
-
|
|
190
|
+
value: () => asValue(answerOf(question)),
|
|
191
|
+
onValueChange: (value) => record(question, value),
|
|
192
|
+
children: () => question.options.map((option) => RadioGroupItem({
|
|
191
193
|
value: option.value,
|
|
192
|
-
|
|
194
|
+
children: option.label,
|
|
193
195
|
description: option.description,
|
|
194
196
|
})),
|
|
195
|
-
value: () => asValue(answerOf(question)),
|
|
196
|
-
onValueChange: (value) => record(question, value),
|
|
197
197
|
});
|
|
198
198
|
}
|
|
199
199
|
if (isMultiple(question)) {
|