@c9up/nebula 0.2.2 → 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 (116) hide show
  1. package/README.md +8 -7
  2. package/dist/atoms/Avatar.d.ts +14 -0
  3. package/dist/atoms/Avatar.js +46 -8
  4. package/dist/atoms/Checkbox.d.ts +1 -1
  5. package/dist/atoms/Checkbox.js +1 -1
  6. package/dist/atoms/Input.d.ts +5 -0
  7. package/dist/atoms/Input.js +1 -0
  8. package/dist/cli/add.d.ts +2 -0
  9. package/dist/cli/add.js +4 -1
  10. package/dist/cli/diff.d.ts +2 -0
  11. package/dist/cli/diff.js +4 -1
  12. package/dist/cli/projectConfig.d.ts +16 -0
  13. package/dist/cli/projectConfig.js +61 -0
  14. package/dist/console/AddCommand.js +6 -1
  15. package/dist/console/DiffCommand.js +6 -1
  16. package/dist/lib/children.d.ts +13 -8
  17. package/dist/lib/children.js +5 -0
  18. package/dist/lib/icons.d.ts +8 -0
  19. package/dist/lib/icons.js +8 -0
  20. package/dist/lib/image.js +12 -1
  21. package/dist/molecules/Breadcrumb.d.ts +11 -2
  22. package/dist/molecules/Breadcrumb.js +2 -2
  23. package/dist/molecules/InputOTP.d.ts +14 -0
  24. package/dist/molecules/InputOTP.js +71 -28
  25. package/dist/molecules/Pagination.d.ts +34 -2
  26. package/dist/molecules/Pagination.js +15 -6
  27. package/dist/molecules/PieceMap.d.ts +72 -0
  28. package/dist/molecules/PieceMap.js +78 -0
  29. package/dist/molecules/Resizable.d.ts +2 -0
  30. package/dist/molecules/Resizable.js +1 -1
  31. package/dist/molecules/index.d.ts +4 -3
  32. package/dist/molecules/index.js +2 -1
  33. package/dist/organisms/Calendar.d.ts +13 -0
  34. package/dist/organisms/Calendar.js +2 -2
  35. package/dist/organisms/Carousel.d.ts +8 -0
  36. package/dist/organisms/Carousel.js +8 -5
  37. package/dist/organisms/Combobox.d.ts +13 -0
  38. package/dist/organisms/Combobox.js +5 -2
  39. package/dist/organisms/Command.js +56 -8
  40. package/dist/organisms/DataTable.d.ts +23 -1
  41. package/dist/organisms/DataTable.js +57 -27
  42. package/dist/organisms/DatePicker.d.ts +7 -0
  43. package/dist/organisms/DatePicker.js +2 -1
  44. package/dist/organisms/DateRangePicker.d.ts +2 -0
  45. package/dist/organisms/DateRangePicker.js +2 -1
  46. package/dist/organisms/Dialog.d.ts +13 -3
  47. package/dist/organisms/Dialog.js +12 -5
  48. package/dist/organisms/Form.d.ts +15 -0
  49. package/dist/organisms/Form.js +10 -0
  50. package/dist/organisms/Questionnaire.d.ts +4 -0
  51. package/dist/organisms/Questionnaire.js +5 -2
  52. package/dist/organisms/Select.d.ts +25 -4
  53. package/dist/organisms/Select.js +116 -15
  54. package/dist/organisms/Sheet.d.ts +2 -0
  55. package/dist/organisms/Sheet.js +2 -1
  56. package/dist/organisms/Sidebar.d.ts +10 -2
  57. package/dist/organisms/Sidebar.js +62 -29
  58. package/dist/organisms/Sonner.d.ts +243 -0
  59. package/dist/organisms/Sonner.js +909 -0
  60. package/dist/organisms/Toaster.d.ts +11 -0
  61. package/dist/organisms/Toaster.js +34 -9
  62. package/dist/organisms/Tooltip.d.ts +4 -0
  63. package/dist/organisms/index.d.ts +8 -2
  64. package/dist/organisms/index.js +7 -1
  65. package/dist/primitives/dismissable.d.ts +11 -4
  66. package/dist/primitives/dismissable.js +8 -6
  67. package/dist/primitives/floating.d.ts +5 -1
  68. package/dist/primitives/floating.js +32 -2
  69. package/dist/primitives/menu.js +2 -1
  70. package/dist/primitives/modalSurface.js +70 -36
  71. package/dist/primitives/presence.js +8 -5
  72. package/dist/templates/SettingsLayout.d.ts +2 -0
  73. package/dist/templates/SettingsLayout.js +1 -1
  74. package/nebula.css +2 -2
  75. package/package.json +3 -3
  76. package/registry.json +26 -0
  77. package/src/atoms/Avatar.ts +54 -7
  78. package/src/atoms/Checkbox.ts +1 -1
  79. package/src/atoms/Input.ts +6 -0
  80. package/src/cli/add.ts +7 -1
  81. package/src/cli/diff.ts +7 -1
  82. package/src/cli/projectConfig.ts +71 -0
  83. package/src/console/AddCommand.ts +6 -1
  84. package/src/console/DiffCommand.ts +6 -1
  85. package/src/lib/children.ts +15 -7
  86. package/src/lib/icons.ts +28 -0
  87. package/src/lib/image.ts +13 -1
  88. package/src/molecules/Breadcrumb.ts +15 -4
  89. package/src/molecules/InputOTP.ts +88 -28
  90. package/src/molecules/Pagination.ts +50 -8
  91. package/src/molecules/PieceMap.ts +136 -0
  92. package/src/molecules/Resizable.ts +3 -1
  93. package/src/molecules/index.ts +17 -0
  94. package/src/organisms/Calendar.ts +16 -2
  95. package/src/organisms/Carousel.ts +17 -5
  96. package/src/organisms/Combobox.ts +18 -2
  97. package/src/organisms/Command.ts +66 -7
  98. package/src/organisms/DataTable.ts +95 -30
  99. package/src/organisms/DatePicker.ts +10 -2
  100. package/src/organisms/DateRangePicker.ts +4 -2
  101. package/src/organisms/Dialog.ts +17 -5
  102. package/src/organisms/Form.ts +21 -0
  103. package/src/organisms/Questionnaire.ts +10 -2
  104. package/src/organisms/Select.ts +140 -16
  105. package/src/organisms/Sheet.ts +5 -1
  106. package/src/organisms/Sidebar.ts +62 -23
  107. package/src/organisms/Sonner.ts +1366 -0
  108. package/src/organisms/Toaster.ts +38 -10
  109. package/src/organisms/Tooltip.ts +4 -0
  110. package/src/organisms/index.ts +30 -1
  111. package/src/primitives/dismissable.ts +16 -8
  112. package/src/primitives/floating.ts +40 -3
  113. package/src/primitives/menu.ts +2 -1
  114. package/src/primitives/modalSurface.ts +77 -40
  115. package/src/primitives/presence.ts +12 -9
  116. package/src/templates/SettingsLayout.ts +3 -1
@@ -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
  });
@@ -21,6 +21,8 @@
21
21
  */
22
22
  import { type TemplateResult } from "@c9up/aurora";
23
23
  import type { Child } from "../lib/children.js";
24
+ import { type Reactive } from "../lib/props.js";
25
+ import { type PaginationLabels } from "../molecules/Pagination.js";
24
26
  export interface Column<Row> {
25
27
  key: string;
26
28
  header: Child;
@@ -33,16 +35,36 @@ export interface Column<Row> {
33
35
  }
34
36
  export interface DataTableProps<Row> {
35
37
  columns: readonly Column<Row>[];
36
- rows: readonly Row[];
38
+ /**
39
+ * The rows, or an accessor for rows that change. An accessor must return the
40
+ * same array until the data changes — a new one per read counts as new data
41
+ * on every read, as it does for TanStack's `data`.
42
+ */
43
+ rows: Reactive<readonly Row[]>;
37
44
  /** Stable identity per row — used for selection and as the render key. */
38
45
  rowKey: (row: Row) => string;
39
46
  /** Rows per page. Omit to show everything. */
40
47
  pageSize?: number;
48
+ /**
49
+ * Go back to the first page when the rows change. Default `true`, as
50
+ * TanStack's `autoResetPageIndex`: the page was chosen in data that is
51
+ * gone. Turn it off for rows refreshed in place, such as a polled list.
52
+ * Sorting and the filter always survive a change.
53
+ */
54
+ autoResetPage?: boolean;
41
55
  /** Show a filter box. Provide `filterMatch` to say what it searches. */
42
56
  filterPlaceholder?: string;
57
+ /** The filter box's accessible name. Defaults to the placeholder. */
58
+ filterLabel?: string;
43
59
  filterMatch?: (row: Row, query: string) => boolean;
44
60
  /** Add a checkbox column. */
45
61
  selectable?: boolean;
62
+ /** The header checkbox's accessible name. Default `"Select all rows on this page"`. */
63
+ selectAllLabel?: string;
64
+ /** A row checkbox's accessible name. Default `"Select row <key>"`. */
65
+ selectRowLabel?: (row: Row) => string;
66
+ /** The pager's words — see `PaginationLabels`. */
67
+ paginationLabels?: Partial<PaginationLabels>;
46
68
  onSelectionChange?: (keys: readonly string[]) => void;
47
69
  emptyMessage?: Child;
48
70
  class?: string;
@@ -19,18 +19,23 @@
19
19
  * The little chevron says which column is sorted to anyone who can see it; the
20
20
  * attribute is what says it to everyone else.
21
21
  */
22
- import { html, signal } from "@c9up/aurora";
22
+ import { each, html, memo, signal, } from "@c9up/aurora";
23
23
  import { Checkbox } from "../atoms/Checkbox.js";
24
24
  import { Input } from "../atoms/Input.js";
25
25
  import { cn } from "../lib/cn.js";
26
26
  import { ChevronDownIcon, ChevronsUpDownIcon, ChevronUpIcon, } from "../lib/icons.js";
27
- import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, pageWindow, } from "../molecules/Pagination.js";
27
+ import { read } from "../lib/props.js";
28
+ import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, pageWindow, paginationLabels, } from "../molecules/Pagination.js";
28
29
  import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "../molecules/Table.js";
29
30
  export function DataTable(props) {
30
31
  const sortKey = signal(undefined);
31
32
  const sortDirection = signal("asc");
32
33
  const query = signal("");
33
- const page = signal(1);
34
+ /**
35
+ * The page, and the rows it was chosen in. Derived rather than reset by an
36
+ * effect: when the rows are no longer those, the page reads as the first.
37
+ */
38
+ const page = signal({ number: 1, of: read(props.rows) });
34
39
  const selected = signal([]);
35
40
  function readCell(row, column) {
36
41
  if (column.cell !== undefined)
@@ -44,10 +49,20 @@ export function DataTable(props) {
44
49
  return typeof value === "number" ? value : String(value ?? "");
45
50
  }
46
51
  function filtered() {
52
+ const rows = read(props.rows);
47
53
  const needle = query().trim().toLowerCase();
48
54
  if (needle === "" || props.filterMatch === undefined)
49
- return props.rows;
50
- return props.rows.filter((row) => props.filterMatch?.(row, needle) === true);
55
+ return rows;
56
+ return rows.filter((row) => props.filterMatch?.(row, needle) === true);
57
+ }
58
+ function pageNumber() {
59
+ const { number, of } = page();
60
+ if (props.autoResetPage !== false && of !== read(props.rows))
61
+ return 1;
62
+ return number;
63
+ }
64
+ function goToPage(number) {
65
+ page({ number, of: read(props.rows) });
51
66
  }
52
67
  function sorted() {
53
68
  const key = sortKey();
@@ -79,10 +94,12 @@ export function DataTable(props) {
79
94
  return rows;
80
95
  // Clamp: filtering down to fewer pages while on the last one would
81
96
  // otherwise show an empty table with no way back.
82
- const current = Math.min(page(), pageCount());
97
+ const current = Math.min(pageNumber(), pageCount());
83
98
  const from = (current - 1) * props.pageSize;
84
99
  return rows.slice(from, from + props.pageSize);
85
100
  }
101
+ /** Whether the body shows the empty row — read apart, so the list survives. */
102
+ const isEmpty = memo(() => visible().length === 0);
86
103
  function toggleSort(column) {
87
104
  if (column.sortable === false)
88
105
  return;
@@ -145,10 +162,11 @@ export function DataTable(props) {
145
162
  : Input({
146
163
  type: "search",
147
164
  placeholder: props.filterPlaceholder ?? "Filter…",
165
+ label: props.filterLabel ?? props.filterPlaceholder ?? "Filter…",
148
166
  class: "max-w-sm",
149
167
  onInput: (value) => {
150
168
  query(value);
151
- page(1);
169
+ goToPage(1);
152
170
  },
153
171
  })}
154
172
  ${Table({
@@ -160,7 +178,7 @@ export function DataTable(props) {
160
178
  ? TableHead({
161
179
  class: "w-10",
162
180
  children: Checkbox({
163
- label: "Select all rows on this page",
181
+ label: props.selectAllLabel ?? "Select all rows on this page",
164
182
  checked: () => {
165
183
  const keys = visible().map(props.rowKey);
166
184
  return (keys.length > 0 &&
@@ -189,19 +207,18 @@ export function DataTable(props) {
189
207
  }),
190
208
  }),
191
209
  TableBody({
192
- children: () => {
193
- const rows = visible();
194
- if (rows.length === 0) {
195
- return TableRow({
196
- children: TableCell({
197
- colspan: columnCount,
198
- class: "h-24 text-center",
199
- children: props.emptyMessage ?? "No results.",
200
- }),
201
- });
202
- }
203
- return rows.map((row) => renderRow(row));
204
- },
210
+ // Rows by key: a re-read, a sort or a page change keeps the rows
211
+ // that stay, with their open menus and focus. The body itself only
212
+ // switches between the list and the empty row.
213
+ children: () => isEmpty()
214
+ ? TableRow({
215
+ children: TableCell({
216
+ colspan: columnCount,
217
+ class: "h-24 text-center",
218
+ children: props.emptyMessage ?? "No results.",
219
+ }),
220
+ })
221
+ : each(visible, props.rowKey, renderRow),
205
222
  }),
206
223
  ],
207
224
  })}
@@ -215,22 +232,26 @@ export function DataTable(props) {
215
232
  * current one and the gaps between — and the parts render that list.
216
233
  */
217
234
  function renderPagination() {
218
- const current = () => Math.min(page(), pageCount());
235
+ const current = () => Math.min(pageNumber(), pageCount());
219
236
  const go = (target) => () => {
220
- page(Math.min(Math.max(target, 1), pageCount()));
237
+ goToPage(Math.min(Math.max(target, 1), pageCount()));
221
238
  };
239
+ const word = (key) => props.paginationLabels?.[key] ?? paginationLabels[key];
222
240
  return Pagination({
241
+ "aria-label": word("navigation"),
223
242
  children: () => PaginationContent({
224
243
  children: [
225
244
  PaginationItem({
226
245
  children: PaginationPrevious({
246
+ "aria-label": word("previousPage"),
247
+ children: word("previous"),
227
248
  disabled: () => current() <= 1,
228
249
  onSelect: go(current() - 1),
229
250
  }),
230
251
  }),
231
252
  ...pageWindow(current(), pageCount()).map((entry) => PaginationItem({
232
253
  children: entry === null
233
- ? PaginationEllipsis({})
254
+ ? PaginationEllipsis({ label: word("morePages") })
234
255
  : PaginationLink({
235
256
  children: String(entry),
236
257
  isActive: () => current() === entry,
@@ -239,6 +260,8 @@ export function DataTable(props) {
239
260
  })),
240
261
  PaginationItem({
241
262
  children: PaginationNext({
263
+ "aria-label": word("nextPage"),
264
+ children: word("next"),
242
265
  disabled: () => current() >= pageCount(),
243
266
  onSelect: go(current() + 1),
244
267
  }),
@@ -247,21 +270,28 @@ export function DataTable(props) {
247
270
  }),
248
271
  });
249
272
  }
273
+ /**
274
+ * One row, built once for its key. The cells read the row through its
275
+ * accessor, so a row whose data changed redraws its cells and nothing else.
276
+ */
250
277
  function renderRow(row) {
251
- const key = props.rowKey(row);
278
+ const key = props.rowKey(row());
252
279
  return TableRow({
253
280
  selected: () => selected().includes(key),
254
281
  children: [
255
282
  props.selectable === true
256
283
  ? TableCell({
257
284
  children: Checkbox({
258
- label: `Select row ${key}`,
285
+ label: () => props.selectRowLabel?.(row()) ?? `Select row ${key}`,
259
286
  checked: () => selected().includes(key),
260
287
  onCheckedChange: () => toggleRow(key),
261
288
  }),
262
289
  })
263
290
  : null,
264
- ...props.columns.map((column) => TableCell({ class: column.class, children: readCell(row, column) })),
291
+ ...props.columns.map((column) => TableCell({
292
+ class: column.class,
293
+ children: () => readCell(row(), column),
294
+ })),
265
295
  ],
266
296
  });
267
297
  }
@@ -16,6 +16,12 @@
16
16
  * wants — never the localised string on the button.
17
17
  */
18
18
  import { type Reactive } from "../lib/props.js";
19
+ import { type CalendarLabels } from "./Calendar.js";
20
+ /** The calendar's words, plus the popup's accessible name. */
21
+ export interface DatePickerLabels extends CalendarLabels {
22
+ /** Default `"Choose a date"`, or `"Choose a date range"`. */
23
+ dialog: string;
24
+ }
19
25
  export interface DatePickerProps {
20
26
  name?: string;
21
27
  value?: Reactive<Date | undefined>;
@@ -26,6 +32,7 @@ export interface DatePickerProps {
26
32
  disabled?: Reactive<boolean>;
27
33
  invalid?: Reactive<boolean>;
28
34
  locale?: string;
35
+ labels?: Partial<DatePickerLabels>;
29
36
  class?: Reactive<string>;
30
37
  onValueChange?: (date: Date) => void;
31
38
  }
@@ -65,7 +65,7 @@ export const DatePicker = component((props) => {
65
65
  data-slot="date-picker-content"
66
66
  id="${contentId}"
67
67
  role="dialog"
68
- aria-label="Choose a date"
68
+ aria-label="${props.labels?.dialog ?? "Choose a date"}"
69
69
  class="${cn("bg-popover text-popover-foreground z-50 rounded-md border p-0 shadow-md outline-none", zoomInOut)}"
70
70
  >
71
71
  ${Calendar({
@@ -74,6 +74,7 @@ export const DatePicker = component((props) => {
74
74
  min: props.min,
75
75
  max: props.max,
76
76
  locale: props.locale,
77
+ labels: props.labels,
77
78
  onValueChange: choose,
78
79
  })}
79
80
  </div>`,
@@ -16,6 +16,7 @@
16
16
  */
17
17
  import { type Reactive } from "../lib/props.js";
18
18
  import { type DateRange } from "./Calendar.js";
19
+ import { type DatePickerLabels } from "./DatePicker.js";
19
20
  export interface DateRangePickerProps {
20
21
  /** Base name for the hidden inputs — `"stay"` posts `stay_from` / `stay_to`. */
21
22
  name?: string;
@@ -27,6 +28,7 @@ export interface DateRangePickerProps {
27
28
  disabled?: Reactive<boolean>;
28
29
  invalid?: Reactive<boolean>;
29
30
  locale?: string;
31
+ labels?: Partial<DatePickerLabels>;
30
32
  class?: Reactive<string>;
31
33
  /** Fires on both clicks — `to` is absent after the first. */
32
34
  onValueChange?: (range: DateRange) => void;
@@ -70,7 +70,7 @@ export const DateRangePicker = component((props) => {
70
70
  data-slot="date-range-picker-content"
71
71
  id="${contentId}"
72
72
  role="dialog"
73
- aria-label="Choose a date range"
73
+ aria-label="${props.labels?.dialog ?? "Choose a date range"}"
74
74
  class="${cn("bg-popover text-popover-foreground z-50 rounded-md border p-0 shadow-md outline-none", zoomInOut)}"
75
75
  >
76
76
  ${Calendar({
@@ -80,6 +80,7 @@ export const DateRangePicker = component((props) => {
80
80
  min: props.min,
81
81
  max: props.max,
82
82
  locale: props.locale,
83
+ labels: props.labels,
83
84
  onRangeChange: pick,
84
85
  })}
85
86
  </div>`,
@@ -7,11 +7,11 @@
7
7
  * Dialog({ children: () => html`
8
8
  * ${DialogTrigger({ children: "Edit" })}
9
9
  * ${DialogContent({ children: () => html`
10
- * ${DialogHeader({ children: () => html`
10
+ * ${DialogHeader({ children: html`
11
11
  * ${DialogTitle({ children: "Edit profile" })}
12
12
  * ${DialogDescription({ children: "Change it." })}
13
13
  * ` })}
14
- * ${DialogFooter({ children: () => Button({ children: "Save" }) })}
14
+ * ${DialogFooter({ children: Button({ children: "Save" }) })}
15
15
  * ` })}
16
16
  * ` })
17
17
  *
@@ -21,6 +21,11 @@
21
21
  * with the title's id and a panel rendered first would have had nothing to
22
22
  * point at.
23
23
  *
24
+ * Hence `DialogHeader` gets a VALUE: it takes a `Slot`, which the renderer calls
25
+ * when the panel renders, and a `DialogTitle` built in there registers after
26
+ * the panel has looked for one — it renders, and the panel stays unnamed (see
27
+ * `Parts`). Content that changes goes inside the title, not around it.
28
+ *
24
29
  * The `panel` callback matters more than it looks. The overlay's root spans
25
30
  * the viewport so the backdrop can, which means containment has to be answered
26
31
  * against the panel — check the root and every click on the page counts as
@@ -29,7 +34,8 @@
29
34
  * `aria-labelledby` points at the title and `aria-describedby` at the
30
35
  * description, so a screen reader announces what the dialog is for on open. A
31
36
  * dialog with neither announces only "dialog", which is why a missing
32
- * `DialogTitle` is warned about — as upstream warns — rather than tolerated.
37
+ * `DialogTitle` is warned about rather than tolerated — as Radix did through
38
+ * 1.1; 1.3 counts its titles and no longer warns.
33
39
  */
34
40
  import { type TemplateResult } from "@c9up/aurora";
35
41
  import type { Parts, Slot } from "../lib/children.js";
@@ -83,6 +89,8 @@ export interface DialogContentProps {
83
89
  children?: Parts;
84
90
  /** The corner cross. */
85
91
  showCloseButton?: boolean;
92
+ /** The cross's accessible name. Default `"Close"`. */
93
+ closeLabel?: string;
86
94
  /** A click outside closes. `false` for a decision that must be made. */
87
95
  dismissOnOutside?: boolean;
88
96
  /** Escape closes. `false` for the same reason. */
@@ -105,6 +113,8 @@ export declare const DialogHeader: (props?: DialogSectionProps | undefined) => T
105
113
  export interface DialogFooterProps extends DialogSectionProps {
106
114
  /** Append a "Close" button after the children, as upstream can. */
107
115
  showCloseButton?: boolean;
116
+ /** That button's text. Default `"Close"`. */
117
+ closeLabel?: string;
108
118
  }
109
119
  export declare const DialogFooter: (props?: DialogFooterProps | undefined) => TemplateResult;
110
120
  export interface DialogTitleProps {
@@ -7,11 +7,11 @@
7
7
  * Dialog({ children: () => html`
8
8
  * ${DialogTrigger({ children: "Edit" })}
9
9
  * ${DialogContent({ children: () => html`
10
- * ${DialogHeader({ children: () => html`
10
+ * ${DialogHeader({ children: html`
11
11
  * ${DialogTitle({ children: "Edit profile" })}
12
12
  * ${DialogDescription({ children: "Change it." })}
13
13
  * ` })}
14
- * ${DialogFooter({ children: () => Button({ children: "Save" }) })}
14
+ * ${DialogFooter({ children: Button({ children: "Save" }) })}
15
15
  * ` })}
16
16
  * ` })
17
17
  *
@@ -21,6 +21,11 @@
21
21
  * with the title's id and a panel rendered first would have had nothing to
22
22
  * point at.
23
23
  *
24
+ * Hence `DialogHeader` gets a VALUE: it takes a `Slot`, which the renderer calls
25
+ * when the panel renders, and a `DialogTitle` built in there registers after
26
+ * the panel has looked for one — it renders, and the panel stays unnamed (see
27
+ * `Parts`). Content that changes goes inside the title, not around it.
28
+ *
24
29
  * The `panel` callback matters more than it looks. The overlay's root spans
25
30
  * the viewport so the backdrop can, which means containment has to be answered
26
31
  * against the panel — check the root and every click on the page counts as
@@ -29,7 +34,8 @@
29
34
  * `aria-labelledby` points at the title and `aria-describedby` at the
30
35
  * description, so a screen reader announces what the dialog is for on open. A
31
36
  * dialog with neither announces only "dialog", which is why a missing
32
- * `DialogTitle` is warned about — as upstream warns — rather than tolerated.
37
+ * `DialogTitle` is warned about rather than tolerated — as Radix did through
38
+ * 1.1; 1.3 counts its titles and no longer warns.
33
39
  */
34
40
  import { component, createContext, html, inject, onUnmount, provide, signal, } from "@c9up/aurora";
35
41
  import { Button } from "../atoms/Button.js";
@@ -165,6 +171,7 @@ export const DialogContent = component((props) => {
165
171
  dialog.register({
166
172
  body,
167
173
  showCloseButton: props.showCloseButton ?? true,
174
+ closeLabel: props.closeLabel ?? "Close",
168
175
  dismissOnOutside: props.dismissOnOutside ?? true,
169
176
  dismissOnEscape: props.dismissOnEscape ?? true,
170
177
  class: props.class,
@@ -182,7 +189,7 @@ export const DialogFooter = component((props) => {
182
189
  type="button"
183
190
  data-slot="dialog-close"
184
191
  @click="${() => dialog.setOpen(false)}"
185
- >${Button({ variant: "outline", children: "Close" })}</button>`
192
+ >${Button({ variant: "outline", children: props.closeLabel ?? "Close" })}</button>`
186
193
  : null;
187
194
  return html `<div
188
195
  data-slot="dialog-footer"
@@ -214,7 +221,7 @@ function renderSurface(registered, ids) {
214
221
  data-slot="dialog-close"
215
222
  class="${closeButtonClasses}"
216
223
  @click="${() => ids.close()}"
217
- >${XIcon({ class: "size-4" })}<span class="sr-only">Close</span></button>`
224
+ >${XIcon({ class: "size-4" })}<span class="sr-only">${registered.closeLabel}</span></button>`
218
225
  : null;
219
226
  return html `<div data-slot="dialog-portal" class="${cn("fixed inset-0 z-50", fadeInOut)}">
220
227
  <div data-slot="dialog-overlay" class="${dialogBackdropClasses}"></div>
@@ -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,6 +66,10 @@ export interface QuestionnaireProps {
66
66
  nextLabel?: string;
67
67
  skipLabel?: string;
68
68
  submitLabel?: string;
69
+ /** The progress bar's accessible name. Default `"Questionnaire progress"`. */
70
+ progressLabel?: string;
71
+ /** The counter under the bar. Default `"Question 2 of 5"`. */
72
+ counterLabel?: (position: number, total: number) => string;
69
73
  class?: Reactive<string>;
70
74
  }
71
75
  /** Has this question been answered at all? */
@@ -58,6 +58,9 @@ export function isAnswered(question, answer) {
58
58
  return asSet(answer).length > 0;
59
59
  return asValue(answer).trim() !== "";
60
60
  }
61
+ function questionOf(position, total) {
62
+ return `Question ${position} of ${total}`;
63
+ }
61
64
  export const Questionnaire = component((props) => {
62
65
  const total = props.questions.length;
63
66
  const step = signal(0);
@@ -123,13 +126,13 @@ export const Questionnaire = component((props) => {
123
126
  ${Progress({
124
127
  value: () => step() + 1,
125
128
  max: total,
126
- label: "Questionnaire progress",
129
+ label: props.progressLabel ?? "Questionnaire progress",
127
130
  })}
128
131
  <p
129
132
  id="${counterId}"
130
133
  aria-live="polite"
131
134
  class="text-muted-foreground text-xs tabular-nums"
132
- >${() => `Question ${step() + 1} of ${total}`}</p>
135
+ >${() => (props.counterLabel ?? questionOf)(step() + 1, total)}</p>
133
136
  </div>`}
134
137
 
135
138
  ${() => renderQuestion()}