@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.
- package/README.md +8 -7
- package/dist/atoms/Avatar.d.ts +14 -0
- package/dist/atoms/Avatar.js +46 -8
- package/dist/atoms/Checkbox.d.ts +1 -1
- package/dist/atoms/Checkbox.js +1 -1
- package/dist/atoms/Input.d.ts +5 -0
- package/dist/atoms/Input.js +1 -0
- package/dist/cli/add.d.ts +2 -0
- package/dist/cli/add.js +4 -1
- package/dist/cli/diff.d.ts +2 -0
- package/dist/cli/diff.js +4 -1
- package/dist/cli/projectConfig.d.ts +16 -0
- package/dist/cli/projectConfig.js +61 -0
- package/dist/console/AddCommand.js +6 -1
- package/dist/console/DiffCommand.js +6 -1
- package/dist/lib/children.d.ts +13 -8
- package/dist/lib/children.js +5 -0
- package/dist/lib/icons.d.ts +8 -0
- package/dist/lib/icons.js +8 -0
- package/dist/lib/image.js +12 -1
- package/dist/molecules/Breadcrumb.d.ts +11 -2
- package/dist/molecules/Breadcrumb.js +2 -2
- package/dist/molecules/InputOTP.d.ts +14 -0
- package/dist/molecules/InputOTP.js +71 -28
- package/dist/molecules/Pagination.d.ts +34 -2
- package/dist/molecules/Pagination.js +15 -6
- package/dist/molecules/PieceMap.d.ts +72 -0
- package/dist/molecules/PieceMap.js +78 -0
- package/dist/molecules/Resizable.d.ts +2 -0
- package/dist/molecules/Resizable.js +1 -1
- package/dist/molecules/index.d.ts +4 -3
- package/dist/molecules/index.js +2 -1
- package/dist/organisms/Calendar.d.ts +13 -0
- package/dist/organisms/Calendar.js +2 -2
- package/dist/organisms/Carousel.d.ts +8 -0
- package/dist/organisms/Carousel.js +8 -5
- package/dist/organisms/Combobox.d.ts +13 -0
- package/dist/organisms/Combobox.js +5 -2
- package/dist/organisms/Command.js +56 -8
- package/dist/organisms/DataTable.d.ts +23 -1
- package/dist/organisms/DataTable.js +57 -27
- package/dist/organisms/DatePicker.d.ts +7 -0
- package/dist/organisms/DatePicker.js +2 -1
- package/dist/organisms/DateRangePicker.d.ts +2 -0
- package/dist/organisms/DateRangePicker.js +2 -1
- package/dist/organisms/Dialog.d.ts +13 -3
- package/dist/organisms/Dialog.js +12 -5
- package/dist/organisms/Form.d.ts +15 -0
- package/dist/organisms/Form.js +10 -0
- package/dist/organisms/Questionnaire.d.ts +4 -0
- package/dist/organisms/Questionnaire.js +5 -2
- package/dist/organisms/Select.d.ts +25 -4
- package/dist/organisms/Select.js +116 -15
- package/dist/organisms/Sheet.d.ts +2 -0
- package/dist/organisms/Sheet.js +2 -1
- package/dist/organisms/Sidebar.d.ts +10 -2
- package/dist/organisms/Sidebar.js +62 -29
- package/dist/organisms/Sonner.d.ts +243 -0
- package/dist/organisms/Sonner.js +909 -0
- package/dist/organisms/Toaster.d.ts +11 -0
- package/dist/organisms/Toaster.js +34 -9
- package/dist/organisms/Tooltip.d.ts +4 -0
- package/dist/organisms/index.d.ts +8 -2
- package/dist/organisms/index.js +7 -1
- package/dist/primitives/dismissable.d.ts +11 -4
- package/dist/primitives/dismissable.js +8 -6
- package/dist/primitives/floating.d.ts +5 -1
- package/dist/primitives/floating.js +32 -2
- package/dist/primitives/menu.js +2 -1
- package/dist/primitives/modalSurface.js +70 -36
- package/dist/primitives/presence.js +8 -5
- package/dist/templates/SettingsLayout.d.ts +2 -0
- package/dist/templates/SettingsLayout.js +1 -1
- package/nebula.css +2 -2
- package/package.json +3 -3
- package/registry.json +26 -0
- package/src/atoms/Avatar.ts +54 -7
- package/src/atoms/Checkbox.ts +1 -1
- package/src/atoms/Input.ts +6 -0
- package/src/cli/add.ts +7 -1
- package/src/cli/diff.ts +7 -1
- package/src/cli/projectConfig.ts +71 -0
- package/src/console/AddCommand.ts +6 -1
- package/src/console/DiffCommand.ts +6 -1
- package/src/lib/children.ts +15 -7
- package/src/lib/icons.ts +28 -0
- package/src/lib/image.ts +13 -1
- package/src/molecules/Breadcrumb.ts +15 -4
- package/src/molecules/InputOTP.ts +88 -28
- package/src/molecules/Pagination.ts +50 -8
- package/src/molecules/PieceMap.ts +136 -0
- package/src/molecules/Resizable.ts +3 -1
- package/src/molecules/index.ts +17 -0
- package/src/organisms/Calendar.ts +16 -2
- package/src/organisms/Carousel.ts +17 -5
- package/src/organisms/Combobox.ts +18 -2
- package/src/organisms/Command.ts +66 -7
- package/src/organisms/DataTable.ts +95 -30
- package/src/organisms/DatePicker.ts +10 -2
- package/src/organisms/DateRangePicker.ts +4 -2
- package/src/organisms/Dialog.ts +17 -5
- package/src/organisms/Form.ts +21 -0
- package/src/organisms/Questionnaire.ts +10 -2
- package/src/organisms/Select.ts +140 -16
- package/src/organisms/Sheet.ts +5 -1
- package/src/organisms/Sidebar.ts +62 -23
- package/src/organisms/Sonner.ts +1366 -0
- package/src/organisms/Toaster.ts +38 -10
- package/src/organisms/Tooltip.ts +4 -0
- package/src/organisms/index.ts +30 -1
- package/src/primitives/dismissable.ts +16 -8
- package/src/primitives/floating.ts +40 -3
- package/src/primitives/menu.ts +2 -1
- package/src/primitives/modalSurface.ts +77 -40
- package/src/primitives/presence.ts +12 -9
- package/src/templates/SettingsLayout.ts +3 -1
|
@@ -20,7 +20,14 @@
|
|
|
20
20
|
* attribute is what says it to everyone else.
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
each,
|
|
25
|
+
html,
|
|
26
|
+
memo,
|
|
27
|
+
type ReadSignal,
|
|
28
|
+
signal,
|
|
29
|
+
type TemplateResult,
|
|
30
|
+
} from "@c9up/aurora";
|
|
24
31
|
import { Checkbox } from "../atoms/Checkbox.js";
|
|
25
32
|
import { Input } from "../atoms/Input.js";
|
|
26
33
|
import type { Child } from "../lib/children.js";
|
|
@@ -30,15 +37,18 @@ import {
|
|
|
30
37
|
ChevronsUpDownIcon,
|
|
31
38
|
ChevronUpIcon,
|
|
32
39
|
} from "../lib/icons.js";
|
|
40
|
+
import { type Reactive, read } from "../lib/props.js";
|
|
33
41
|
import {
|
|
34
42
|
Pagination,
|
|
35
43
|
PaginationContent,
|
|
36
44
|
PaginationEllipsis,
|
|
37
45
|
PaginationItem,
|
|
46
|
+
type PaginationLabels,
|
|
38
47
|
PaginationLink,
|
|
39
48
|
PaginationNext,
|
|
40
49
|
PaginationPrevious,
|
|
41
50
|
pageWindow,
|
|
51
|
+
paginationLabels,
|
|
42
52
|
} from "../molecules/Pagination.js";
|
|
43
53
|
import {
|
|
44
54
|
Table,
|
|
@@ -62,16 +72,36 @@ export interface Column<Row> {
|
|
|
62
72
|
|
|
63
73
|
export interface DataTableProps<Row> {
|
|
64
74
|
columns: readonly Column<Row>[];
|
|
65
|
-
|
|
75
|
+
/**
|
|
76
|
+
* The rows, or an accessor for rows that change. An accessor must return the
|
|
77
|
+
* same array until the data changes — a new one per read counts as new data
|
|
78
|
+
* on every read, as it does for TanStack's `data`.
|
|
79
|
+
*/
|
|
80
|
+
rows: Reactive<readonly Row[]>;
|
|
66
81
|
/** Stable identity per row — used for selection and as the render key. */
|
|
67
82
|
rowKey: (row: Row) => string;
|
|
68
83
|
/** Rows per page. Omit to show everything. */
|
|
69
84
|
pageSize?: number;
|
|
85
|
+
/**
|
|
86
|
+
* Go back to the first page when the rows change. Default `true`, as
|
|
87
|
+
* TanStack's `autoResetPageIndex`: the page was chosen in data that is
|
|
88
|
+
* gone. Turn it off for rows refreshed in place, such as a polled list.
|
|
89
|
+
* Sorting and the filter always survive a change.
|
|
90
|
+
*/
|
|
91
|
+
autoResetPage?: boolean;
|
|
70
92
|
/** Show a filter box. Provide `filterMatch` to say what it searches. */
|
|
71
93
|
filterPlaceholder?: string;
|
|
94
|
+
/** The filter box's accessible name. Defaults to the placeholder. */
|
|
95
|
+
filterLabel?: string;
|
|
72
96
|
filterMatch?: (row: Row, query: string) => boolean;
|
|
73
97
|
/** Add a checkbox column. */
|
|
74
98
|
selectable?: boolean;
|
|
99
|
+
/** The header checkbox's accessible name. Default `"Select all rows on this page"`. */
|
|
100
|
+
selectAllLabel?: string;
|
|
101
|
+
/** A row checkbox's accessible name. Default `"Select row <key>"`. */
|
|
102
|
+
selectRowLabel?: (row: Row) => string;
|
|
103
|
+
/** The pager's words — see `PaginationLabels`. */
|
|
104
|
+
paginationLabels?: Partial<PaginationLabels>;
|
|
75
105
|
onSelectionChange?: (keys: readonly string[]) => void;
|
|
76
106
|
emptyMessage?: Child;
|
|
77
107
|
class?: string;
|
|
@@ -83,7 +113,13 @@ export function DataTable<Row>(props: DataTableProps<Row>): TemplateResult {
|
|
|
83
113
|
const sortKey = signal<string | undefined>(undefined);
|
|
84
114
|
const sortDirection = signal<SortDirection>("asc");
|
|
85
115
|
const query = signal("");
|
|
86
|
-
|
|
116
|
+
/**
|
|
117
|
+
* The page, and the rows it was chosen in. Derived rather than reset by an
|
|
118
|
+
* effect: when the rows are no longer those, the page reads as the first.
|
|
119
|
+
*/
|
|
120
|
+
const page = signal<{ readonly number: number; readonly of: readonly Row[] }>(
|
|
121
|
+
{ number: 1, of: read(props.rows) },
|
|
122
|
+
);
|
|
87
123
|
const selected = signal<readonly string[]>([]);
|
|
88
124
|
|
|
89
125
|
function readCell(row: Row, column: Column<Row>): Child {
|
|
@@ -98,11 +134,20 @@ export function DataTable<Row>(props: DataTableProps<Row>): TemplateResult {
|
|
|
98
134
|
}
|
|
99
135
|
|
|
100
136
|
function filtered(): readonly Row[] {
|
|
137
|
+
const rows = read(props.rows);
|
|
101
138
|
const needle = query().trim().toLowerCase();
|
|
102
|
-
if (needle === "" || props.filterMatch === undefined) return
|
|
103
|
-
return
|
|
104
|
-
|
|
105
|
-
|
|
139
|
+
if (needle === "" || props.filterMatch === undefined) return rows;
|
|
140
|
+
return rows.filter((row) => props.filterMatch?.(row, needle) === true);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function pageNumber(): number {
|
|
144
|
+
const { number, of } = page();
|
|
145
|
+
if (props.autoResetPage !== false && of !== read(props.rows)) return 1;
|
|
146
|
+
return number;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function goToPage(number: number): void {
|
|
150
|
+
page({ number, of: read(props.rows) });
|
|
106
151
|
}
|
|
107
152
|
|
|
108
153
|
function sorted(): readonly Row[] {
|
|
@@ -135,11 +180,14 @@ export function DataTable<Row>(props: DataTableProps<Row>): TemplateResult {
|
|
|
135
180
|
if (props.pageSize === undefined) return rows;
|
|
136
181
|
// Clamp: filtering down to fewer pages while on the last one would
|
|
137
182
|
// otherwise show an empty table with no way back.
|
|
138
|
-
const current = Math.min(
|
|
183
|
+
const current = Math.min(pageNumber(), pageCount());
|
|
139
184
|
const from = (current - 1) * props.pageSize;
|
|
140
185
|
return rows.slice(from, from + props.pageSize);
|
|
141
186
|
}
|
|
142
187
|
|
|
188
|
+
/** Whether the body shows the empty row — read apart, so the list survives. */
|
|
189
|
+
const isEmpty = memo(() => visible().length === 0);
|
|
190
|
+
|
|
143
191
|
function toggleSort(column: Column<Row>): void {
|
|
144
192
|
if (column.sortable === false) return;
|
|
145
193
|
if (sortKey() === column.key) {
|
|
@@ -210,10 +258,11 @@ export function DataTable<Row>(props: DataTableProps<Row>): TemplateResult {
|
|
|
210
258
|
: Input({
|
|
211
259
|
type: "search",
|
|
212
260
|
placeholder: props.filterPlaceholder ?? "Filter…",
|
|
261
|
+
label: props.filterLabel ?? props.filterPlaceholder ?? "Filter…",
|
|
213
262
|
class: "max-w-sm",
|
|
214
263
|
onInput: (value) => {
|
|
215
264
|
query(value);
|
|
216
|
-
|
|
265
|
+
goToPage(1);
|
|
217
266
|
},
|
|
218
267
|
})
|
|
219
268
|
}
|
|
@@ -226,7 +275,8 @@ export function DataTable<Row>(props: DataTableProps<Row>): TemplateResult {
|
|
|
226
275
|
? TableHead({
|
|
227
276
|
class: "w-10",
|
|
228
277
|
children: Checkbox({
|
|
229
|
-
label:
|
|
278
|
+
label:
|
|
279
|
+
props.selectAllLabel ?? "Select all rows on this page",
|
|
230
280
|
checked: () => {
|
|
231
281
|
const keys = visible().map(props.rowKey);
|
|
232
282
|
return (
|
|
@@ -264,19 +314,19 @@ export function DataTable<Row>(props: DataTableProps<Row>): TemplateResult {
|
|
|
264
314
|
}),
|
|
265
315
|
}),
|
|
266
316
|
TableBody({
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
317
|
+
// Rows by key: a re-read, a sort or a page change keeps the rows
|
|
318
|
+
// that stay, with their open menus and focus. The body itself only
|
|
319
|
+
// switches between the list and the empty row.
|
|
320
|
+
children: () =>
|
|
321
|
+
isEmpty()
|
|
322
|
+
? TableRow({
|
|
323
|
+
children: TableCell({
|
|
324
|
+
colspan: columnCount,
|
|
325
|
+
class: "h-24 text-center",
|
|
326
|
+
children: props.emptyMessage ?? "No results.",
|
|
327
|
+
}),
|
|
328
|
+
})
|
|
329
|
+
: each(visible, props.rowKey, renderRow),
|
|
280
330
|
}),
|
|
281
331
|
],
|
|
282
332
|
})}
|
|
@@ -291,16 +341,21 @@ export function DataTable<Row>(props: DataTableProps<Row>): TemplateResult {
|
|
|
291
341
|
* current one and the gaps between — and the parts render that list.
|
|
292
342
|
*/
|
|
293
343
|
function renderPagination(): Child {
|
|
294
|
-
const current = (): number => Math.min(
|
|
344
|
+
const current = (): number => Math.min(pageNumber(), pageCount());
|
|
295
345
|
const go = (target: number) => (): void => {
|
|
296
|
-
|
|
346
|
+
goToPage(Math.min(Math.max(target, 1), pageCount()));
|
|
297
347
|
};
|
|
348
|
+
const word = (key: keyof PaginationLabels): string =>
|
|
349
|
+
props.paginationLabels?.[key] ?? paginationLabels[key];
|
|
298
350
|
return Pagination({
|
|
351
|
+
"aria-label": word("navigation"),
|
|
299
352
|
children: () =>
|
|
300
353
|
PaginationContent({
|
|
301
354
|
children: [
|
|
302
355
|
PaginationItem({
|
|
303
356
|
children: PaginationPrevious({
|
|
357
|
+
"aria-label": word("previousPage"),
|
|
358
|
+
children: word("previous"),
|
|
304
359
|
disabled: () => current() <= 1,
|
|
305
360
|
onSelect: go(current() - 1),
|
|
306
361
|
}),
|
|
@@ -309,7 +364,7 @@ export function DataTable<Row>(props: DataTableProps<Row>): TemplateResult {
|
|
|
309
364
|
PaginationItem({
|
|
310
365
|
children:
|
|
311
366
|
entry === null
|
|
312
|
-
? PaginationEllipsis({})
|
|
367
|
+
? PaginationEllipsis({ label: word("morePages") })
|
|
313
368
|
: PaginationLink({
|
|
314
369
|
children: String(entry),
|
|
315
370
|
isActive: () => current() === entry,
|
|
@@ -319,6 +374,8 @@ export function DataTable<Row>(props: DataTableProps<Row>): TemplateResult {
|
|
|
319
374
|
),
|
|
320
375
|
PaginationItem({
|
|
321
376
|
children: PaginationNext({
|
|
377
|
+
"aria-label": word("nextPage"),
|
|
378
|
+
children: word("next"),
|
|
322
379
|
disabled: () => current() >= pageCount(),
|
|
323
380
|
onSelect: go(current() + 1),
|
|
324
381
|
}),
|
|
@@ -328,22 +385,30 @@ export function DataTable<Row>(props: DataTableProps<Row>): TemplateResult {
|
|
|
328
385
|
});
|
|
329
386
|
}
|
|
330
387
|
|
|
331
|
-
|
|
332
|
-
|
|
388
|
+
/**
|
|
389
|
+
* One row, built once for its key. The cells read the row through its
|
|
390
|
+
* accessor, so a row whose data changed redraws its cells and nothing else.
|
|
391
|
+
*/
|
|
392
|
+
function renderRow(row: ReadSignal<Row>): Child {
|
|
393
|
+
const key = props.rowKey(row());
|
|
333
394
|
return TableRow({
|
|
334
395
|
selected: () => selected().includes(key),
|
|
335
396
|
children: [
|
|
336
397
|
props.selectable === true
|
|
337
398
|
? TableCell({
|
|
338
399
|
children: Checkbox({
|
|
339
|
-
label:
|
|
400
|
+
label: () =>
|
|
401
|
+
props.selectRowLabel?.(row()) ?? `Select row ${key}`,
|
|
340
402
|
checked: () => selected().includes(key),
|
|
341
403
|
onCheckedChange: () => toggleRow(key),
|
|
342
404
|
}),
|
|
343
405
|
})
|
|
344
406
|
: null,
|
|
345
407
|
...props.columns.map((column) =>
|
|
346
|
-
TableCell({
|
|
408
|
+
TableCell({
|
|
409
|
+
class: column.class,
|
|
410
|
+
children: () => readCell(row(), column),
|
|
411
|
+
}),
|
|
347
412
|
),
|
|
348
413
|
],
|
|
349
414
|
});
|
|
@@ -26,7 +26,13 @@ import { type Reactive, read, readOr } from "../lib/props.js";
|
|
|
26
26
|
import { controllable } from "../primitives/controllable.js";
|
|
27
27
|
import { floatingSurface } from "../primitives/floatingSurface.js";
|
|
28
28
|
import { focusSilently } from "../primitives/focusable.js";
|
|
29
|
-
import { Calendar, startOfDay } from "./Calendar.js";
|
|
29
|
+
import { Calendar, type CalendarLabels, startOfDay } from "./Calendar.js";
|
|
30
|
+
|
|
31
|
+
/** The calendar's words, plus the popup's accessible name. */
|
|
32
|
+
export interface DatePickerLabels extends CalendarLabels {
|
|
33
|
+
/** Default `"Choose a date"`, or `"Choose a date range"`. */
|
|
34
|
+
dialog: string;
|
|
35
|
+
}
|
|
30
36
|
|
|
31
37
|
export interface DatePickerProps {
|
|
32
38
|
name?: string;
|
|
@@ -38,6 +44,7 @@ export interface DatePickerProps {
|
|
|
38
44
|
disabled?: Reactive<boolean>;
|
|
39
45
|
invalid?: Reactive<boolean>;
|
|
40
46
|
locale?: string;
|
|
47
|
+
labels?: Partial<DatePickerLabels>;
|
|
41
48
|
class?: Reactive<string>;
|
|
42
49
|
onValueChange?: (date: Date) => void;
|
|
43
50
|
}
|
|
@@ -86,7 +93,7 @@ export const DatePicker = component<DatePickerProps>((props) => {
|
|
|
86
93
|
data-slot="date-picker-content"
|
|
87
94
|
id="${contentId}"
|
|
88
95
|
role="dialog"
|
|
89
|
-
aria-label="Choose a date"
|
|
96
|
+
aria-label="${props.labels?.dialog ?? "Choose a date"}"
|
|
90
97
|
class="${cn(
|
|
91
98
|
"bg-popover text-popover-foreground z-50 rounded-md border p-0 shadow-md outline-none",
|
|
92
99
|
zoomInOut,
|
|
@@ -98,6 +105,7 @@ export const DatePicker = component<DatePickerProps>((props) => {
|
|
|
98
105
|
min: props.min,
|
|
99
106
|
max: props.max,
|
|
100
107
|
locale: props.locale,
|
|
108
|
+
labels: props.labels,
|
|
101
109
|
onValueChange: choose,
|
|
102
110
|
})}
|
|
103
111
|
</div>`,
|
|
@@ -26,7 +26,7 @@ import { controllable } from "../primitives/controllable.js";
|
|
|
26
26
|
import { floatingSurface } from "../primitives/floatingSurface.js";
|
|
27
27
|
import { focusSilently } from "../primitives/focusable.js";
|
|
28
28
|
import { Calendar, type DateRange, startOfDay } from "./Calendar.js";
|
|
29
|
-
import { toISODate } from "./DatePicker.js";
|
|
29
|
+
import { type DatePickerLabels, toISODate } from "./DatePicker.js";
|
|
30
30
|
|
|
31
31
|
export interface DateRangePickerProps {
|
|
32
32
|
/** Base name for the hidden inputs — `"stay"` posts `stay_from` / `stay_to`. */
|
|
@@ -39,6 +39,7 @@ export interface DateRangePickerProps {
|
|
|
39
39
|
disabled?: Reactive<boolean>;
|
|
40
40
|
invalid?: Reactive<boolean>;
|
|
41
41
|
locale?: string;
|
|
42
|
+
labels?: Partial<DatePickerLabels>;
|
|
42
43
|
class?: Reactive<string>;
|
|
43
44
|
/** Fires on both clicks — `to` is absent after the first. */
|
|
44
45
|
onValueChange?: (range: DateRange) => void;
|
|
@@ -90,7 +91,7 @@ export const DateRangePicker = component<DateRangePickerProps>((props) => {
|
|
|
90
91
|
data-slot="date-range-picker-content"
|
|
91
92
|
id="${contentId}"
|
|
92
93
|
role="dialog"
|
|
93
|
-
aria-label="Choose a date range"
|
|
94
|
+
aria-label="${props.labels?.dialog ?? "Choose a date range"}"
|
|
94
95
|
class="${cn(
|
|
95
96
|
"bg-popover text-popover-foreground z-50 rounded-md border p-0 shadow-md outline-none",
|
|
96
97
|
zoomInOut,
|
|
@@ -103,6 +104,7 @@ export const DateRangePicker = component<DateRangePickerProps>((props) => {
|
|
|
103
104
|
min: props.min,
|
|
104
105
|
max: props.max,
|
|
105
106
|
locale: props.locale,
|
|
107
|
+
labels: props.labels,
|
|
106
108
|
onRangeChange: pick,
|
|
107
109
|
})}
|
|
108
110
|
</div>`,
|
package/src/organisms/Dialog.ts
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
* Dialog({ children: () => html`
|
|
8
8
|
* ${DialogTrigger({ children: "Edit" })}
|
|
9
9
|
* ${DialogContent({ children: () => html`
|
|
10
|
-
* ${DialogHeader({ children:
|
|
10
|
+
* ${DialogHeader({ children: html`
|
|
11
11
|
* ${DialogTitle({ children: "Edit profile" })}
|
|
12
12
|
* ${DialogDescription({ children: "Change it." })}
|
|
13
13
|
* ` })}
|
|
14
|
-
* ${DialogFooter({ children:
|
|
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
|
|
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
|
|
|
35
41
|
import {
|
|
@@ -66,6 +72,7 @@ const closeButtonClasses =
|
|
|
66
72
|
interface RegisteredContent {
|
|
67
73
|
readonly body: Child;
|
|
68
74
|
readonly showCloseButton: boolean;
|
|
75
|
+
readonly closeLabel: string;
|
|
69
76
|
readonly dismissOnOutside: boolean;
|
|
70
77
|
readonly dismissOnEscape: boolean;
|
|
71
78
|
readonly class?: Reactive<string>;
|
|
@@ -238,6 +245,8 @@ export interface DialogContentProps {
|
|
|
238
245
|
children?: Parts;
|
|
239
246
|
/** The corner cross. */
|
|
240
247
|
showCloseButton?: boolean;
|
|
248
|
+
/** The cross's accessible name. Default `"Close"`. */
|
|
249
|
+
closeLabel?: string;
|
|
241
250
|
/** A click outside closes. `false` for a decision that must be made. */
|
|
242
251
|
dismissOnOutside?: boolean;
|
|
243
252
|
/** Escape closes. `false` for the same reason. */
|
|
@@ -258,6 +267,7 @@ export const DialogContent = component<DialogContentProps>((props) => {
|
|
|
258
267
|
dialog.register({
|
|
259
268
|
body,
|
|
260
269
|
showCloseButton: props.showCloseButton ?? true,
|
|
270
|
+
closeLabel: props.closeLabel ?? "Close",
|
|
261
271
|
dismissOnOutside: props.dismissOnOutside ?? true,
|
|
262
272
|
dismissOnEscape: props.dismissOnEscape ?? true,
|
|
263
273
|
class: props.class,
|
|
@@ -280,6 +290,8 @@ export const DialogHeader = component<DialogSectionProps>(
|
|
|
280
290
|
export interface DialogFooterProps extends DialogSectionProps {
|
|
281
291
|
/** Append a "Close" button after the children, as upstream can. */
|
|
282
292
|
showCloseButton?: boolean;
|
|
293
|
+
/** That button's text. Default `"Close"`. */
|
|
294
|
+
closeLabel?: string;
|
|
283
295
|
}
|
|
284
296
|
|
|
285
297
|
export const DialogFooter = component<DialogFooterProps>((props) => {
|
|
@@ -290,7 +302,7 @@ export const DialogFooter = component<DialogFooterProps>((props) => {
|
|
|
290
302
|
type="button"
|
|
291
303
|
data-slot="dialog-close"
|
|
292
304
|
@click="${() => dialog.setOpen(false)}"
|
|
293
|
-
>${Button({ variant: "outline", children: "Close" })}</button>`
|
|
305
|
+
>${Button({ variant: "outline", children: props.closeLabel ?? "Close" })}</button>`
|
|
294
306
|
: null;
|
|
295
307
|
return html`<div
|
|
296
308
|
data-slot="dialog-footer"
|
|
@@ -347,7 +359,7 @@ function renderSurface(
|
|
|
347
359
|
data-slot="dialog-close"
|
|
348
360
|
class="${closeButtonClasses}"
|
|
349
361
|
@click="${() => ids.close()}"
|
|
350
|
-
>${XIcon({ class: "size-4" })}<span class="sr-only"
|
|
362
|
+
>${XIcon({ class: "size-4" })}<span class="sr-only">${registered.closeLabel}</span></button>`
|
|
351
363
|
: null;
|
|
352
364
|
return html`<div data-slot="dialog-portal" class="${cn("fixed inset-0 z-50", fadeInOut)}">
|
|
353
365
|
<div data-slot="dialog-overlay" class="${dialogBackdropClasses}"></div>
|
package/src/organisms/Form.ts
CHANGED
|
@@ -77,6 +77,17 @@ export function bind<T, K extends keyof T & string>(
|
|
|
77
77
|
|
|
78
78
|
export interface FormProps<T> {
|
|
79
79
|
form: AuroraForm<T>;
|
|
80
|
+
/**
|
|
81
|
+
* How the browser submits it before the page is hydrated, or when a
|
|
82
|
+
* script fails to load. Default `"post"`.
|
|
83
|
+
*/
|
|
84
|
+
method?: "post" | "get" | "dialog";
|
|
85
|
+
/** Where that submission goes. Left out, it goes to the current page. */
|
|
86
|
+
action?: string;
|
|
87
|
+
enctype?:
|
|
88
|
+
| "application/x-www-form-urlencoded"
|
|
89
|
+
| "multipart/form-data"
|
|
90
|
+
| "text/plain";
|
|
80
91
|
children?: Slot;
|
|
81
92
|
class?: Reactive<string>;
|
|
82
93
|
}
|
|
@@ -88,11 +99,21 @@ export interface FormProps<T> {
|
|
|
88
99
|
* styled, appear one at a time, and vanish on scroll — and they would fire
|
|
89
100
|
* before the controller's validation ever runs, so the user would see two
|
|
90
101
|
* different error presentations for the same field.
|
|
102
|
+
*
|
|
103
|
+
* NAMED DEVIATION: `method="post"` unless told otherwise. shadcn's `Form`
|
|
104
|
+
* renders no `<form>`, so the app writes its own method; this one owns the
|
|
105
|
+
* element, and the server renders it. Pressed before hydration, a form with
|
|
106
|
+
* no method is a GET, and every named field — a password included — lands in
|
|
107
|
+
* the URL, the history and the access logs. An app with CSRF protection puts
|
|
108
|
+
* its token field among the children, so that early POST is accepted.
|
|
91
109
|
*/
|
|
92
110
|
export function Form<T>(props: FormProps<T>): ReturnType<typeof html> {
|
|
93
111
|
return html`<form
|
|
94
112
|
data-slot="form"
|
|
95
113
|
novalidate
|
|
114
|
+
method="${props.method ?? "post"}"
|
|
115
|
+
action="${props.action}"
|
|
116
|
+
enctype="${props.enctype}"
|
|
96
117
|
class="${() => cn("flex flex-col gap-6", read(props.class))}"
|
|
97
118
|
@submit="${(event: Event) => {
|
|
98
119
|
// A DOM listener returns nothing, so this promise is nobody's to
|
|
@@ -87,6 +87,10 @@ export interface QuestionnaireProps {
|
|
|
87
87
|
nextLabel?: string;
|
|
88
88
|
skipLabel?: string;
|
|
89
89
|
submitLabel?: string;
|
|
90
|
+
/** The progress bar's accessible name. Default `"Questionnaire progress"`. */
|
|
91
|
+
progressLabel?: string;
|
|
92
|
+
/** The counter under the bar. Default `"Question 2 of 5"`. */
|
|
93
|
+
counterLabel?: (position: number, total: number) => string;
|
|
90
94
|
class?: Reactive<string>;
|
|
91
95
|
}
|
|
92
96
|
|
|
@@ -120,6 +124,10 @@ export function isAnswered(
|
|
|
120
124
|
return asValue(answer).trim() !== "";
|
|
121
125
|
}
|
|
122
126
|
|
|
127
|
+
function questionOf(position: number, total: number): string {
|
|
128
|
+
return `Question ${position} of ${total}`;
|
|
129
|
+
}
|
|
130
|
+
|
|
123
131
|
export const Questionnaire = component<QuestionnaireProps>((props) => {
|
|
124
132
|
const total = props.questions.length;
|
|
125
133
|
const step = signal(0);
|
|
@@ -192,13 +200,13 @@ export const Questionnaire = component<QuestionnaireProps>((props) => {
|
|
|
192
200
|
${Progress({
|
|
193
201
|
value: () => step() + 1,
|
|
194
202
|
max: total,
|
|
195
|
-
label: "Questionnaire progress",
|
|
203
|
+
label: props.progressLabel ?? "Questionnaire progress",
|
|
196
204
|
})}
|
|
197
205
|
<p
|
|
198
206
|
id="${counterId}"
|
|
199
207
|
aria-live="polite"
|
|
200
208
|
class="text-muted-foreground text-xs tabular-nums"
|
|
201
|
-
>${() =>
|
|
209
|
+
>${() => (props.counterLabel ?? questionOf)(step() + 1, total)}</p>
|
|
202
210
|
</div>`
|
|
203
211
|
}
|
|
204
212
|
|