@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,51 +1,87 @@
|
|
|
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
30
|
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
import {
|
|
32
|
+
component,
|
|
33
|
+
createContext,
|
|
34
|
+
html,
|
|
35
|
+
inject,
|
|
36
|
+
onUnmount,
|
|
37
|
+
provide,
|
|
38
|
+
type TemplateResult,
|
|
39
|
+
} from "@c9up/aurora";
|
|
40
|
+
import { type ButtonVariants, buttonVariants } from "../atoms/Button.js";
|
|
41
|
+
import type { Child, Parts, Slot } from "../lib/children.js";
|
|
42
|
+
import { slot } from "../lib/children.js";
|
|
24
43
|
import { cn } from "../lib/cn.js";
|
|
25
44
|
import { uid } from "../lib/id.js";
|
|
26
45
|
import { fadeInOut, zoomInOut } from "../lib/motion.js";
|
|
27
46
|
import { type Reactive, read } from "../lib/props.js";
|
|
28
47
|
import { controllable } from "../primitives/controllable.js";
|
|
29
48
|
import { modalSurface } from "../primitives/modalSurface.js";
|
|
30
|
-
import {
|
|
49
|
+
import { portal } from "../primitives/portal.js";
|
|
50
|
+
import { dialogBackdropClasses } from "./Dialog.js";
|
|
51
|
+
|
|
52
|
+
const panelClasses =
|
|
53
|
+
"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";
|
|
54
|
+
|
|
55
|
+
interface RegisteredContent {
|
|
56
|
+
readonly body: Child;
|
|
57
|
+
readonly size: "default" | "sm";
|
|
58
|
+
readonly class?: Reactive<string>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface AlertDialogApi {
|
|
62
|
+
readonly triggerId: string;
|
|
63
|
+
readonly panelId: string;
|
|
64
|
+
readonly titleId: string;
|
|
65
|
+
readonly descriptionId: string;
|
|
66
|
+
readonly cancelId: string;
|
|
67
|
+
readonly open: () => boolean;
|
|
68
|
+
setOpen(next: boolean): void;
|
|
69
|
+
confirm(): void;
|
|
70
|
+
cancel(): void;
|
|
71
|
+
declareTitle(): void;
|
|
72
|
+
declareDescription(): void;
|
|
73
|
+
register(content: RegisteredContent): void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const AlertDialogContext = createContext<AlertDialogApi>("AlertDialog");
|
|
31
77
|
|
|
32
78
|
export interface AlertDialogProps {
|
|
33
|
-
trigger?: Slot;
|
|
34
|
-
title: Child;
|
|
35
|
-
description: Child;
|
|
36
|
-
/** Label for the confirming action. Default `"Continue"`. */
|
|
37
|
-
actionLabel?: Child;
|
|
38
|
-
/** Label for the way out. Default `"Cancel"`. */
|
|
39
|
-
cancelLabel?: Child;
|
|
40
|
-
/** Styles the action as destructive. */
|
|
41
|
-
destructive?: boolean;
|
|
42
79
|
open?: Reactive<boolean>;
|
|
43
80
|
defaultOpen?: boolean;
|
|
44
81
|
onOpenChange?: (open: boolean) => void;
|
|
45
82
|
onConfirm?: () => void;
|
|
46
83
|
onCancel?: () => void;
|
|
47
|
-
|
|
48
|
-
contentClass?: Reactive<string>;
|
|
84
|
+
children?: Parts;
|
|
49
85
|
}
|
|
50
86
|
|
|
51
87
|
export const AlertDialog = component<AlertDialogProps>((props) => {
|
|
@@ -54,6 +90,9 @@ export const AlertDialog = component<AlertDialogProps>((props) => {
|
|
|
54
90
|
const titleId = uid("alert-dialog-title");
|
|
55
91
|
const descriptionId = uid("alert-dialog-description");
|
|
56
92
|
const cancelId = uid("alert-dialog-cancel");
|
|
93
|
+
let hasTitle = false;
|
|
94
|
+
let hasDescription = false;
|
|
95
|
+
let content: RegisteredContent | undefined;
|
|
57
96
|
|
|
58
97
|
const state = controllable<boolean>({
|
|
59
98
|
value: props.open,
|
|
@@ -71,63 +110,261 @@ export const AlertDialog = component<AlertDialogProps>((props) => {
|
|
|
71
110
|
state.set(false);
|
|
72
111
|
}
|
|
73
112
|
|
|
74
|
-
|
|
113
|
+
provide<AlertDialogApi>(AlertDialogContext, {
|
|
114
|
+
triggerId,
|
|
115
|
+
panelId,
|
|
116
|
+
titleId,
|
|
117
|
+
descriptionId,
|
|
118
|
+
cancelId,
|
|
75
119
|
open: () => state.current(),
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
aria-modal="true"
|
|
89
|
-
aria-labelledby="${titleId}"
|
|
90
|
-
aria-describedby="${descriptionId}"
|
|
91
|
-
tabindex="-1"
|
|
92
|
-
class="${cn(dialogPanelClasses, zoomInOut, read(props.contentClass))}"
|
|
93
|
-
>
|
|
94
|
-
<div class="flex flex-col gap-2 text-center sm:text-left">
|
|
95
|
-
<h2 id="${titleId}" class="text-lg font-semibold">${props.title}</h2>
|
|
96
|
-
<p id="${descriptionId}" class="text-muted-foreground text-sm">
|
|
97
|
-
${props.description}
|
|
98
|
-
</p>
|
|
99
|
-
</div>
|
|
100
|
-
<div class="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">
|
|
101
|
-
<button
|
|
102
|
-
type="button"
|
|
103
|
-
id="${cancelId}"
|
|
104
|
-
data-slot="alert-dialog-cancel"
|
|
105
|
-
class="${buttonVariants({ variant: "outline" })}"
|
|
106
|
-
@click="${cancel}"
|
|
107
|
-
>${props.cancelLabel ?? "Cancel"}</button>
|
|
108
|
-
<button
|
|
109
|
-
type="button"
|
|
110
|
-
data-slot="alert-dialog-action"
|
|
111
|
-
class="${buttonVariants({
|
|
112
|
-
variant: props.destructive === true ? "destructive" : "default",
|
|
113
|
-
})}"
|
|
114
|
-
@click="${confirm}"
|
|
115
|
-
>${props.actionLabel ?? "Continue"}</button>
|
|
116
|
-
</div>
|
|
117
|
-
</div>
|
|
118
|
-
</div>`,
|
|
120
|
+
setOpen: (next) => state.set(next),
|
|
121
|
+
confirm,
|
|
122
|
+
cancel,
|
|
123
|
+
declareTitle() {
|
|
124
|
+
hasTitle = true;
|
|
125
|
+
},
|
|
126
|
+
declareDescription() {
|
|
127
|
+
hasDescription = true;
|
|
128
|
+
},
|
|
129
|
+
register(registered) {
|
|
130
|
+
content = registered;
|
|
131
|
+
},
|
|
119
132
|
});
|
|
120
133
|
|
|
121
|
-
|
|
122
|
-
|
|
134
|
+
const parts = props.children?.();
|
|
135
|
+
|
|
136
|
+
if (content !== undefined) {
|
|
137
|
+
const registered = content;
|
|
138
|
+
if (!hasTitle) {
|
|
139
|
+
console.warn(
|
|
140
|
+
"nebula: an AlertDialog has no AlertDialogTitle. It will be announced only as “alertdialog”.",
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
modalSurface({
|
|
144
|
+
open: () => state.current(),
|
|
145
|
+
// Escape cancels rather than confirms: the keyboard spelling of the
|
|
146
|
+
// safe way out.
|
|
147
|
+
onClose: cancel,
|
|
148
|
+
panel: (root) => root.querySelector(`#${CSS.escape(panelId)}`),
|
|
149
|
+
initialFocus: (panel) => panel.querySelector(`#${CSS.escape(cancelId)}`),
|
|
150
|
+
returnFocus: () => document.getElementById(triggerId),
|
|
151
|
+
dismissOnOutside: false,
|
|
152
|
+
content: () =>
|
|
153
|
+
renderSurface(registered, {
|
|
154
|
+
panelId,
|
|
155
|
+
titleId: hasTitle ? titleId : undefined,
|
|
156
|
+
descriptionId: hasDescription ? descriptionId : undefined,
|
|
157
|
+
}),
|
|
158
|
+
});
|
|
123
159
|
}
|
|
124
160
|
|
|
161
|
+
return html`${parts}`;
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
export interface AlertDialogTriggerProps {
|
|
165
|
+
children?: Slot;
|
|
166
|
+
class?: Reactive<string>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export const AlertDialogTrigger = component<AlertDialogTriggerProps>(
|
|
170
|
+
(props) => {
|
|
171
|
+
const dialog = inject(AlertDialogContext);
|
|
172
|
+
return html`<button
|
|
173
|
+
type="button"
|
|
174
|
+
data-slot="alert-dialog-trigger"
|
|
175
|
+
id="${dialog.triggerId}"
|
|
176
|
+
aria-haspopup="dialog"
|
|
177
|
+
aria-expanded="${() => (dialog.open() ? "true" : "false")}"
|
|
178
|
+
data-state="${() => (dialog.open() ? "open" : "closed")}"
|
|
179
|
+
class="${() => cn(read(props.class))}"
|
|
180
|
+
@click="${() => dialog.setOpen(true)}"
|
|
181
|
+
>${slot(props.children)}</button>`;
|
|
182
|
+
},
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
export interface AlertDialogContentProps {
|
|
186
|
+
children?: Parts;
|
|
187
|
+
size?: "default" | "sm";
|
|
188
|
+
class?: Reactive<string>;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export const AlertDialogContent = component<AlertDialogContentProps>(
|
|
192
|
+
(props) => {
|
|
193
|
+
const dialog = inject(AlertDialogContext);
|
|
194
|
+
dialog.register({
|
|
195
|
+
body: props.children?.(),
|
|
196
|
+
size: props.size ?? "default",
|
|
197
|
+
class: props.class,
|
|
198
|
+
});
|
|
199
|
+
return html``;
|
|
200
|
+
},
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
export interface AlertDialogSectionProps {
|
|
204
|
+
children?: Slot;
|
|
205
|
+
class?: Reactive<string>;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export const AlertDialogOverlay = component<AlertDialogSectionProps>(
|
|
209
|
+
(props) => html`<div
|
|
210
|
+
data-slot="alert-dialog-overlay"
|
|
211
|
+
class="${() => cn(dialogBackdropClasses, read(props.class))}"
|
|
212
|
+
></div>`,
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
export interface AlertDialogPortalProps {
|
|
216
|
+
children?: Slot;
|
|
217
|
+
container?: () => Element | null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Mount children outside the component's own DOM position.
|
|
222
|
+
*
|
|
223
|
+
* `AlertDialogContent` does not need it — the dialog portals its whole overlay
|
|
224
|
+
* through `modalSurface`, which also owns the trap and the scroll lock. It is
|
|
225
|
+
* exported because upstream exports it, doing here what its name says rather
|
|
226
|
+
* than standing in as a passthrough.
|
|
227
|
+
*/
|
|
228
|
+
export const AlertDialogPortal = component<AlertDialogPortalProps>((props) => {
|
|
229
|
+
const mounted = portal(html`${slot(props.children)}`, {
|
|
230
|
+
container: props.container,
|
|
231
|
+
});
|
|
232
|
+
mounted.host.setAttribute("data-slot", "alert-dialog-portal");
|
|
233
|
+
onUnmount(() => mounted.close());
|
|
234
|
+
return html``;
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
export const AlertDialogHeader = component<AlertDialogSectionProps>(
|
|
238
|
+
(props) => html`<div
|
|
239
|
+
data-slot="alert-dialog-header"
|
|
240
|
+
class="${() =>
|
|
241
|
+
cn(
|
|
242
|
+
"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",
|
|
243
|
+
read(props.class),
|
|
244
|
+
)}"
|
|
245
|
+
>${slot(props.children)}</div>`,
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
export const AlertDialogFooter = component<AlertDialogSectionProps>(
|
|
249
|
+
(props) => html`<div
|
|
250
|
+
data-slot="alert-dialog-footer"
|
|
251
|
+
class="${() =>
|
|
252
|
+
cn(
|
|
253
|
+
"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",
|
|
254
|
+
read(props.class),
|
|
255
|
+
)}"
|
|
256
|
+
>${slot(props.children)}</div>`,
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
/** An icon block above the title — a warning glyph, a product mark. */
|
|
260
|
+
export const AlertDialogMedia = component<AlertDialogSectionProps>(
|
|
261
|
+
(props) => html`<div
|
|
262
|
+
data-slot="alert-dialog-media"
|
|
263
|
+
class="${() =>
|
|
264
|
+
cn(
|
|
265
|
+
"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",
|
|
266
|
+
read(props.class),
|
|
267
|
+
)}"
|
|
268
|
+
>${slot(props.children)}</div>`,
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
export const AlertDialogTitle = component<AlertDialogSectionProps>((props) => {
|
|
272
|
+
const dialog = inject(AlertDialogContext);
|
|
273
|
+
dialog.declareTitle();
|
|
274
|
+
return html`<h2
|
|
275
|
+
id="${dialog.titleId}"
|
|
276
|
+
data-slot="alert-dialog-title"
|
|
277
|
+
class="${() =>
|
|
278
|
+
cn(
|
|
279
|
+
"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",
|
|
280
|
+
read(props.class),
|
|
281
|
+
)}"
|
|
282
|
+
>${slot(props.children)}</h2>`;
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
export const AlertDialogDescription = component<AlertDialogSectionProps>(
|
|
286
|
+
(props) => {
|
|
287
|
+
const dialog = inject(AlertDialogContext);
|
|
288
|
+
dialog.declareDescription();
|
|
289
|
+
return html`<p
|
|
290
|
+
id="${dialog.descriptionId}"
|
|
291
|
+
data-slot="alert-dialog-description"
|
|
292
|
+
class="${() => cn("text-muted-foreground text-sm", read(props.class))}"
|
|
293
|
+
>${slot(props.children)}</p>`;
|
|
294
|
+
},
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
export interface AlertDialogButtonProps {
|
|
298
|
+
children?: Slot;
|
|
299
|
+
variant?: ButtonVariants["variant"];
|
|
300
|
+
size?: ButtonVariants["size"];
|
|
301
|
+
class?: Reactive<string>;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** The confirming action. */
|
|
305
|
+
export const AlertDialogAction = component<AlertDialogButtonProps>((props) => {
|
|
306
|
+
const dialog = inject(AlertDialogContext);
|
|
125
307
|
return html`<button
|
|
126
308
|
type="button"
|
|
127
|
-
data-slot="alert-dialog-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
309
|
+
data-slot="alert-dialog-action"
|
|
310
|
+
class="${() =>
|
|
311
|
+
cn(
|
|
312
|
+
buttonVariants({
|
|
313
|
+
variant: props.variant ?? "default",
|
|
314
|
+
size: props.size ?? "default",
|
|
315
|
+
}),
|
|
316
|
+
read(props.class),
|
|
317
|
+
)}"
|
|
318
|
+
@click="${() => dialog.confirm()}"
|
|
319
|
+
>${slot(props.children)}</button>`;
|
|
133
320
|
});
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* The way out, and where focus lands.
|
|
324
|
+
*
|
|
325
|
+
* The safe choice is the one a hurried Enter should hit, which is why the
|
|
326
|
+
* surface focuses this rather than the action beside it.
|
|
327
|
+
*/
|
|
328
|
+
export const AlertDialogCancel = component<AlertDialogButtonProps>((props) => {
|
|
329
|
+
const dialog = inject(AlertDialogContext);
|
|
330
|
+
return html`<button
|
|
331
|
+
type="button"
|
|
332
|
+
data-slot="alert-dialog-cancel"
|
|
333
|
+
id="${dialog.cancelId}"
|
|
334
|
+
class="${() =>
|
|
335
|
+
cn(
|
|
336
|
+
buttonVariants({
|
|
337
|
+
variant: props.variant ?? "outline",
|
|
338
|
+
size: props.size ?? "default",
|
|
339
|
+
}),
|
|
340
|
+
read(props.class),
|
|
341
|
+
)}"
|
|
342
|
+
@click="${() => dialog.cancel()}"
|
|
343
|
+
>${slot(props.children)}</button>`;
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
interface SurfaceIds {
|
|
347
|
+
readonly panelId: string;
|
|
348
|
+
readonly titleId: string | undefined;
|
|
349
|
+
readonly descriptionId: string | undefined;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function renderSurface(
|
|
353
|
+
registered: RegisteredContent,
|
|
354
|
+
ids: SurfaceIds,
|
|
355
|
+
): TemplateResult {
|
|
356
|
+
return html`<div data-slot="alert-dialog-portal" class="${cn("fixed inset-0 z-50", fadeInOut)}">
|
|
357
|
+
<div data-slot="alert-dialog-overlay" class="${dialogBackdropClasses}"></div>
|
|
358
|
+
<div
|
|
359
|
+
data-slot="alert-dialog-content"
|
|
360
|
+
data-size="${registered.size}"
|
|
361
|
+
id="${ids.panelId}"
|
|
362
|
+
role="alertdialog"
|
|
363
|
+
aria-modal="true"
|
|
364
|
+
aria-labelledby="${ids.titleId}"
|
|
365
|
+
aria-describedby="${ids.descriptionId}"
|
|
366
|
+
tabindex="-1"
|
|
367
|
+
class="${cn(panelClasses, zoomInOut, read(registered.class))}"
|
|
368
|
+
>${registered.body}</div>
|
|
369
|
+
</div>`;
|
|
370
|
+
}
|
|
@@ -17,21 +17,44 @@
|
|
|
17
17
|
* the edge carries none of that.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
component,
|
|
22
|
+
createContext,
|
|
23
|
+
html,
|
|
24
|
+
inject,
|
|
25
|
+
onMount,
|
|
26
|
+
onUnmount,
|
|
27
|
+
provide,
|
|
28
|
+
signal,
|
|
29
|
+
} from "@c9up/aurora";
|
|
21
30
|
import { buttonVariants } from "../atoms/Button.js";
|
|
22
|
-
import type {
|
|
31
|
+
import type { Parts, Slot } from "../lib/children.js";
|
|
32
|
+
import { slot } from "../lib/children.js";
|
|
23
33
|
import { cn } from "../lib/cn.js";
|
|
24
34
|
import { ArrowLeftIcon, ArrowRightIcon } from "../lib/icons.js";
|
|
25
35
|
import { uid } from "../lib/id.js";
|
|
26
36
|
import { type Reactive, read } from "../lib/props.js";
|
|
27
37
|
|
|
38
|
+
interface CarouselApi {
|
|
39
|
+
readonly trackId: string;
|
|
40
|
+
readonly horizontal: boolean;
|
|
41
|
+
readonly atStart: () => boolean;
|
|
42
|
+
readonly atEnd: () => boolean;
|
|
43
|
+
/** Claim the next slide's position, for its "n of m" label. */
|
|
44
|
+
claimSlide(): number;
|
|
45
|
+
readonly slideCount: () => number;
|
|
46
|
+
scrollByPage(direction: 1 | -1): void;
|
|
47
|
+
syncEdges(): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const CarouselContext = createContext<CarouselApi>("Carousel");
|
|
51
|
+
|
|
28
52
|
export interface CarouselProps {
|
|
29
|
-
slides: readonly Child[];
|
|
30
53
|
/** Announced before the slides. */
|
|
31
54
|
label?: string;
|
|
32
55
|
orientation?: "horizontal" | "vertical";
|
|
33
56
|
class?: Reactive<string>;
|
|
34
|
-
|
|
57
|
+
children?: Parts;
|
|
35
58
|
}
|
|
36
59
|
|
|
37
60
|
export const Carousel = component<CarouselProps>((props) => {
|
|
@@ -39,18 +62,18 @@ export const Carousel = component<CarouselProps>((props) => {
|
|
|
39
62
|
const horizontal = props.orientation !== "vertical";
|
|
40
63
|
const atStart = signal(true);
|
|
41
64
|
const atEnd = signal(false);
|
|
65
|
+
let slides = 0;
|
|
42
66
|
|
|
43
67
|
function track(): HTMLElement | null {
|
|
44
68
|
return document.getElementById(trackId);
|
|
45
69
|
}
|
|
46
70
|
|
|
47
71
|
/**
|
|
48
|
-
*
|
|
72
|
+
* Which arrows are usable, read from the scroll position.
|
|
49
73
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* button enabled on a carousel that cannot scroll any further.
|
|
74
|
+
* Derived rather than tracked: the track is a scroll container, so a drag,
|
|
75
|
+
* a wheel, a trackpad swipe and the buttons all move it, and only the
|
|
76
|
+
* element knows where it ended up.
|
|
54
77
|
*/
|
|
55
78
|
function syncEdges(): void {
|
|
56
79
|
const element = track();
|
|
@@ -98,7 +121,19 @@ export const Carousel = component<CarouselProps>((props) => {
|
|
|
98
121
|
window.removeEventListener("resize", syncEdges);
|
|
99
122
|
});
|
|
100
123
|
|
|
101
|
-
|
|
124
|
+
provide<CarouselApi>(CarouselContext, {
|
|
125
|
+
trackId,
|
|
126
|
+
horizontal,
|
|
127
|
+
atStart: () => atStart(),
|
|
128
|
+
atEnd: () => atEnd(),
|
|
129
|
+
claimSlide() {
|
|
130
|
+
slides += 1;
|
|
131
|
+
return slides;
|
|
132
|
+
},
|
|
133
|
+
slideCount: () => slides,
|
|
134
|
+
scrollByPage,
|
|
135
|
+
syncEdges,
|
|
136
|
+
});
|
|
102
137
|
|
|
103
138
|
return html`<div
|
|
104
139
|
data-slot="carousel"
|
|
@@ -107,55 +142,97 @@ export const Carousel = component<CarouselProps>((props) => {
|
|
|
107
142
|
aria-label="${props.label ?? "Carousel"}"
|
|
108
143
|
class="${() => cn("relative", read(props.class))}"
|
|
109
144
|
@keydown="${onKeyDown}"
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
145
|
+
>${props.children?.()}</div>`;
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
export interface CarouselContentProps {
|
|
149
|
+
children?: Slot;
|
|
150
|
+
class?: Reactive<string>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The scroll container. */
|
|
154
|
+
export const CarouselContent = component<CarouselContentProps>((props) => {
|
|
155
|
+
const carousel = inject(CarouselContext);
|
|
156
|
+
return html`<div
|
|
157
|
+
data-slot="carousel-content"
|
|
158
|
+
id="${carousel.trackId}"
|
|
159
|
+
tabindex="0"
|
|
160
|
+
class="${() =>
|
|
161
|
+
cn(
|
|
162
|
+
"flex snap-mandatory gap-4 overflow-auto scroll-smooth outline-none motion-reduce:scroll-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
|
|
163
|
+
carousel.horizontal ? "snap-x flex-row" : "snap-y max-h-96 flex-col",
|
|
164
|
+
read(props.class),
|
|
120
165
|
)}"
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
166
|
+
>${slot(props.children)}</div>`;
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
export interface CarouselItemProps {
|
|
170
|
+
children?: Slot;
|
|
171
|
+
class?: Reactive<string>;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* One slide.
|
|
176
|
+
*
|
|
177
|
+
* Claims its position as it is built, which is what `"3 of 7"` needs — and the
|
|
178
|
+
* count is only final once every slide has been built, so the label reads it
|
|
179
|
+
* lazily rather than capturing it.
|
|
180
|
+
*/
|
|
181
|
+
export const CarouselItem = component<CarouselItemProps>((props) => {
|
|
182
|
+
const carousel = inject(CarouselContext);
|
|
183
|
+
const position = carousel.claimSlide();
|
|
184
|
+
return html`<div
|
|
185
|
+
data-slot="carousel-item"
|
|
186
|
+
role="group"
|
|
187
|
+
aria-roledescription="slide"
|
|
188
|
+
aria-label="${() => `${position} of ${carousel.slideCount()}`}"
|
|
189
|
+
class="${() =>
|
|
190
|
+
cn("min-w-0 shrink-0 grow-0 basis-full snap-start", read(props.class))}"
|
|
191
|
+
>${slot(props.children)}</div>`;
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
export interface CarouselButtonProps {
|
|
195
|
+
class?: Reactive<string>;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const arrowClasses = "absolute size-8 rounded-full";
|
|
199
|
+
|
|
200
|
+
export const CarouselPrevious = component<CarouselButtonProps>((props) => {
|
|
201
|
+
const carousel = inject(CarouselContext);
|
|
202
|
+
return html`<button
|
|
203
|
+
type="button"
|
|
204
|
+
data-slot="carousel-previous"
|
|
205
|
+
aria-label="Previous slide"
|
|
206
|
+
?disabled="${() => carousel.atStart()}"
|
|
207
|
+
class="${() =>
|
|
208
|
+
cn(
|
|
138
209
|
buttonVariants({ variant: "outline", size: "icon" }),
|
|
139
|
-
|
|
140
|
-
horizontal
|
|
210
|
+
arrowClasses,
|
|
211
|
+
carousel.horizontal
|
|
141
212
|
? "top-1/2 -left-12 -translate-y-1/2"
|
|
142
213
|
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
214
|
+
read(props.class),
|
|
143
215
|
)}"
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
216
|
+
@click="${() => carousel.scrollByPage(-1)}"
|
|
217
|
+
>${ArrowLeftIcon({ class: "size-4" })}</button>`;
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
export const CarouselNext = component<CarouselButtonProps>((props) => {
|
|
221
|
+
const carousel = inject(CarouselContext);
|
|
222
|
+
return html`<button
|
|
223
|
+
type="button"
|
|
224
|
+
data-slot="carousel-next"
|
|
225
|
+
aria-label="Next slide"
|
|
226
|
+
?disabled="${() => carousel.atEnd()}"
|
|
227
|
+
class="${() =>
|
|
228
|
+
cn(
|
|
152
229
|
buttonVariants({ variant: "outline", size: "icon" }),
|
|
153
|
-
|
|
154
|
-
horizontal
|
|
230
|
+
arrowClasses,
|
|
231
|
+
carousel.horizontal
|
|
155
232
|
? "top-1/2 -right-12 -translate-y-1/2"
|
|
156
233
|
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
|
234
|
+
read(props.class),
|
|
157
235
|
)}"
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
</div>`;
|
|
236
|
+
@click="${() => carousel.scrollByPage(1)}"
|
|
237
|
+
>${ArrowRightIcon({ class: "size-4" })}</button>`;
|
|
161
238
|
});
|