@c9up/nebula 0.2.2 → 0.2.3
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 +2 -2
- 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/lib/children.d.ts +13 -8
- package/dist/lib/children.js +5 -0
- package/dist/molecules/Breadcrumb.d.ts +11 -2
- package/dist/molecules/Breadcrumb.js +2 -2
- package/dist/molecules/InputOTP.d.ts +2 -0
- package/dist/molecules/InputOTP.js +3 -1
- 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 +3 -2
- package/dist/molecules/index.js +1 -0
- 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/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/Questionnaire.d.ts +4 -0
- package/dist/organisms/Questionnaire.js +5 -2
- package/dist/organisms/Select.d.ts +23 -4
- package/dist/organisms/Select.js +115 -15
- package/dist/organisms/Sheet.d.ts +2 -0
- package/dist/organisms/Sheet.js +2 -1
- package/dist/organisms/Sidebar.d.ts +6 -0
- package/dist/organisms/Sidebar.js +9 -4
- package/dist/organisms/Toaster.d.ts +2 -0
- package/dist/organisms/Toaster.js +6 -4
- package/dist/organisms/index.d.ts +2 -2
- package/dist/organisms/index.js +1 -1
- package/dist/primitives/floating.js +24 -1
- package/dist/templates/SettingsLayout.d.ts +2 -0
- package/dist/templates/SettingsLayout.js +1 -1
- package/nebula.css +1 -1
- package/package.json +3 -3
- package/registry.json +13 -0
- package/src/atoms/Checkbox.ts +1 -1
- package/src/atoms/Input.ts +6 -0
- package/src/lib/children.ts +15 -7
- package/src/molecules/Breadcrumb.ts +15 -4
- package/src/molecules/InputOTP.ts +7 -1
- 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 +14 -0
- package/src/organisms/Calendar.ts +16 -2
- package/src/organisms/Carousel.ts +17 -5
- 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/Questionnaire.ts +10 -2
- package/src/organisms/Select.ts +137 -16
- package/src/organisms/Sheet.ts +5 -1
- package/src/organisms/Sidebar.ts +15 -4
- package/src/organisms/Toaster.ts +8 -4
- package/src/organisms/index.ts +7 -1
- package/src/primitives/floating.ts +27 -1
- package/src/templates/SettingsLayout.ts +3 -1
|
@@ -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
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
|
50
|
-
return
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
})
|
|
202
|
-
}
|
|
203
|
-
|
|
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(
|
|
235
|
+
const current = () => Math.min(pageNumber(), pageCount());
|
|
219
236
|
const go = (target) => () => {
|
|
220
|
-
|
|
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({
|
|
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:
|
|
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
|
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 {
|
package/dist/organisms/Dialog.js
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
|
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"
|
|
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>
|
|
@@ -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
|
-
>${() =>
|
|
135
|
+
>${() => (props.counterLabel ?? questionOf)(step() + 1, total)}</p>
|
|
133
136
|
</div>`}
|
|
134
137
|
|
|
135
138
|
${() => renderQuestion()}
|
|
@@ -19,10 +19,19 @@
|
|
|
19
19
|
* ` })}
|
|
20
20
|
* ` })
|
|
21
21
|
*
|
|
22
|
-
* The items REGISTER themselves as they are built
|
|
23
|
-
*
|
|
24
|
-
* the
|
|
25
|
-
*
|
|
22
|
+
* The items REGISTER themselves as they are built: what each one is called and
|
|
23
|
+
* whether it is disabled, by value. WHICH options exist and in what order is
|
|
24
|
+
* read from the mounted list, as Radix's collection reads it — so options built
|
|
25
|
+
* in an accessor follow a signal:
|
|
26
|
+
*
|
|
27
|
+
* SelectContent({ children: () => html`${() => roles().map((role) =>
|
|
28
|
+
* SelectItem({ value: role.id, children: role.name }))}` })
|
|
29
|
+
*
|
|
30
|
+
* Closed, the list is still mounted, outside the document, as Radix renders a
|
|
31
|
+
* closed select's content into a DocumentFragment: the options exist, so the
|
|
32
|
+
* trigger shows the chosen one's label and the keyboard can walk them. Focus
|
|
33
|
+
* stays on the trigger and only `aria-activedescendant` moves, so the walk is
|
|
34
|
+
* over those options, not over focusable elements.
|
|
26
35
|
*
|
|
27
36
|
* What a native `<select>` was doing for free, and all of which has to be put
|
|
28
37
|
* back by hand:
|
|
@@ -56,9 +65,19 @@ export interface SelectProps {
|
|
|
56
65
|
children?: Parts;
|
|
57
66
|
}
|
|
58
67
|
export declare const Select: (props?: SelectProps | undefined) => TemplateResult;
|
|
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.
|
|
73
|
+
*/
|
|
59
74
|
export interface SelectTriggerProps {
|
|
60
75
|
children?: Slot;
|
|
61
76
|
size?: "default" | "sm";
|
|
77
|
+
id?: string;
|
|
78
|
+
/** Accessible name (`aria-label`), for a select no `<label>` names. */
|
|
79
|
+
label?: Reactive<string | undefined>;
|
|
80
|
+
describedBy?: Reactive<string | undefined>;
|
|
62
81
|
class?: Reactive<string>;
|
|
63
82
|
}
|
|
64
83
|
export declare const SelectTrigger: (props?: SelectTriggerProps | undefined) => TemplateResult;
|