@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.
Files changed (122) hide show
  1. package/dist/atoms/Avatar.d.ts +36 -9
  2. package/dist/atoms/Avatar.js +66 -27
  3. package/dist/atoms/index.d.ts +1 -1
  4. package/dist/atoms/index.js +1 -1
  5. package/dist/lib/children.d.ts +30 -0
  6. package/dist/lib/motion.d.ts +10 -0
  7. package/dist/lib/motion.js +10 -0
  8. package/dist/molecules/Accordion.d.ts +36 -15
  9. package/dist/molecules/Accordion.js +68 -45
  10. package/dist/molecules/Breadcrumb.d.ts +29 -11
  11. package/dist/molecules/Breadcrumb.js +52 -52
  12. package/dist/molecules/Collapsible.d.ts +18 -17
  13. package/dist/molecules/Collapsible.js +42 -34
  14. package/dist/molecules/Field.d.ts +66 -30
  15. package/dist/molecules/Field.js +106 -55
  16. package/dist/molecules/InputGroup.d.ts +39 -21
  17. package/dist/molecules/InputGroup.js +43 -27
  18. package/dist/molecules/InputOTP.d.ts +26 -3
  19. package/dist/molecules/InputOTP.js +109 -76
  20. package/dist/molecules/Message.js +5 -4
  21. package/dist/molecules/Pagination.d.ts +36 -11
  22. package/dist/molecules/Pagination.js +58 -74
  23. package/dist/molecules/RadioGroup.d.ts +25 -17
  24. package/dist/molecules/RadioGroup.js +47 -43
  25. package/dist/molecules/Resizable.d.ts +32 -7
  26. package/dist/molecules/Resizable.js +76 -49
  27. package/dist/molecules/Tabs.d.ts +49 -11
  28. package/dist/molecules/Tabs.js +107 -51
  29. package/dist/molecules/ToggleGroup.d.ts +16 -10
  30. package/dist/molecules/ToggleGroup.js +37 -21
  31. package/dist/molecules/index.d.ts +11 -11
  32. package/dist/molecules/index.js +11 -11
  33. package/dist/organisms/AlertDialog.d.ts +80 -28
  34. package/dist/organisms/AlertDialog.js +192 -67
  35. package/dist/organisms/Carousel.d.ts +25 -3
  36. package/dist/organisms/Carousel.js +75 -43
  37. package/dist/organisms/Combobox.d.ts +2 -1
  38. package/dist/organisms/Combobox.js +46 -16
  39. package/dist/organisms/Command.d.ts +73 -32
  40. package/dist/organisms/Command.js +209 -131
  41. package/dist/organisms/CommandDialog.js +5 -5
  42. package/dist/organisms/ContextMenu.d.ts +41 -19
  43. package/dist/organisms/ContextMenu.js +112 -71
  44. package/dist/organisms/DataTable.js +42 -8
  45. package/dist/organisms/Dialog.d.ts +97 -31
  46. package/dist/organisms/Dialog.js +193 -68
  47. package/dist/organisms/Drawer.d.ts +33 -10
  48. package/dist/organisms/Drawer.js +130 -52
  49. package/dist/organisms/DropdownMenu.d.ts +58 -11
  50. package/dist/organisms/DropdownMenu.js +137 -50
  51. package/dist/organisms/Form.js +9 -11
  52. package/dist/organisms/HoverCard.d.ts +39 -19
  53. package/dist/organisms/HoverCard.js +116 -40
  54. package/dist/organisms/Menubar.d.ts +55 -19
  55. package/dist/organisms/Menubar.js +166 -82
  56. package/dist/organisms/NavigationMenu.d.ts +77 -31
  57. package/dist/organisms/NavigationMenu.js +169 -98
  58. package/dist/organisms/Popover.d.ts +72 -12
  59. package/dist/organisms/Popover.js +132 -25
  60. package/dist/organisms/Questionnaire.js +5 -5
  61. package/dist/organisms/Select.d.ts +99 -18
  62. package/dist/organisms/Select.js +253 -111
  63. package/dist/organisms/Sheet.d.ts +57 -13
  64. package/dist/organisms/Sheet.js +141 -54
  65. package/dist/organisms/Sidebar.d.ts +146 -56
  66. package/dist/organisms/Sidebar.js +236 -128
  67. package/dist/organisms/Tooltip.d.ts +88 -14
  68. package/dist/organisms/Tooltip.js +210 -47
  69. package/dist/organisms/index.d.ts +15 -15
  70. package/dist/organisms/index.js +15 -15
  71. package/dist/primitives/floating.js +25 -0
  72. package/dist/primitives/floatingSurface.d.ts +11 -0
  73. package/dist/primitives/floatingSurface.js +8 -0
  74. package/dist/primitives/menu.d.ts +45 -1
  75. package/dist/primitives/menu.js +45 -14
  76. package/dist/primitives/menuParts.d.ts +113 -0
  77. package/dist/primitives/menuParts.js +207 -0
  78. package/nebula.css +1 -1
  79. package/package.json +5 -4
  80. package/registry.json +18 -6
  81. package/src/atoms/Avatar.ts +141 -37
  82. package/src/atoms/index.ts +13 -1
  83. package/src/lib/children.ts +31 -0
  84. package/src/lib/motion.ts +12 -0
  85. package/src/molecules/Accordion.ts +120 -60
  86. package/src/molecules/Breadcrumb.ts +77 -76
  87. package/src/molecules/Collapsible.ts +77 -41
  88. package/src/molecules/Field.ts +187 -72
  89. package/src/molecules/InputGroup.ts +88 -35
  90. package/src/molecules/InputOTP.ts +150 -86
  91. package/src/molecules/Message.ts +6 -4
  92. package/src/molecules/Pagination.ts +96 -101
  93. package/src/molecules/RadioGroup.ts +70 -59
  94. package/src/molecules/Resizable.ts +138 -75
  95. package/src/molecules/Tabs.ts +187 -74
  96. package/src/molecules/ToggleGroup.ts +77 -38
  97. package/src/molecules/index.ts +85 -8
  98. package/src/organisms/AlertDialog.ts +319 -82
  99. package/src/organisms/Carousel.ts +129 -52
  100. package/src/organisms/Combobox.ts +64 -19
  101. package/src/organisms/Command.ts +342 -159
  102. package/src/organisms/CommandDialog.ts +6 -6
  103. package/src/organisms/ContextMenu.ts +185 -83
  104. package/src/organisms/DataTable.ts +56 -10
  105. package/src/organisms/Dialog.ts +312 -102
  106. package/src/organisms/Drawer.ts +219 -71
  107. package/src/organisms/DropdownMenu.ts +219 -61
  108. package/src/organisms/Form.ts +48 -34
  109. package/src/organisms/HoverCard.ts +187 -53
  110. package/src/organisms/Menubar.ts +247 -87
  111. package/src/organisms/NavigationMenu.ts +306 -128
  112. package/src/organisms/Popover.ts +215 -39
  113. package/src/organisms/Questionnaire.ts +9 -6
  114. package/src/organisms/Select.ts +397 -130
  115. package/src/organisms/Sheet.ts +252 -83
  116. package/src/organisms/Sidebar.ts +438 -185
  117. package/src/organisms/Tooltip.ts +315 -65
  118. package/src/organisms/index.ts +284 -14
  119. package/src/primitives/floating.ts +33 -0
  120. package/src/primitives/floatingSurface.ts +19 -0
  121. package/src/primitives/menu.ts +79 -18
  122. package/src/primitives/menuParts.ts +371 -0
@@ -2,8 +2,24 @@
2
2
  * Dialog — a modal window over the page.
3
3
  *
4
4
  * `modalSurface` supplies the contract (trap, scroll lock, backdrop dismissal,
5
- * hiding the page from assistive technology); this component supplies the
6
- * markup and the trigger.
5
+ * hiding the page from assistive technology); these parts supply the markup.
6
+ *
7
+ * Dialog({ children: () => html`
8
+ * ${DialogTrigger({ children: "Edit" })}
9
+ * ${DialogContent({ children: () => html`
10
+ * ${DialogHeader({ children: () => html`
11
+ * ${DialogTitle({ children: "Edit profile" })}
12
+ * ${DialogDescription({ children: "Change it." })}
13
+ * ` })}
14
+ * ${DialogFooter({ children: () => Button({ children: "Save" }) })}
15
+ * ` })}
16
+ * ` })
17
+ *
18
+ * Every part is built during `Dialog`'s setup, including the ones inside
19
+ * `DialogContent`. That is not only the context rule — `DialogTitle` has to
20
+ * have registered before the surface is wired, because the panel names itself
21
+ * with the title's id and a panel rendered first would have had nothing to
22
+ * point at.
7
23
  *
8
24
  * The `panel` callback matters more than it looks. The overlay's root spans
9
25
  * the viewport so the backdrop can, which means containment has to be answered
@@ -12,13 +28,23 @@
12
28
  *
13
29
  * `aria-labelledby` points at the title and `aria-describedby` at the
14
30
  * description, so a screen reader announces what the dialog is for on open. A
15
- * dialog with neither announces only "dialog", which is why `title` is
16
- * required rather than optional — `srOnlyTitle` is there for designs that show
17
- * no visible heading.
31
+ * dialog with neither announces only "dialog", which is why a missing
32
+ * `DialogTitle` is warned about — as upstream warns — rather than tolerated.
18
33
  */
19
34
 
20
- import { component, html, signal } from "@c9up/aurora";
21
- import { type Slot, slot } from "../lib/children.js";
35
+ import {
36
+ component,
37
+ createContext,
38
+ html,
39
+ inject,
40
+ onUnmount,
41
+ provide,
42
+ signal,
43
+ type TemplateResult,
44
+ } from "@c9up/aurora";
45
+ import { Button } from "../atoms/Button.js";
46
+ import type { Child, Parts, Slot } from "../lib/children.js";
47
+ import { slot } from "../lib/children.js";
22
48
  import { cn } from "../lib/cn.js";
23
49
  import { XIcon } from "../lib/icons.js";
24
50
  import { uid } from "../lib/id.js";
@@ -26,46 +52,61 @@ import { fadeInOut, zoomInOut } from "../lib/motion.js";
26
52
  import { type Reactive, read } from "../lib/props.js";
27
53
  import { controllable } from "../primitives/controllable.js";
28
54
  import { modalSurface } from "../primitives/modalSurface.js";
55
+ import { portal } from "../primitives/portal.js";
29
56
 
30
- export const dialogBackdropClasses = "fixed inset-0 z-50 bg-black/50";
57
+ export const dialogBackdropClasses =
58
+ "fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0";
31
59
 
32
60
  export const dialogPanelClasses =
33
- "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 outline-none sm:max-w-lg";
61
+ "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 sm:max-w-lg";
62
+
63
+ const closeButtonClasses =
64
+ "ring-offset-background focus-visible:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0";
65
+
66
+ interface RegisteredContent {
67
+ readonly body: Child;
68
+ readonly showCloseButton: boolean;
69
+ readonly dismissOnOutside: boolean;
70
+ readonly dismissOnEscape: boolean;
71
+ readonly class?: Reactive<string>;
72
+ }
73
+
74
+ interface DialogApi {
75
+ readonly triggerId: string;
76
+ readonly panelId: string;
77
+ readonly titleId: string;
78
+ readonly descriptionId: string;
79
+ readonly open: () => boolean;
80
+ setOpen(next: boolean): void;
81
+ /** A part announcing it exists, so the panel can point `aria-*` at it. */
82
+ declareTitle(): void;
83
+ declareDescription(): void;
84
+ register(content: RegisteredContent): void;
85
+ }
86
+
87
+ const DialogContext = createContext<DialogApi>("Dialog");
34
88
 
35
89
  export interface DialogProps {
36
- /** Rendered inside the trigger button. Omit to drive `open` yourself. */
37
- trigger?: Slot;
38
- /**
39
- * Announced on open. Hide it visually with `srOnlyTitle`.
40
- *
41
- * A `Slot`, so it may be an accessor: one Dialog driven between "create" and
42
- * "edit" needs a title that follows. It already behaved that way — the
43
- * renderer binds whatever it is given — while the type said `Child` and
44
- * refused the function, so the working call did not compile and the type
45
- * disagreed with `children` beside it for no reason.
46
- */
47
- title: Slot;
48
- description?: Slot;
49
- children?: Slot;
50
- /** Actions, laid out bottom-right. */
51
- footer?: Slot;
52
90
  open?: Reactive<boolean>;
53
91
  defaultOpen?: boolean;
54
92
  onOpenChange?: (open: boolean) => void;
55
- /** Keep the title for screen readers but out of the layout. */
56
- srOnlyTitle?: boolean;
57
- /** Hide the corner close button. Escape and the backdrop still work. */
58
- hideCloseButton?: boolean;
59
- class?: Reactive<string>;
60
- triggerClass?: Reactive<string>;
61
- contentClass?: Reactive<string>;
93
+ children?: Parts;
62
94
  }
63
95
 
96
+ /**
97
+ * The state every part reads.
98
+ *
99
+ * Renders no element of its own, as upstream does not: `data-slot="dialog"`
100
+ * sits on a Radix Root that produces no DOM.
101
+ */
64
102
  export const Dialog = component<DialogProps>((props) => {
65
103
  const triggerId = uid("dialog-trigger");
66
104
  const panelId = uid("dialog-panel");
67
105
  const titleId = uid("dialog-title");
68
106
  const descriptionId = uid("dialog-description");
107
+ let hasTitle = false;
108
+ let hasDescription = false;
109
+ let content: RegisteredContent | undefined;
69
110
 
70
111
  const state = controllable<boolean>({
71
112
  value: props.open,
@@ -73,87 +114,256 @@ export const Dialog = component<DialogProps>((props) => {
73
114
  onChange: props.onOpenChange,
74
115
  });
75
116
 
76
- modalSurface({
117
+ provide<DialogApi>(DialogContext, {
118
+ triggerId,
119
+ panelId,
120
+ titleId,
121
+ descriptionId,
77
122
  open: () => state.current(),
78
- onClose: () => state.set(false),
79
- panel: (root) => root.querySelector(`#${CSS.escape(panelId)}`),
80
- returnFocus: () => document.getElementById(triggerId),
81
- content: () =>
82
- html`<div data-slot="dialog-overlay" class="${cn("fixed inset-0 z-50", fadeInOut)}">
83
- <div data-slot="dialog-backdrop" class="${dialogBackdropClasses}"></div>
84
- <div
85
- data-slot="dialog-content"
86
- id="${panelId}"
87
- role="dialog"
88
- aria-modal="true"
89
- aria-labelledby="${titleId}"
90
- aria-describedby="${props.description === undefined ? undefined : descriptionId}"
91
- tabindex="-1"
92
- class="${cn(dialogPanelClasses, zoomInOut, read(props.contentClass))}"
93
- >
94
- <div data-slot="dialog-header" class="flex flex-col gap-2 text-center sm:text-left">
95
- <h2
96
- id="${titleId}"
97
- data-slot="dialog-title"
98
- class="${cn(
99
- "text-lg leading-none font-semibold",
100
- props.srOnlyTitle === true ? "sr-only" : "",
101
- )}"
102
- >${slot(props.title)}</h2>
103
- ${
104
- props.description === undefined
105
- ? null
106
- : html`<p
107
- id="${descriptionId}"
108
- data-slot="dialog-description"
109
- class="text-muted-foreground text-sm"
110
- >${slot(props.description)}</p>`
111
- }
112
- </div>
113
- ${slot(props.children)}
114
- ${
115
- props.footer === undefined
116
- ? null
117
- : html`<div
118
- data-slot="dialog-footer"
119
- class="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end"
120
- >${slot(props.footer)}</div>`
121
- }
122
- ${
123
- props.hideCloseButton === true
124
- ? null
125
- : html`<button
126
- type="button"
127
- data-slot="dialog-close"
128
- class="ring-offset-background focus-visible:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none"
129
- @click="${() => state.set(false)}"
130
- >
131
- ${XIcon({ class: "size-4" })}
132
- <span class="sr-only">Close</span>
133
- </button>`
134
- }
135
- </div>
136
- </div>`,
123
+ setOpen: (next) => state.set(next),
124
+ declareTitle() {
125
+ hasTitle = true;
126
+ },
127
+ declareDescription() {
128
+ hasDescription = true;
129
+ },
130
+ register(registered) {
131
+ content = registered;
132
+ },
137
133
  });
138
134
 
139
- if (props.trigger === undefined) {
140
- // No trigger: the dialog is driven entirely by the `open` prop. Something
141
- // still has to be in the tree for the component to mount into, and the
142
- // surface itself lives in a portal.
143
- return html`<span data-slot="dialog" hidden></span>`;
135
+ const parts = props.children?.();
136
+
137
+ if (content !== undefined) {
138
+ const registered = content;
139
+ if (!hasTitle) {
140
+ // Upstream warns rather than raises, and so does this: a dialog with
141
+ // no accessible name is a real defect, but not one worth taking a
142
+ // page down for at runtime.
143
+ console.warn(
144
+ "nebula: a Dialog has no DialogTitle. It will be announced only as “dialog”.",
145
+ );
146
+ }
147
+ modalSurface({
148
+ open: () => state.current(),
149
+ onClose: () => state.set(false),
150
+ panel: (root) => root.querySelector(`#${CSS.escape(panelId)}`),
151
+ returnFocus: () => document.getElementById(triggerId),
152
+ dismissOnOutside: registered.dismissOnOutside,
153
+ dismissOnEscape: registered.dismissOnEscape,
154
+ content: () =>
155
+ renderSurface(registered, {
156
+ panelId,
157
+ titleId: hasTitle ? titleId : undefined,
158
+ descriptionId: hasDescription ? descriptionId : undefined,
159
+ close: () => state.set(false),
160
+ }),
161
+ });
144
162
  }
145
163
 
164
+ return html`${parts}`;
165
+ });
166
+
167
+ export interface DialogTriggerProps {
168
+ children?: Slot;
169
+ class?: Reactive<string>;
170
+ }
171
+
172
+ export const DialogTrigger = component<DialogTriggerProps>((props) => {
173
+ const dialog = inject(DialogContext);
146
174
  return html`<button
147
175
  type="button"
148
176
  data-slot="dialog-trigger"
149
- id="${triggerId}"
177
+ id="${dialog.triggerId}"
150
178
  aria-haspopup="dialog"
151
- aria-expanded="${() => (state.current() ? "true" : "false")}"
152
- class="${() => cn(read(props.triggerClass))}"
153
- @click="${() => state.set(true)}"
154
- >${slot(props.trigger)}</button>`;
179
+ aria-expanded="${() => (dialog.open() ? "true" : "false")}"
180
+ data-state="${() => (dialog.open() ? "open" : "closed")}"
181
+ class="${() => cn(read(props.class))}"
182
+ @click="${() => dialog.setOpen(true)}"
183
+ >${slot(props.children)}</button>`;
184
+ });
185
+
186
+ export interface DialogCloseProps {
187
+ children?: Slot;
188
+ class?: Reactive<string>;
189
+ }
190
+
191
+ /** Anything that dismisses the dialog — a Cancel button, the corner cross. */
192
+ export const DialogClose = component<DialogCloseProps>((props) => {
193
+ const dialog = inject(DialogContext);
194
+ return html`<button
195
+ type="button"
196
+ data-slot="dialog-close"
197
+ class="${() => cn(read(props.class))}"
198
+ @click="${() => dialog.setOpen(false)}"
199
+ >${slot(props.children)}</button>`;
155
200
  });
156
201
 
202
+ export interface DialogOverlayProps {
203
+ class?: Reactive<string>;
204
+ }
205
+
206
+ /** The backdrop. Rendered by `DialogContent`; exported to compose your own. */
207
+ export const DialogOverlay = component<DialogOverlayProps>(
208
+ (props) => html`<div
209
+ data-slot="dialog-overlay"
210
+ class="${() => cn(dialogBackdropClasses, read(props.class))}"
211
+ ></div>`,
212
+ );
213
+
214
+ export interface DialogPortalProps {
215
+ children?: Slot;
216
+ /** Where to mount. Defaults to `document.body`. */
217
+ container?: () => Element | null;
218
+ }
219
+
220
+ /**
221
+ * Mount children outside the component's own DOM position.
222
+ *
223
+ * `DialogContent` does NOT need it — `Dialog` portals the whole overlay
224
+ * through `modalSurface`, which also owns the trap and the scroll lock. It is
225
+ * exported because upstream exports it, and it does here what its name says
226
+ * rather than standing in as a passthrough.
227
+ */
228
+ export const DialogPortal = component<DialogPortalProps>((props) => {
229
+ const mounted = portal(html`${slot(props.children)}`, {
230
+ container: props.container,
231
+ });
232
+ mounted.host.setAttribute("data-slot", "dialog-portal");
233
+ onUnmount(() => mounted.close());
234
+ return html``;
235
+ });
236
+
237
+ export interface DialogContentProps {
238
+ children?: Parts;
239
+ /** The corner cross. */
240
+ showCloseButton?: boolean;
241
+ /** A click outside closes. `false` for a decision that must be made. */
242
+ dismissOnOutside?: boolean;
243
+ /** Escape closes. `false` for the same reason. */
244
+ dismissOnEscape?: boolean;
245
+ class?: Reactive<string>;
246
+ }
247
+
248
+ /**
249
+ * The panel.
250
+ *
251
+ * Renders nothing where it is written: the dialog portals its overlay out of
252
+ * the tree when it opens. Its children are built HERE, during setup, so the
253
+ * parts inside see the context and register before the surface is wired.
254
+ */
255
+ export const DialogContent = component<DialogContentProps>((props) => {
256
+ const dialog = inject(DialogContext);
257
+ const body = props.children?.();
258
+ dialog.register({
259
+ body,
260
+ showCloseButton: props.showCloseButton ?? true,
261
+ dismissOnOutside: props.dismissOnOutside ?? true,
262
+ dismissOnEscape: props.dismissOnEscape ?? true,
263
+ class: props.class,
264
+ });
265
+ return html``;
266
+ });
267
+
268
+ export interface DialogSectionProps {
269
+ children?: Slot;
270
+ class?: Reactive<string>;
271
+ }
272
+
273
+ export const DialogHeader = component<DialogSectionProps>(
274
+ (props) => html`<div
275
+ data-slot="dialog-header"
276
+ class="${() => cn("flex flex-col gap-2 text-center sm:text-left", read(props.class))}"
277
+ >${slot(props.children)}</div>`,
278
+ );
279
+
280
+ export interface DialogFooterProps extends DialogSectionProps {
281
+ /** Append a "Close" button after the children, as upstream can. */
282
+ showCloseButton?: boolean;
283
+ }
284
+
285
+ export const DialogFooter = component<DialogFooterProps>((props) => {
286
+ const dialog = inject(DialogContext);
287
+ const trailing =
288
+ props.showCloseButton === true
289
+ ? html`<button
290
+ type="button"
291
+ data-slot="dialog-close"
292
+ @click="${() => dialog.setOpen(false)}"
293
+ >${Button({ variant: "outline", children: "Close" })}</button>`
294
+ : null;
295
+ return html`<div
296
+ data-slot="dialog-footer"
297
+ class="${() => cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", read(props.class))}"
298
+ >${slot(props.children)}${trailing}</div>`;
299
+ });
300
+
301
+ export interface DialogTitleProps {
302
+ children?: Slot;
303
+ /** Keep it for screen readers but out of the layout. */
304
+ srOnly?: boolean;
305
+ class?: Reactive<string>;
306
+ }
307
+
308
+ export const DialogTitle = component<DialogTitleProps>((props) => {
309
+ const dialog = inject(DialogContext);
310
+ dialog.declareTitle();
311
+ return html`<h2
312
+ id="${dialog.titleId}"
313
+ data-slot="dialog-title"
314
+ class="${() =>
315
+ cn(
316
+ "text-lg leading-none font-semibold",
317
+ props.srOnly === true ? "sr-only" : "",
318
+ read(props.class),
319
+ )}"
320
+ >${slot(props.children)}</h2>`;
321
+ });
322
+
323
+ export const DialogDescription = component<DialogSectionProps>((props) => {
324
+ const dialog = inject(DialogContext);
325
+ dialog.declareDescription();
326
+ return html`<p
327
+ id="${dialog.descriptionId}"
328
+ data-slot="dialog-description"
329
+ class="${() => cn("text-muted-foreground text-sm", read(props.class))}"
330
+ >${slot(props.children)}</p>`;
331
+ });
332
+
333
+ interface SurfaceIds {
334
+ readonly panelId: string;
335
+ readonly titleId: string | undefined;
336
+ readonly descriptionId: string | undefined;
337
+ close(): void;
338
+ }
339
+
340
+ function renderSurface(
341
+ registered: RegisteredContent,
342
+ ids: SurfaceIds,
343
+ ): TemplateResult {
344
+ const corner = registered.showCloseButton
345
+ ? html`<button
346
+ type="button"
347
+ data-slot="dialog-close"
348
+ class="${closeButtonClasses}"
349
+ @click="${() => ids.close()}"
350
+ >${XIcon({ class: "size-4" })}<span class="sr-only">Close</span></button>`
351
+ : null;
352
+ return html`<div data-slot="dialog-portal" class="${cn("fixed inset-0 z-50", fadeInOut)}">
353
+ <div data-slot="dialog-overlay" class="${dialogBackdropClasses}"></div>
354
+ <div
355
+ data-slot="dialog-content"
356
+ id="${ids.panelId}"
357
+ role="dialog"
358
+ aria-modal="true"
359
+ aria-labelledby="${ids.titleId}"
360
+ aria-describedby="${ids.descriptionId}"
361
+ tabindex="-1"
362
+ class="${cn(dialogPanelClasses, zoomInOut, read(registered.class))}"
363
+ >${registered.body}${corner}</div>
364
+ </div>`;
365
+ }
366
+
157
367
  /** A dialog driven purely by a signal, with no trigger of its own. */
158
368
  export function useDialog(initial = false): {
159
369
  open: () => boolean;