@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,22 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* AlertDialog — a modal that interrupts to ask
|
|
2
|
+
* AlertDialog — a modal that interrupts to ask a question.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* AlertDialog({ children: () => html`
|
|
5
|
+
* ${AlertDialogTrigger({ children: "Delete" })}
|
|
6
|
+
* ${AlertDialogContent({ children: () => html`
|
|
7
|
+
* ${AlertDialogHeader({ children: html`
|
|
8
|
+
* ${AlertDialogTitle({ children: "Delete this?" })}
|
|
9
|
+
* ${AlertDialogDescription({ children: "It cannot be undone." })}
|
|
10
|
+
* ` })}
|
|
11
|
+
* ${AlertDialogFooter({ children: html`
|
|
12
|
+
* ${AlertDialogCancel({ children: "Cancel" })}
|
|
13
|
+
* ${AlertDialogAction({ children: "Delete", variant: "destructive" })}
|
|
14
|
+
* ` })}
|
|
15
|
+
* ` })}
|
|
16
|
+
* ` })
|
|
7
17
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* -
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
+
* Everything that distinguishes it from a Dialog is about refusing to let the
|
|
19
|
+
* question be dismissed by accident:
|
|
20
|
+
*
|
|
21
|
+
* - `role="alertdialog"`, which tells a screen reader this interrupts.
|
|
22
|
+
* - No outside-click dismissal. A decision has to be made, and clicking past
|
|
23
|
+
* it is not one.
|
|
24
|
+
* - Focus lands on the CANCEL button, not the confirming action. The safe
|
|
25
|
+
* choice is the one a hurried Enter should hit.
|
|
26
|
+
*
|
|
27
|
+
* Escape still closes, and it cancels rather than confirms — it is the
|
|
28
|
+
* keyboard spelling of the same safe way out.
|
|
18
29
|
*/
|
|
19
|
-
import { component, html } from "@c9up/aurora";
|
|
30
|
+
import { component, createContext, html, inject, onUnmount, provide, } from "@c9up/aurora";
|
|
20
31
|
import { buttonVariants } from "../atoms/Button.js";
|
|
21
32
|
import { slot } from "../lib/children.js";
|
|
22
33
|
import { cn } from "../lib/cn.js";
|
|
@@ -25,13 +36,19 @@ import { fadeInOut, zoomInOut } from "../lib/motion.js";
|
|
|
25
36
|
import { read } from "../lib/props.js";
|
|
26
37
|
import { controllable } from "../primitives/controllable.js";
|
|
27
38
|
import { modalSurface } from "../primitives/modalSurface.js";
|
|
28
|
-
import {
|
|
39
|
+
import { portal } from "../primitives/portal.js";
|
|
40
|
+
import { dialogBackdropClasses } from "./Dialog.js";
|
|
41
|
+
const panelClasses = "group/alert-dialog-content bg-background fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none data-[size=sm]:max-w-xs sm:max-w-lg";
|
|
42
|
+
const AlertDialogContext = createContext("AlertDialog");
|
|
29
43
|
export const AlertDialog = component((props) => {
|
|
30
44
|
const triggerId = uid("alert-dialog-trigger");
|
|
31
45
|
const panelId = uid("alert-dialog-panel");
|
|
32
46
|
const titleId = uid("alert-dialog-title");
|
|
33
47
|
const descriptionId = uid("alert-dialog-description");
|
|
34
48
|
const cancelId = uid("alert-dialog-cancel");
|
|
49
|
+
let hasTitle = false;
|
|
50
|
+
let hasDescription = false;
|
|
51
|
+
let content;
|
|
35
52
|
const state = controllable({
|
|
36
53
|
value: props.open,
|
|
37
54
|
initial: props.defaultOpen ?? false,
|
|
@@ -45,60 +62,168 @@ export const AlertDialog = component((props) => {
|
|
|
45
62
|
props.onConfirm?.();
|
|
46
63
|
state.set(false);
|
|
47
64
|
}
|
|
48
|
-
|
|
65
|
+
provide(AlertDialogContext, {
|
|
66
|
+
triggerId,
|
|
67
|
+
panelId,
|
|
68
|
+
titleId,
|
|
69
|
+
descriptionId,
|
|
70
|
+
cancelId,
|
|
49
71
|
open: () => state.current(),
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
aria-labelledby="${titleId}"
|
|
63
|
-
aria-describedby="${descriptionId}"
|
|
64
|
-
tabindex="-1"
|
|
65
|
-
class="${cn(dialogPanelClasses, zoomInOut, read(props.contentClass))}"
|
|
66
|
-
>
|
|
67
|
-
<div class="flex flex-col gap-2 text-center sm:text-left">
|
|
68
|
-
<h2 id="${titleId}" class="text-lg font-semibold">${props.title}</h2>
|
|
69
|
-
<p id="${descriptionId}" class="text-muted-foreground text-sm">
|
|
70
|
-
${props.description}
|
|
71
|
-
</p>
|
|
72
|
-
</div>
|
|
73
|
-
<div class="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">
|
|
74
|
-
<button
|
|
75
|
-
type="button"
|
|
76
|
-
id="${cancelId}"
|
|
77
|
-
data-slot="alert-dialog-cancel"
|
|
78
|
-
class="${buttonVariants({ variant: "outline" })}"
|
|
79
|
-
@click="${cancel}"
|
|
80
|
-
>${props.cancelLabel ?? "Cancel"}</button>
|
|
81
|
-
<button
|
|
82
|
-
type="button"
|
|
83
|
-
data-slot="alert-dialog-action"
|
|
84
|
-
class="${buttonVariants({
|
|
85
|
-
variant: props.destructive === true ? "destructive" : "default",
|
|
86
|
-
})}"
|
|
87
|
-
@click="${confirm}"
|
|
88
|
-
>${props.actionLabel ?? "Continue"}</button>
|
|
89
|
-
</div>
|
|
90
|
-
</div>
|
|
91
|
-
</div>`,
|
|
72
|
+
setOpen: (next) => state.set(next),
|
|
73
|
+
confirm,
|
|
74
|
+
cancel,
|
|
75
|
+
declareTitle() {
|
|
76
|
+
hasTitle = true;
|
|
77
|
+
},
|
|
78
|
+
declareDescription() {
|
|
79
|
+
hasDescription = true;
|
|
80
|
+
},
|
|
81
|
+
register(registered) {
|
|
82
|
+
content = registered;
|
|
83
|
+
},
|
|
92
84
|
});
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
const parts = props.children?.();
|
|
86
|
+
if (content !== undefined) {
|
|
87
|
+
const registered = content;
|
|
88
|
+
if (!hasTitle) {
|
|
89
|
+
console.warn("nebula: an AlertDialog has no AlertDialogTitle. It will be announced only as “alertdialog”.");
|
|
90
|
+
}
|
|
91
|
+
modalSurface({
|
|
92
|
+
open: () => state.current(),
|
|
93
|
+
// Escape cancels rather than confirms: the keyboard spelling of the
|
|
94
|
+
// safe way out.
|
|
95
|
+
onClose: cancel,
|
|
96
|
+
panel: (root) => root.querySelector(`#${CSS.escape(panelId)}`),
|
|
97
|
+
initialFocus: (panel) => panel.querySelector(`#${CSS.escape(cancelId)}`),
|
|
98
|
+
returnFocus: () => document.getElementById(triggerId),
|
|
99
|
+
dismissOnOutside: false,
|
|
100
|
+
content: () => renderSurface(registered, {
|
|
101
|
+
panelId,
|
|
102
|
+
titleId: hasTitle ? titleId : undefined,
|
|
103
|
+
descriptionId: hasDescription ? descriptionId : undefined,
|
|
104
|
+
}),
|
|
105
|
+
});
|
|
95
106
|
}
|
|
107
|
+
return html `${parts}`;
|
|
108
|
+
});
|
|
109
|
+
export const AlertDialogTrigger = component((props) => {
|
|
110
|
+
const dialog = inject(AlertDialogContext);
|
|
111
|
+
return html `<button
|
|
112
|
+
type="button"
|
|
113
|
+
data-slot="alert-dialog-trigger"
|
|
114
|
+
id="${dialog.triggerId}"
|
|
115
|
+
aria-haspopup="dialog"
|
|
116
|
+
aria-expanded="${() => (dialog.open() ? "true" : "false")}"
|
|
117
|
+
data-state="${() => (dialog.open() ? "open" : "closed")}"
|
|
118
|
+
class="${() => cn(read(props.class))}"
|
|
119
|
+
@click="${() => dialog.setOpen(true)}"
|
|
120
|
+
>${slot(props.children)}</button>`;
|
|
121
|
+
});
|
|
122
|
+
export const AlertDialogContent = component((props) => {
|
|
123
|
+
const dialog = inject(AlertDialogContext);
|
|
124
|
+
dialog.register({
|
|
125
|
+
body: props.children?.(),
|
|
126
|
+
size: props.size ?? "default",
|
|
127
|
+
class: props.class,
|
|
128
|
+
});
|
|
129
|
+
return html ``;
|
|
130
|
+
});
|
|
131
|
+
export const AlertDialogOverlay = component((props) => html `<div
|
|
132
|
+
data-slot="alert-dialog-overlay"
|
|
133
|
+
class="${() => cn(dialogBackdropClasses, read(props.class))}"
|
|
134
|
+
></div>`);
|
|
135
|
+
/**
|
|
136
|
+
* Mount children outside the component's own DOM position.
|
|
137
|
+
*
|
|
138
|
+
* `AlertDialogContent` does not need it — the dialog portals its whole overlay
|
|
139
|
+
* through `modalSurface`, which also owns the trap and the scroll lock. It is
|
|
140
|
+
* exported because upstream exports it, doing here what its name says rather
|
|
141
|
+
* than standing in as a passthrough.
|
|
142
|
+
*/
|
|
143
|
+
export const AlertDialogPortal = component((props) => {
|
|
144
|
+
const mounted = portal(html `${slot(props.children)}`, {
|
|
145
|
+
container: props.container,
|
|
146
|
+
});
|
|
147
|
+
mounted.host.setAttribute("data-slot", "alert-dialog-portal");
|
|
148
|
+
onUnmount(() => mounted.close());
|
|
149
|
+
return html ``;
|
|
150
|
+
});
|
|
151
|
+
export const AlertDialogHeader = component((props) => html `<div
|
|
152
|
+
data-slot="alert-dialog-header"
|
|
153
|
+
class="${() => cn("grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-6 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left", read(props.class))}"
|
|
154
|
+
>${slot(props.children)}</div>`);
|
|
155
|
+
export const AlertDialogFooter = component((props) => html `<div
|
|
156
|
+
data-slot="alert-dialog-footer"
|
|
157
|
+
class="${() => cn("flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end", read(props.class))}"
|
|
158
|
+
>${slot(props.children)}</div>`);
|
|
159
|
+
/** An icon block above the title — a warning glyph, a product mark. */
|
|
160
|
+
export const AlertDialogMedia = component((props) => html `<div
|
|
161
|
+
data-slot="alert-dialog-media"
|
|
162
|
+
class="${() => cn("bg-muted mb-2 inline-flex size-16 items-center justify-center rounded-md sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-8", read(props.class))}"
|
|
163
|
+
>${slot(props.children)}</div>`);
|
|
164
|
+
export const AlertDialogTitle = component((props) => {
|
|
165
|
+
const dialog = inject(AlertDialogContext);
|
|
166
|
+
dialog.declareTitle();
|
|
167
|
+
return html `<h2
|
|
168
|
+
id="${dialog.titleId}"
|
|
169
|
+
data-slot="alert-dialog-title"
|
|
170
|
+
class="${() => cn("text-lg font-semibold sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2", read(props.class))}"
|
|
171
|
+
>${slot(props.children)}</h2>`;
|
|
172
|
+
});
|
|
173
|
+
export const AlertDialogDescription = component((props) => {
|
|
174
|
+
const dialog = inject(AlertDialogContext);
|
|
175
|
+
dialog.declareDescription();
|
|
176
|
+
return html `<p
|
|
177
|
+
id="${dialog.descriptionId}"
|
|
178
|
+
data-slot="alert-dialog-description"
|
|
179
|
+
class="${() => cn("text-muted-foreground text-sm", read(props.class))}"
|
|
180
|
+
>${slot(props.children)}</p>`;
|
|
181
|
+
});
|
|
182
|
+
/** The confirming action. */
|
|
183
|
+
export const AlertDialogAction = component((props) => {
|
|
184
|
+
const dialog = inject(AlertDialogContext);
|
|
185
|
+
return html `<button
|
|
186
|
+
type="button"
|
|
187
|
+
data-slot="alert-dialog-action"
|
|
188
|
+
class="${() => cn(buttonVariants({
|
|
189
|
+
variant: props.variant ?? "default",
|
|
190
|
+
size: props.size ?? "default",
|
|
191
|
+
}), read(props.class))}"
|
|
192
|
+
@click="${() => dialog.confirm()}"
|
|
193
|
+
>${slot(props.children)}</button>`;
|
|
194
|
+
});
|
|
195
|
+
/**
|
|
196
|
+
* The way out, and where focus lands.
|
|
197
|
+
*
|
|
198
|
+
* The safe choice is the one a hurried Enter should hit, which is why the
|
|
199
|
+
* surface focuses this rather than the action beside it.
|
|
200
|
+
*/
|
|
201
|
+
export const AlertDialogCancel = component((props) => {
|
|
202
|
+
const dialog = inject(AlertDialogContext);
|
|
96
203
|
return html `<button
|
|
97
204
|
type="button"
|
|
98
|
-
data-slot="alert-dialog-
|
|
99
|
-
id="${
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
205
|
+
data-slot="alert-dialog-cancel"
|
|
206
|
+
id="${dialog.cancelId}"
|
|
207
|
+
class="${() => cn(buttonVariants({
|
|
208
|
+
variant: props.variant ?? "outline",
|
|
209
|
+
size: props.size ?? "default",
|
|
210
|
+
}), read(props.class))}"
|
|
211
|
+
@click="${() => dialog.cancel()}"
|
|
212
|
+
>${slot(props.children)}</button>`;
|
|
104
213
|
});
|
|
214
|
+
function renderSurface(registered, ids) {
|
|
215
|
+
return html `<div data-slot="alert-dialog-portal" class="${cn("fixed inset-0 z-50", fadeInOut)}">
|
|
216
|
+
<div data-slot="alert-dialog-overlay" class="${dialogBackdropClasses}"></div>
|
|
217
|
+
<div
|
|
218
|
+
data-slot="alert-dialog-content"
|
|
219
|
+
data-size="${registered.size}"
|
|
220
|
+
id="${ids.panelId}"
|
|
221
|
+
role="alertdialog"
|
|
222
|
+
aria-modal="true"
|
|
223
|
+
aria-labelledby="${ids.titleId}"
|
|
224
|
+
aria-describedby="${ids.descriptionId}"
|
|
225
|
+
tabindex="-1"
|
|
226
|
+
class="${cn(panelClasses, zoomInOut, read(registered.class))}"
|
|
227
|
+
>${registered.body}</div>
|
|
228
|
+
</div>`;
|
|
229
|
+
}
|
|
@@ -16,14 +16,36 @@
|
|
|
16
16
|
* tell how much is off-screen — the visual affordance of a strip running off
|
|
17
17
|
* the edge carries none of that.
|
|
18
18
|
*/
|
|
19
|
-
import type {
|
|
19
|
+
import type { Parts, Slot } from "../lib/children.js";
|
|
20
20
|
import { type Reactive } from "../lib/props.js";
|
|
21
21
|
export interface CarouselProps {
|
|
22
|
-
slides: readonly Child[];
|
|
23
22
|
/** Announced before the slides. */
|
|
24
23
|
label?: string;
|
|
25
24
|
orientation?: "horizontal" | "vertical";
|
|
26
25
|
class?: Reactive<string>;
|
|
27
|
-
|
|
26
|
+
children?: Parts;
|
|
28
27
|
}
|
|
29
28
|
export declare const Carousel: (props?: CarouselProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
29
|
+
export interface CarouselContentProps {
|
|
30
|
+
children?: Slot;
|
|
31
|
+
class?: Reactive<string>;
|
|
32
|
+
}
|
|
33
|
+
/** The scroll container. */
|
|
34
|
+
export declare const CarouselContent: (props?: CarouselContentProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
35
|
+
export interface CarouselItemProps {
|
|
36
|
+
children?: Slot;
|
|
37
|
+
class?: Reactive<string>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* One slide.
|
|
41
|
+
*
|
|
42
|
+
* Claims its position as it is built, which is what `"3 of 7"` needs — and the
|
|
43
|
+
* count is only final once every slide has been built, so the label reads it
|
|
44
|
+
* lazily rather than capturing it.
|
|
45
|
+
*/
|
|
46
|
+
export declare const CarouselItem: (props?: CarouselItemProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
47
|
+
export interface CarouselButtonProps {
|
|
48
|
+
class?: Reactive<string>;
|
|
49
|
+
}
|
|
50
|
+
export declare const CarouselPrevious: (props?: CarouselButtonProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
51
|
+
export declare const CarouselNext: (props?: CarouselButtonProps | undefined) => import("@c9up/aurora").TemplateResult;
|
|
@@ -16,27 +16,29 @@
|
|
|
16
16
|
* tell how much is off-screen — the visual affordance of a strip running off
|
|
17
17
|
* the edge carries none of that.
|
|
18
18
|
*/
|
|
19
|
-
import { component, html, onMount, onUnmount, signal } from "@c9up/aurora";
|
|
19
|
+
import { component, createContext, html, inject, onMount, onUnmount, provide, signal, } from "@c9up/aurora";
|
|
20
20
|
import { buttonVariants } from "../atoms/Button.js";
|
|
21
|
+
import { slot } from "../lib/children.js";
|
|
21
22
|
import { cn } from "../lib/cn.js";
|
|
22
23
|
import { ArrowLeftIcon, ArrowRightIcon } from "../lib/icons.js";
|
|
23
24
|
import { uid } from "../lib/id.js";
|
|
24
25
|
import { read } from "../lib/props.js";
|
|
26
|
+
const CarouselContext = createContext("Carousel");
|
|
25
27
|
export const Carousel = component((props) => {
|
|
26
28
|
const trackId = uid("carousel-track");
|
|
27
29
|
const horizontal = props.orientation !== "vertical";
|
|
28
30
|
const atStart = signal(true);
|
|
29
31
|
const atEnd = signal(false);
|
|
32
|
+
let slides = 0;
|
|
30
33
|
function track() {
|
|
31
34
|
return document.getElementById(trackId);
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
34
|
-
*
|
|
37
|
+
* Which arrows are usable, read from the scroll position.
|
|
35
38
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* button enabled on a carousel that cannot scroll any further.
|
|
39
|
+
* Derived rather than tracked: the track is a scroll container, so a drag,
|
|
40
|
+
* a wheel, a trackpad swipe and the buttons all move it, and only the
|
|
41
|
+
* element knows where it ended up.
|
|
40
42
|
*/
|
|
41
43
|
function syncEdges() {
|
|
42
44
|
const element = track();
|
|
@@ -79,7 +81,19 @@ export const Carousel = component((props) => {
|
|
|
79
81
|
track()?.removeEventListener("scroll", syncEdges);
|
|
80
82
|
window.removeEventListener("resize", syncEdges);
|
|
81
83
|
});
|
|
82
|
-
|
|
84
|
+
provide(CarouselContext, {
|
|
85
|
+
trackId,
|
|
86
|
+
horizontal,
|
|
87
|
+
atStart: () => atStart(),
|
|
88
|
+
atEnd: () => atEnd(),
|
|
89
|
+
claimSlide() {
|
|
90
|
+
slides += 1;
|
|
91
|
+
return slides;
|
|
92
|
+
},
|
|
93
|
+
slideCount: () => slides,
|
|
94
|
+
scrollByPage,
|
|
95
|
+
syncEdges,
|
|
96
|
+
});
|
|
83
97
|
return html `<div
|
|
84
98
|
data-slot="carousel"
|
|
85
99
|
role="region"
|
|
@@ -87,42 +101,60 @@ export const Carousel = component((props) => {
|
|
|
87
101
|
aria-label="${props.label ?? "Carousel"}"
|
|
88
102
|
class="${() => cn("relative", read(props.class))}"
|
|
89
103
|
@keydown="${onKeyDown}"
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
>${props.children?.()}</div>`;
|
|
105
|
+
});
|
|
106
|
+
/** The scroll container. */
|
|
107
|
+
export const CarouselContent = component((props) => {
|
|
108
|
+
const carousel = inject(CarouselContext);
|
|
109
|
+
return html `<div
|
|
110
|
+
data-slot="carousel-content"
|
|
111
|
+
id="${carousel.trackId}"
|
|
112
|
+
tabindex="0"
|
|
113
|
+
class="${() => cn("flex snap-mandatory gap-4 overflow-auto scroll-smooth outline-none motion-reduce:scroll-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden", carousel.horizontal ? "snap-x flex-row" : "snap-y max-h-96 flex-col", read(props.class))}"
|
|
114
|
+
>${slot(props.children)}</div>`;
|
|
115
|
+
});
|
|
116
|
+
/**
|
|
117
|
+
* One slide.
|
|
118
|
+
*
|
|
119
|
+
* Claims its position as it is built, which is what `"3 of 7"` needs — and the
|
|
120
|
+
* count is only final once every slide has been built, so the label reads it
|
|
121
|
+
* lazily rather than capturing it.
|
|
122
|
+
*/
|
|
123
|
+
export const CarouselItem = component((props) => {
|
|
124
|
+
const carousel = inject(CarouselContext);
|
|
125
|
+
const position = carousel.claimSlide();
|
|
126
|
+
return html `<div
|
|
127
|
+
data-slot="carousel-item"
|
|
128
|
+
role="group"
|
|
129
|
+
aria-roledescription="slide"
|
|
130
|
+
aria-label="${() => `${position} of ${carousel.slideCount()}`}"
|
|
131
|
+
class="${() => cn("min-w-0 shrink-0 grow-0 basis-full snap-start", read(props.class))}"
|
|
132
|
+
>${slot(props.children)}</div>`;
|
|
133
|
+
});
|
|
134
|
+
const arrowClasses = "absolute size-8 rounded-full";
|
|
135
|
+
export const CarouselPrevious = component((props) => {
|
|
136
|
+
const carousel = inject(CarouselContext);
|
|
137
|
+
return html `<button
|
|
138
|
+
type="button"
|
|
139
|
+
data-slot="carousel-previous"
|
|
140
|
+
aria-label="Previous slide"
|
|
141
|
+
?disabled="${() => carousel.atStart()}"
|
|
142
|
+
class="${() => cn(buttonVariants({ variant: "outline", size: "icon" }), arrowClasses, carousel.horizontal
|
|
113
143
|
? "top-1/2 -left-12 -translate-y-1/2"
|
|
114
|
-
: "-top-12 left-1/2 -translate-x-1/2 rotate-90")}"
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
144
|
+
: "-top-12 left-1/2 -translate-x-1/2 rotate-90", read(props.class))}"
|
|
145
|
+
@click="${() => carousel.scrollByPage(-1)}"
|
|
146
|
+
>${ArrowLeftIcon({ class: "size-4" })}</button>`;
|
|
147
|
+
});
|
|
148
|
+
export const CarouselNext = component((props) => {
|
|
149
|
+
const carousel = inject(CarouselContext);
|
|
150
|
+
return html `<button
|
|
151
|
+
type="button"
|
|
152
|
+
data-slot="carousel-next"
|
|
153
|
+
aria-label="Next slide"
|
|
154
|
+
?disabled="${() => carousel.atEnd()}"
|
|
155
|
+
class="${() => cn(buttonVariants({ variant: "outline", size: "icon" }), arrowClasses, carousel.horizontal
|
|
123
156
|
? "top-1/2 -right-12 -translate-y-1/2"
|
|
124
|
-
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90")}"
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
</div>`;
|
|
157
|
+
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90", read(props.class))}"
|
|
158
|
+
@click="${() => carousel.scrollByPage(1)}"
|
|
159
|
+
>${ArrowRightIcon({ class: "size-4" })}</button>`;
|
|
128
160
|
});
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* control — and returns to the trigger on close, so the tab order does not
|
|
15
15
|
* jump to the top of the page after choosing.
|
|
16
16
|
*/
|
|
17
|
+
import { type TemplateResult } from "@c9up/aurora";
|
|
17
18
|
import { type Reactive } from "../lib/props.js";
|
|
18
19
|
export interface ComboboxOption {
|
|
19
20
|
value: string;
|
|
@@ -38,4 +39,4 @@ export interface ComboboxProps {
|
|
|
38
39
|
contentClass?: Reactive<string>;
|
|
39
40
|
onValueChange?: (value: string) => void;
|
|
40
41
|
}
|
|
41
|
-
export declare const Combobox: (props?: ComboboxProps | undefined) =>
|
|
42
|
+
export declare const Combobox: (props?: ComboboxProps | undefined) => TemplateResult;
|
|
@@ -23,7 +23,7 @@ import { read, readOr } from "../lib/props.js";
|
|
|
23
23
|
import { controllable } from "../primitives/controllable.js";
|
|
24
24
|
import { floatingSurface } from "../primitives/floatingSurface.js";
|
|
25
25
|
import { focusSilently } from "../primitives/focusable.js";
|
|
26
|
-
import { Command } from "./Command.js";
|
|
26
|
+
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "./Command.js";
|
|
27
27
|
import { selectTriggerClasses } from "./Select.js";
|
|
28
28
|
export const Combobox = component((props) => {
|
|
29
29
|
const triggerId = uid("combobox-trigger");
|
|
@@ -40,18 +40,53 @@ export const Combobox = component((props) => {
|
|
|
40
40
|
function labelFor(value) {
|
|
41
41
|
return props.options.find((option) => option.value === value)?.label;
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
label: option.label,
|
|
46
|
-
keywords: option.keywords,
|
|
47
|
-
disabled: option.disabled,
|
|
48
|
-
group: option.group,
|
|
49
|
-
}));
|
|
50
|
-
function choose(item) {
|
|
51
|
-
selection.set(item.value);
|
|
43
|
+
function choose(value) {
|
|
44
|
+
selection.set(value);
|
|
52
45
|
open(false);
|
|
53
46
|
focusSilently(document.getElementById(triggerId));
|
|
54
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* The palette inside the popover.
|
|
50
|
+
*
|
|
51
|
+
* Built fresh on each open, so the options prop is read at the moment the
|
|
52
|
+
* surface appears rather than captured once — a combobox whose options load
|
|
53
|
+
* asynchronously is the common case.
|
|
54
|
+
*
|
|
55
|
+
* Consecutive options sharing a `group` are gathered under one heading, in
|
|
56
|
+
* the order they were given. A group that repeats after an interruption
|
|
57
|
+
* gets a second heading, because reordering the caller's list to merge them
|
|
58
|
+
* would change which option the arrows reach next.
|
|
59
|
+
*/
|
|
60
|
+
function renderPalette() {
|
|
61
|
+
const groups = [];
|
|
62
|
+
for (const option of props.options) {
|
|
63
|
+
const last = groups[groups.length - 1];
|
|
64
|
+
if (last !== undefined && last.heading === option.group) {
|
|
65
|
+
last.options.push(option);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
groups.push({ heading: option.group, options: [option] });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return Command({
|
|
72
|
+
onSelect: choose,
|
|
73
|
+
children: () => html `${CommandInput({
|
|
74
|
+
placeholder: props.searchPlaceholder ?? "Search…",
|
|
75
|
+
})}${CommandList({
|
|
76
|
+
children: () => html `${CommandEmpty({
|
|
77
|
+
children: props.emptyMessage ?? "No results found.",
|
|
78
|
+
})}${groups.map((group) => CommandGroup({
|
|
79
|
+
heading: group.heading,
|
|
80
|
+
children: () => group.options.map((option) => CommandItem({
|
|
81
|
+
value: option.value,
|
|
82
|
+
children: option.label,
|
|
83
|
+
keywords: option.keywords,
|
|
84
|
+
disabled: option.disabled,
|
|
85
|
+
})),
|
|
86
|
+
}))}`,
|
|
87
|
+
})}`,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
55
90
|
floatingSurface({
|
|
56
91
|
anchor: () => document.getElementById(triggerId),
|
|
57
92
|
open: () => open(),
|
|
@@ -69,12 +104,7 @@ export const Combobox = component((props) => {
|
|
|
69
104
|
id="${contentId}"
|
|
70
105
|
class="${cn("bg-popover text-popover-foreground z-50 min-w-(--nebula-anchor-width) overflow-hidden rounded-md border shadow-md", zoomInOut, read(props.contentClass))}"
|
|
71
106
|
>
|
|
72
|
-
${
|
|
73
|
-
items: items(),
|
|
74
|
-
placeholder: props.searchPlaceholder ?? "Search…",
|
|
75
|
-
emptyMessage: props.emptyMessage ?? "No results found.",
|
|
76
|
-
onSelect: choose,
|
|
77
|
-
})}
|
|
107
|
+
${renderPalette()}
|
|
78
108
|
</div>`,
|
|
79
109
|
});
|
|
80
110
|
return html `<div data-slot="combobox" class="${() => cn("inline-flex", read(props.class))}">
|