@c9up/nebula 0.2.3 → 0.2.4

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 (68) hide show
  1. package/README.md +7 -6
  2. package/dist/atoms/Avatar.d.ts +14 -0
  3. package/dist/atoms/Avatar.js +46 -8
  4. package/dist/cli/add.d.ts +2 -0
  5. package/dist/cli/add.js +4 -1
  6. package/dist/cli/diff.d.ts +2 -0
  7. package/dist/cli/diff.js +4 -1
  8. package/dist/cli/projectConfig.d.ts +16 -0
  9. package/dist/cli/projectConfig.js +61 -0
  10. package/dist/console/AddCommand.js +6 -1
  11. package/dist/console/DiffCommand.js +6 -1
  12. package/dist/lib/icons.d.ts +8 -0
  13. package/dist/lib/icons.js +8 -0
  14. package/dist/lib/image.js +12 -1
  15. package/dist/molecules/InputOTP.d.ts +12 -0
  16. package/dist/molecules/InputOTP.js +68 -27
  17. package/dist/molecules/index.d.ts +1 -1
  18. package/dist/molecules/index.js +1 -1
  19. package/dist/organisms/Combobox.d.ts +13 -0
  20. package/dist/organisms/Combobox.js +5 -2
  21. package/dist/organisms/Command.js +56 -8
  22. package/dist/organisms/Form.d.ts +15 -0
  23. package/dist/organisms/Form.js +10 -0
  24. package/dist/organisms/Select.d.ts +6 -4
  25. package/dist/organisms/Select.js +1 -0
  26. package/dist/organisms/Sidebar.d.ts +4 -2
  27. package/dist/organisms/Sidebar.js +54 -26
  28. package/dist/organisms/Sonner.d.ts +243 -0
  29. package/dist/organisms/Sonner.js +909 -0
  30. package/dist/organisms/Toaster.d.ts +9 -0
  31. package/dist/organisms/Toaster.js +28 -5
  32. package/dist/organisms/Tooltip.d.ts +4 -0
  33. package/dist/organisms/index.d.ts +6 -0
  34. package/dist/organisms/index.js +6 -0
  35. package/dist/primitives/dismissable.d.ts +11 -4
  36. package/dist/primitives/dismissable.js +8 -6
  37. package/dist/primitives/floating.d.ts +5 -1
  38. package/dist/primitives/floating.js +8 -1
  39. package/dist/primitives/menu.js +2 -1
  40. package/dist/primitives/modalSurface.js +70 -36
  41. package/dist/primitives/presence.js +8 -5
  42. package/nebula.css +2 -2
  43. package/package.json +1 -1
  44. package/registry.json +13 -0
  45. package/src/atoms/Avatar.ts +54 -7
  46. package/src/cli/add.ts +7 -1
  47. package/src/cli/diff.ts +7 -1
  48. package/src/cli/projectConfig.ts +71 -0
  49. package/src/console/AddCommand.ts +6 -1
  50. package/src/console/DiffCommand.ts +6 -1
  51. package/src/lib/icons.ts +28 -0
  52. package/src/lib/image.ts +13 -1
  53. package/src/molecules/InputOTP.ts +81 -27
  54. package/src/molecules/index.ts +3 -0
  55. package/src/organisms/Combobox.ts +18 -2
  56. package/src/organisms/Command.ts +66 -7
  57. package/src/organisms/Form.ts +21 -0
  58. package/src/organisms/Select.ts +7 -4
  59. package/src/organisms/Sidebar.ts +47 -19
  60. package/src/organisms/Sonner.ts +1366 -0
  61. package/src/organisms/Toaster.ts +30 -6
  62. package/src/organisms/Tooltip.ts +4 -0
  63. package/src/organisms/index.ts +23 -0
  64. package/src/primitives/dismissable.ts +16 -8
  65. package/src/primitives/floating.ts +13 -2
  66. package/src/primitives/menu.ts +2 -1
  67. package/src/primitives/modalSurface.ts +77 -40
  68. package/src/primitives/presence.ts +12 -9
@@ -23,7 +23,7 @@
23
23
  * focused, which is what lets a screen reader read each result as the arrows
24
24
  * pass over it while typing continues to work.
25
25
  */
26
- import { component, createContext, html, inject, provide, signal, } from "@c9up/aurora";
26
+ import { component, createContext, html, inject, onMount, onUnmount, provide, signal, } from "@c9up/aurora";
27
27
  import { slot } from "../lib/children.js";
28
28
  import { cn } from "../lib/cn.js";
29
29
  import { SearchIcon } from "../lib/icons.js";
@@ -70,6 +70,33 @@ export const Command = component((props) => {
70
70
  * Nothing needs the value stored before the user moves.
71
71
  */
72
72
  const explicitActive = signal(undefined);
73
+ /**
74
+ * Bumped when items mount or unmount, so the bindings that read the list
75
+ * — the empty state, the groups, the highlight — follow it. `items` itself
76
+ * stays a plain array, filled during setup: a signal written while the
77
+ * items are being built re-entered the effect building them.
78
+ *
79
+ * Coalesced to one bump per task, as cmdk schedules its store updates: a
80
+ * list of a hundred items mounting is one pass over the bindings, not a
81
+ * hundred.
82
+ */
83
+ const revision = signal(0);
84
+ let scheduled = false;
85
+ function changed() {
86
+ if (scheduled)
87
+ return;
88
+ scheduled = true;
89
+ queueMicrotask(() => {
90
+ scheduled = false;
91
+ // The highlighted item left: back to "the first match", as cmdk
92
+ // re-selects the first item when the selected one unmounts.
93
+ const chosen = explicitActive();
94
+ if (chosen !== undefined && !items.some((i) => i.value === chosen)) {
95
+ explicitActive(undefined);
96
+ }
97
+ revision(revision() + 1);
98
+ });
99
+ }
73
100
  function active() {
74
101
  const chosen = explicitActive();
75
102
  if (chosen !== undefined)
@@ -77,15 +104,20 @@ export const Command = component((props) => {
77
104
  return matches()[0]?.value;
78
105
  }
79
106
  function matches() {
107
+ revision();
80
108
  const filter = props.filter ?? defaultFilter;
81
109
  return items.filter((item) => !item.disabled && filter(item, query()));
82
110
  }
83
- function run(value) {
84
- const item = items.find((entry) => entry.value === value);
85
- if (item === undefined || item.disabled)
111
+ function runItem(item) {
112
+ if (item.disabled || !items.includes(item))
86
113
  return;
87
114
  item.run();
88
- props.onSelect?.(value);
115
+ props.onSelect?.(item.value);
116
+ }
117
+ function run(value) {
118
+ const item = items.find((entry) => entry.value === value);
119
+ if (item !== undefined)
120
+ runItem(item);
89
121
  }
90
122
  function move(delta) {
91
123
  const list = matches();
@@ -109,7 +141,19 @@ export const Command = component((props) => {
109
141
  setActive: (value) => explicitActive(value),
110
142
  itemId,
111
143
  register(item) {
112
- items.push({ ...item, id: itemId(item.value) });
144
+ const entry = { ...item, id: itemId(item.value) };
145
+ items.push(entry);
146
+ return {
147
+ select: () => runItem(entry),
148
+ mounted: changed,
149
+ unregister() {
150
+ const index = items.indexOf(entry);
151
+ if (index === -1)
152
+ return;
153
+ items.splice(index, 1);
154
+ changed();
155
+ },
156
+ };
113
157
  },
114
158
  isVisible(value) {
115
159
  return matches().some((item) => item.value === value);
@@ -214,7 +258,9 @@ export const CommandItem = component((props) => {
214
258
  const group = inject(CommandGroupContext);
215
259
  const children = props.children;
216
260
  const id = command.itemId(props.value);
217
- command.register({
261
+ // Registered during setup, so the first pass over the bindings sees it;
262
+ // gone again when it unmounts, as cmdk's item cleanup.
263
+ const registration = command.register({
218
264
  value: props.value,
219
265
  textValue: props.textValue ??
220
266
  (typeof children === "string" ? children : props.value),
@@ -223,6 +269,8 @@ export const CommandItem = component((props) => {
223
269
  groupId: group?.groupId,
224
270
  run: () => props.onSelect?.(),
225
271
  });
272
+ onMount(() => registration.mounted());
273
+ onUnmount(() => registration.unregister());
226
274
  const chosen = () => command.active() === props.value;
227
275
  return html `<div
228
276
  data-slot="command-item"
@@ -234,7 +282,7 @@ export const CommandItem = component((props) => {
234
282
  data-active="${() => (chosen() ? "" : undefined)}"
235
283
  data-disabled="${props.disabled === true ? "" : undefined}"
236
284
  class="${() => cn("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[active]:bg-accent data-[active]:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4", read(props.class))}"
237
- @click="${() => command.run(props.value)}"
285
+ @click="${() => registration.select()}"
238
286
  @pointerenter="${() => command.setActive(props.value)}"
239
287
  >${slot(children)}</div>`;
240
288
  });
@@ -51,6 +51,14 @@ export interface FieldBinding<V> {
51
51
  export declare function bind<T, K extends keyof T & string>(form: AuroraForm<T>, name: K): FieldBinding<T[K]>;
52
52
  export interface FormProps<T> {
53
53
  form: AuroraForm<T>;
54
+ /**
55
+ * How the browser submits it before the page is hydrated, or when a
56
+ * script fails to load. Default `"post"`.
57
+ */
58
+ method?: "post" | "get" | "dialog";
59
+ /** Where that submission goes. Left out, it goes to the current page. */
60
+ action?: string;
61
+ enctype?: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain";
54
62
  children?: Slot;
55
63
  class?: Reactive<string>;
56
64
  }
@@ -61,6 +69,13 @@ export interface FormProps<T> {
61
69
  * styled, appear one at a time, and vanish on scroll — and they would fire
62
70
  * before the controller's validation ever runs, so the user would see two
63
71
  * different error presentations for the same field.
72
+ *
73
+ * NAMED DEVIATION: `method="post"` unless told otherwise. shadcn's `Form`
74
+ * renders no `<form>`, so the app writes its own method; this one owns the
75
+ * element, and the server renders it. Pressed before hydration, a form with
76
+ * no method is a GET, and every named field — a password included — lands in
77
+ * the URL, the history and the access logs. An app with CSRF protection puts
78
+ * its token field among the children, so that early POST is accepted.
64
79
  */
65
80
  export declare function Form<T>(props: FormProps<T>): ReturnType<typeof html>;
66
81
  interface FieldShellProps {
@@ -52,11 +52,21 @@ export function bind(form, name) {
52
52
  * styled, appear one at a time, and vanish on scroll — and they would fire
53
53
  * before the controller's validation ever runs, so the user would see two
54
54
  * different error presentations for the same field.
55
+ *
56
+ * NAMED DEVIATION: `method="post"` unless told otherwise. shadcn's `Form`
57
+ * renders no `<form>`, so the app writes its own method; this one owns the
58
+ * element, and the server renders it. Pressed before hydration, a form with
59
+ * no method is a GET, and every named field — a password included — lands in
60
+ * the URL, the history and the access logs. An app with CSRF protection puts
61
+ * its token field among the children, so that early POST is accepted.
55
62
  */
56
63
  export function Form(props) {
57
64
  return html `<form
58
65
  data-slot="form"
59
66
  novalidate
67
+ method="${props.method ?? "post"}"
68
+ action="${props.action}"
69
+ enctype="${props.enctype}"
60
70
  class="${() => cn("flex flex-col gap-6", read(props.class))}"
61
71
  @submit="${(event) => {
62
72
  // A DOM listener returns nothing, so this promise is nobody's to
@@ -66,10 +66,10 @@ export interface SelectProps {
66
66
  }
67
67
  export declare const Select: (props?: SelectProps | undefined) => TemplateResult;
68
68
  /**
69
- * `id`, `label` and `describedBy` as on `Input`: upstream's trigger takes every
70
- * button prop, and these are the ones that name it — a `FieldLabel` points its
71
- * `for` at the `id`, and a `<label for>` names a `<button>`. Without them the
72
- * combobox's only name was the value it showed.
69
+ * `id`, `label`, `labelledBy` and `describedBy`, as on `Combobox`: upstream's
70
+ * trigger takes every button prop, and these are the ones that name it — a
71
+ * `FieldLabel` points its `for` at the `id`, and a `<label for>` names a
72
+ * `<button>`. Without them the combobox's only name was the value it showed.
73
73
  */
74
74
  export interface SelectTriggerProps {
75
75
  children?: Slot;
@@ -77,6 +77,8 @@ export interface SelectTriggerProps {
77
77
  id?: string;
78
78
  /** Accessible name (`aria-label`), for a select no `<label>` names. */
79
79
  label?: Reactive<string | undefined>;
80
+ /** Id(s) of the element(s) that name it (`aria-labelledby`). */
81
+ labelledBy?: Reactive<string | undefined>;
80
82
  describedBy?: Reactive<string | undefined>;
81
83
  class?: Reactive<string>;
82
84
  }
@@ -341,6 +341,7 @@ export const SelectTrigger = component((props) => {
341
341
  data-slot="select-trigger"
342
342
  id="${select.claimTriggerId(props.id)}"
343
343
  aria-label="${accessor(props.label, undefined)}"
344
+ aria-labelledby="${accessor(props.labelledBy, undefined)}"
344
345
  aria-describedby="${accessor(props.describedBy, undefined)}"
345
346
  role="combobox"
346
347
  aria-haspopup="listbox"
@@ -35,8 +35,10 @@ import { type Reactive } from "../lib/props.js";
35
35
  /**
36
36
  * The cookie-backed open state, shared by every sidebar on the page.
37
37
  *
38
- * A module singleton and not a per-provider signal: the shell renders once and
39
- * the trigger may sit in a header that is not inside the provider's subtree.
38
+ * In the browser, a module singleton and not a per-provider signal: the shell
39
+ * renders once and the trigger may sit in a header that is not inside the
40
+ * provider's subtree. On the server a module is shared by every request, so
41
+ * each call reads the cookie of the request being rendered instead.
40
42
  */
41
43
  export declare function sidebarState(defaultOpen?: boolean): Signal<boolean>;
42
44
  export declare function sidebarCollapsed(): boolean;
@@ -45,24 +45,33 @@ const COOKIE_NAME = "nebula:sidebar";
45
45
  const COOKIE_MAX_AGE_DAYS = 365;
46
46
  const MOBILE_BREAKPOINT = 768;
47
47
  let sharedOpen;
48
+ function openFromCookie(defaultOpen) {
49
+ return cookieState(COOKIE_NAME, defaultOpen, booleanCookie, {
50
+ path: "/",
51
+ maxAge: COOKIE_MAX_AGE_DAYS * 24 * 60 * 60,
52
+ sameSite: "lax",
53
+ });
54
+ }
48
55
  /**
49
56
  * The cookie-backed open state, shared by every sidebar on the page.
50
57
  *
51
- * A module singleton and not a per-provider signal: the shell renders once and
52
- * the trigger may sit in a header that is not inside the provider's subtree.
58
+ * In the browser, a module singleton and not a per-provider signal: the shell
59
+ * renders once and the trigger may sit in a header that is not inside the
60
+ * provider's subtree. On the server a module is shared by every request, so
61
+ * each call reads the cookie of the request being rendered instead.
53
62
  */
54
63
  export function sidebarState(defaultOpen = true) {
55
- sharedOpen ??= cookieState(COOKIE_NAME, defaultOpen, booleanCookie, {
56
- path: "/",
57
- maxAge: COOKIE_MAX_AGE_DAYS * 24 * 60 * 60,
58
- sameSite: "lax",
59
- });
64
+ if (typeof document === "undefined")
65
+ return openFromCookie(defaultOpen);
66
+ sharedOpen ??= openFromCookie(defaultOpen);
60
67
  return sharedOpen;
61
68
  }
62
69
  export function sidebarCollapsed() {
63
70
  return !sidebarState()();
64
71
  }
65
72
  const SidebarContext = createContext("SidebarProvider");
73
+ /** The same provider, for the parts that also work outside one. */
74
+ const NearestSidebar = createContext("SidebarProvider", null);
66
75
  /**
67
76
  * The sidebar's state, from inside it.
68
77
  *
@@ -109,13 +118,14 @@ export const SidebarProvider = component((props) => {
109
118
  const controlled = read(props.open);
110
119
  return controlled === undefined ? open() : controlled;
111
120
  }
112
- provide(SidebarContext, {
121
+ const api = provide(SidebarContext, {
113
122
  open: current,
114
123
  isMobile: () => mobile(),
115
124
  state: () => (current() ? "expanded" : "collapsed"),
116
125
  setOpen,
117
126
  toggleSidebar,
118
127
  });
128
+ provide(NearestSidebar, api);
119
129
  return html `<div
120
130
  data-slot="sidebar-wrapper"
121
131
  class="${() => cn("flex min-h-svh w-full", read(props.class))}"
@@ -168,20 +178,33 @@ export const Sidebar = component((props) => {
168
178
  class="flex h-full w-full flex-col"
169
179
  >${body}</div></nav>`}</div>`;
170
180
  });
171
- export const SidebarTrigger = component((props) => Button({
172
- variant: "ghost",
173
- size: "icon",
174
- label: props.label ?? "Toggle sidebar",
175
- class: () => cn("size-7", read(props.class)),
176
- onClick: () => {
177
- if (props.onToggle !== undefined) {
178
- props.onToggle();
179
- return;
180
- }
181
- sidebarState()(!sidebarState()());
182
- },
183
- children: PanelLeftIcon({ class: "size-4" }),
184
- }));
181
+ /** The provider's toggle, or the page-wide state's outside a provider. */
182
+ function toggleNearest() {
183
+ const sidebar = inject(NearestSidebar);
184
+ if (sidebar !== null)
185
+ return () => sidebar.toggleSidebar();
186
+ return () => {
187
+ const open = sidebarState();
188
+ open(!open());
189
+ };
190
+ }
191
+ export const SidebarTrigger = component((props) => {
192
+ const toggle = toggleNearest();
193
+ return Button({
194
+ variant: "ghost",
195
+ size: "icon",
196
+ label: props.label ?? "Toggle sidebar",
197
+ class: () => cn("size-7", read(props.class)),
198
+ onClick: () => {
199
+ if (props.onToggle !== undefined) {
200
+ props.onToggle();
201
+ return;
202
+ }
203
+ toggle();
204
+ },
205
+ children: PanelLeftIcon({ class: "size-4" }),
206
+ });
207
+ });
185
208
  /**
186
209
  * The hit area along the sidebar's edge that toggles it.
187
210
  *
@@ -190,15 +213,18 @@ export const SidebarTrigger = component((props) => Button({
190
213
  * keyboard has `cmd/ctrl + B` and the trigger, so a third stop on every page
191
214
  * would be noise.
192
215
  */
193
- export const SidebarRail = component((props) => html `<button
216
+ export const SidebarRail = component((props) => {
217
+ const toggle = toggleNearest();
218
+ return html `<button
194
219
  type="button"
195
220
  data-slot="sidebar-rail"
196
221
  aria-label="${props.label ?? "Toggle sidebar"}"
197
222
  tabindex="-1"
198
223
  title="${props.label ?? "Toggle sidebar"}"
199
224
  class="${() => cn("hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex", read(props.class))}"
200
- @click="${() => sidebarState()(!sidebarState()())}"
201
- ></button>`);
225
+ @click="${toggle}"
226
+ ></button>`;
227
+ });
202
228
  /** The page beside the sidebar. */
203
229
  export const SidebarInset = component((props) => html `<main
204
230
  data-slot="sidebar-inset"
@@ -252,6 +278,8 @@ export const sidebarMenuButtonVariants = cva("peer/menu-button ring-sidebar-ring
252
278
  defaultVariants: { variant: "default", size: "default" },
253
279
  });
254
280
  export const SidebarMenuButton = component((props) => {
281
+ const sidebar = inject(NearestSidebar);
282
+ const collapsed = () => sidebar === null ? sidebarCollapsed() : sidebar.state() === "collapsed";
255
283
  const merged = () => cn(sidebarMenuButtonVariants({
256
284
  variant: props.variant,
257
285
  size: props.size,
@@ -277,7 +305,7 @@ export const SidebarMenuButton = component((props) => {
277
305
  // Wrapped once, not toggled: swapping the wrapper on collapse would remount
278
306
  // the entry and lose focus mid-keyboard-navigation. The tooltip decides for
279
307
  // itself whether to open, which is the cheaper half to make conditional.
280
- return html `${() => sidebarCollapsed()
308
+ return html `${() => collapsed()
281
309
  ? Tooltip({
282
310
  children: () => html `${TooltipTrigger({
283
311
  children: () => entry,
@@ -0,0 +1,243 @@
1
+ /**
2
+ * Sonner — toasts, the way shadcn ships them now.
3
+ *
4
+ * shadcn deprecated its own `toast` component in favour of `sonner`, a thin
5
+ * wrapper over Emil Kowalski's library of the same name. This is that pair in
6
+ * one file, ported to aurora without the library: a `Toaster` region mounted
7
+ * once near the root, and a `toast` function callable from anywhere in the
8
+ * browser — a route handler's error branch included — with no reference to
9
+ * the region. On the server a toast is not kept: the region renders empty
10
+ * there, and page code that raises one runs again in the browser.
11
+ *
12
+ * Toaster({ richColors: true, closeButton: true })
13
+ *
14
+ * toast('Event created', { description: 'Sunday, 9:00' })
15
+ * toast.error('Could not save', { action: { label: 'Retry', onClick: save } })
16
+ * toast.promise(save(form), {
17
+ * loading: 'Saving…',
18
+ * success: (saved) => `Saved ${saved.name}`,
19
+ * error: 'Could not save',
20
+ * })
21
+ *
22
+ * The API is sonner's, read from its published source: the same `toast`
23
+ * methods, the same options, the same Toaster props, the same defaults (four
24
+ * seconds on screen, three toasts visible, a 14px gap, 356px wide, `Alt+T` to
25
+ * reach the region). The look is shadcn's: the surface takes the popover
26
+ * colours, and the icons are the lucide set shadcn hands to sonner. The stack
27
+ * is sonner's too — toasts pile up behind the newest one, scaled down, and fan
28
+ * out while the pointer is over them, which also pauses their timers.
29
+ *
30
+ * NAMED DEVIATIONS, all deliberate:
31
+ *
32
+ * - **Announcements go through two hidden live regions**, mounted empty with
33
+ * the region: `polite` for every toast, `assertive` for an error. sonner
34
+ * makes its whole list one polite region, so an error waits its turn behind
35
+ * whatever is being read, and a list inserted with content in it is not
36
+ * announced by most screen readers at all.
37
+ * - **The layout is computed, not styled.** sonner drives its stack from a
38
+ * stylesheet it injects, reading custom properties it sets per toast. Here
39
+ * the same rules produce an inline `transform`, `opacity` and `height`, so
40
+ * the stack works under every adapter — nothing depends on a stylesheet that
41
+ * might not be there, or on compound selectors an engine might not emit.
42
+ * - **`class`, `descriptionClass`**, where React says `className`. Every
43
+ * nebula component spells it that way.
44
+ * - **`toast.promise` returns `{ id, unwrap }`**, not the id with `unwrap`
45
+ * grafted on: a number or a string cannot carry a method without being
46
+ * boxed into something that is no longer equal to the id.
47
+ * - **No swipe to dismiss, no `getHistory`, no focus hand-back on blur.**
48
+ * The close button, the timer and `Alt+T` remain; an app that needs a swipe
49
+ * gesture has the `data-*` attributes sonner's own CSS reads.
50
+ * - `action` and `cancel` take `{ label, onClick }` only, not an arbitrary
51
+ * element; `toast.custom` is the way to render something of your own.
52
+ */
53
+ import type { Child, Slot } from "../lib/children.js";
54
+ import { type Reactive } from "../lib/props.js";
55
+ /** `undefined` is a plain `toast()`: no icon, no rich colour. */
56
+ export type ToastType = "default" | "success" | "info" | "warning" | "error" | "loading";
57
+ export type Position = "top-left" | "top-right" | "bottom-left" | "bottom-right" | "top-center" | "bottom-center";
58
+ /** A number when `toast` minted it, the caller's own when one was given. */
59
+ export type ToastId = number | string;
60
+ export interface Action {
61
+ label: Child;
62
+ onClick: (event: MouseEvent) => void;
63
+ }
64
+ /** Extra classes per part, merged after nebula's own. */
65
+ export interface ToastClassnames {
66
+ toast?: string;
67
+ title?: string;
68
+ description?: string;
69
+ loader?: string;
70
+ closeButton?: string;
71
+ cancelButton?: string;
72
+ actionButton?: string;
73
+ success?: string;
74
+ error?: string;
75
+ info?: string;
76
+ warning?: string;
77
+ loading?: string;
78
+ default?: string;
79
+ content?: string;
80
+ icon?: string;
81
+ }
82
+ /** Replaces shadcn's icons. `null` for a type shows none. */
83
+ export interface ToastIcons {
84
+ success?: Child;
85
+ info?: Child;
86
+ warning?: Child;
87
+ error?: Child;
88
+ loading?: Child;
89
+ close?: Child;
90
+ }
91
+ /** What every `toast` call takes after its message. */
92
+ export interface ExternalToast {
93
+ /**
94
+ * A stable id. A toast raised under an id already on screen UPDATES it —
95
+ * which is how a loading toast becomes its outcome, and how "you are
96
+ * offline", raised on every failed request, stays one toast.
97
+ */
98
+ id?: ToastId;
99
+ /** Shown only by the `Toaster` whose `id` is this. */
100
+ toasterId?: string;
101
+ description?: Slot;
102
+ /** Replaces the type's icon; `null` shows none. */
103
+ icon?: Child;
104
+ richColors?: boolean;
105
+ invert?: boolean;
106
+ closeButton?: boolean;
107
+ /** `false` keeps the close button and the timer from removing it. */
108
+ dismissible?: boolean;
109
+ /** Milliseconds on screen. `Infinity` keeps it until dismissed. */
110
+ duration?: number;
111
+ action?: Action;
112
+ cancel?: Action;
113
+ /** Called when it is dismissed: the close button, `cancel`, `toast.dismiss`. */
114
+ onDismiss?: (toast: ToastT) => void;
115
+ /** Called when its time runs out. */
116
+ onAutoClose?: (toast: ToastT) => void;
117
+ class?: string;
118
+ descriptionClass?: string;
119
+ classNames?: ToastClassnames;
120
+ /** Drops nebula's look, keeping only the layout. */
121
+ unstyled?: boolean;
122
+ /** A corner of its own, other than the Toaster's. */
123
+ position?: Position;
124
+ testId?: string;
125
+ }
126
+ /** A toast as the region holds it. */
127
+ export interface ToastT extends ExternalToast {
128
+ readonly id: ToastId;
129
+ title?: Slot;
130
+ type?: ToastType;
131
+ /** What `toast.custom` rendered, in place of the title and the styling. */
132
+ custom?: Child;
133
+ /** Raised by `toast.promise`. */
134
+ promise?: boolean;
135
+ }
136
+ /** A stage of `toast.promise` that says more than its message. */
137
+ export interface PromiseExtendedResult extends ExternalToast {
138
+ message: Child;
139
+ }
140
+ type StageValue = Child | PromiseExtendedResult;
141
+ /** A stage of `toast.promise`: its message, or a function of the outcome. */
142
+ export type PromiseResult<Value> = StageValue | ((value: Value) => StageValue | Promise<StageValue>);
143
+ export interface PromiseData<Value> extends Omit<ExternalToast, "description"> {
144
+ loading?: Child;
145
+ success?: PromiseResult<Value>;
146
+ error?: PromiseResult<unknown>;
147
+ description?: Child | ((value: unknown) => Child | Promise<Child>);
148
+ finally?: () => void | Promise<void>;
149
+ }
150
+ declare function dismiss(id?: ToastId): ToastId | undefined;
151
+ declare function promise<Value>(work: Promise<Value> | (() => Promise<Value>), data?: PromiseData<Value>): {
152
+ id: ToastId | undefined;
153
+ unwrap: () => Promise<Value>;
154
+ };
155
+ /**
156
+ * Raise a toast. Returns its id, which `toast.dismiss` takes.
157
+ *
158
+ * Callable from anywhere — no component, no context, no handle.
159
+ */
160
+ export declare const toast: ((message: Slot, data?: ExternalToast) => ToastId) & {
161
+ /** A plain toast; on an existing id, resets its type. */
162
+ message: (message: Slot, data?: ExternalToast) => ToastId;
163
+ success: (message: Slot, data?: ExternalToast) => ToastId;
164
+ info: (message: Slot, data?: ExternalToast) => ToastId;
165
+ warning: (message: Slot, data?: ExternalToast) => ToastId;
166
+ error: (message: Slot, data?: ExternalToast) => ToastId;
167
+ /** Stays until it is updated or dismissed. */
168
+ loading: (message: Slot, data?: ExternalToast) => ToastId;
169
+ /** Render your own content, unstyled; `render` gets the toast's id. */
170
+ custom(render: (id: ToastId) => Child, data?: ExternalToast): ToastId;
171
+ /**
172
+ * One toast for the whole life of an async call: loading, then its outcome.
173
+ *
174
+ * A rejection is reported, not swallowed: `unwrap()` hands it back to the
175
+ * caller's own error path.
176
+ */
177
+ promise: typeof promise;
178
+ /** Dismiss one toast, or every toast when no id is given. */
179
+ dismiss: typeof dismiss;
180
+ /** The toasts on screen, newest first. */
181
+ getToasts(): ToastT[];
182
+ };
183
+ export type Offset = {
184
+ top?: string | number;
185
+ right?: string | number;
186
+ bottom?: string | number;
187
+ left?: string | number;
188
+ } | string | number;
189
+ /** Defaults for every toast this region shows. */
190
+ export interface ToastOptions {
191
+ class?: string;
192
+ closeButton?: boolean;
193
+ descriptionClass?: string;
194
+ duration?: number;
195
+ unstyled?: boolean;
196
+ classNames?: ToastClassnames;
197
+ /** The close cross's accessible name. Default `"Close toast"`. */
198
+ closeButtonAriaLabel?: string;
199
+ }
200
+ export interface ToasterProps {
201
+ /** Shows only the toasts raised with this `toasterId`. */
202
+ id?: string;
203
+ invert?: boolean;
204
+ /**
205
+ * `"system"` follows the app's `dark` variant, which is what shadcn hands
206
+ * sonner from `next-themes`. Default `"system"`.
207
+ */
208
+ theme?: "light" | "dark" | "system";
209
+ /** Default `"bottom-right"`. */
210
+ position?: Position;
211
+ /** `KeyboardEvent` keys and codes that reach the region. Default Alt+T. */
212
+ hotkey?: string[];
213
+ richColors?: boolean;
214
+ /** Keep the stack fanned out instead of piled up. */
215
+ expand?: boolean;
216
+ /** Milliseconds on screen. Default 4000. */
217
+ duration?: number;
218
+ /** Space between fanned-out toasts. Default 14. */
219
+ gap?: number;
220
+ /** How many show at once. Default 3. */
221
+ visibleToasts?: number;
222
+ closeButton?: boolean;
223
+ toastOptions?: ToastOptions;
224
+ class?: Reactive<string>;
225
+ /** From the viewport's edges. Default `24px`. */
226
+ offset?: Offset;
227
+ /** The same, at 600px wide and under. Default `16px`. */
228
+ mobileOffset?: Offset;
229
+ dir?: "rtl" | "ltr" | "auto";
230
+ icons?: ToastIcons;
231
+ /** Replaces the region's whole accessible name. */
232
+ customAriaLabel?: string;
233
+ /** The region's name, before the hotkey. Default `"Notifications"`. */
234
+ containerAriaLabel?: string;
235
+ }
236
+ /**
237
+ * Mount once, near the root of the app.
238
+ *
239
+ * `data-nebula-live` exempts it from the `aria-hidden` sweep a modal performs
240
+ * over its siblings: a toast raised while a dialog is open is still announced.
241
+ */
242
+ export declare const Toaster: (props?: ToasterProps | undefined) => import("@c9up/aurora").TemplateResult;
243
+ export {};