@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
|
@@ -79,11 +79,45 @@ export interface PaginationProps {
|
|
|
79
79
|
class?: Reactive<string>;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Every text the pagination writes, in one place.
|
|
84
|
+
*
|
|
85
|
+
* The defaults are upstream's English. An app in another language passes its
|
|
86
|
+
* own: most of these are read only by a screen reader, which would otherwise
|
|
87
|
+
* switch to English in the middle of the page.
|
|
88
|
+
*/
|
|
89
|
+
export interface PaginationLabels {
|
|
90
|
+
/** The `<nav>`'s accessible name. */
|
|
91
|
+
navigation: string;
|
|
92
|
+
/** The visible word beside the previous arrow. */
|
|
93
|
+
previous: string;
|
|
94
|
+
/** The previous link's accessible name. */
|
|
95
|
+
previousPage: string;
|
|
96
|
+
next: string;
|
|
97
|
+
nextPage: string;
|
|
98
|
+
/** The ellipsis's hidden text. */
|
|
99
|
+
morePages: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Frozen: the defaults, not a place to set an app's language from. */
|
|
103
|
+
export const paginationLabels: Readonly<PaginationLabels> = Object.freeze({
|
|
104
|
+
navigation: "pagination",
|
|
105
|
+
previous: "Previous",
|
|
106
|
+
previousPage: "Go to previous page",
|
|
107
|
+
next: "Next",
|
|
108
|
+
nextPage: "Go to next page",
|
|
109
|
+
morePages: "More pages",
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
export interface PaginationNavProps extends PaginationProps {
|
|
113
|
+
"aria-label"?: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export const Pagination = component<PaginationNavProps>(
|
|
83
117
|
(props) => html`<nav
|
|
84
118
|
data-slot="pagination"
|
|
85
119
|
role="navigation"
|
|
86
|
-
aria-label="
|
|
120
|
+
aria-label="${props["aria-label"] ?? paginationLabels.navigation}"
|
|
87
121
|
class="${() => cn("mx-auto flex w-full justify-center", read(props.class))}"
|
|
88
122
|
>${slot(props.children)}</nav>`,
|
|
89
123
|
);
|
|
@@ -153,18 +187,24 @@ export const PaginationLink = component<PaginationLinkProps>((props) => {
|
|
|
153
187
|
>${slot(props.children)}</a>`;
|
|
154
188
|
});
|
|
155
189
|
|
|
190
|
+
/**
|
|
191
|
+
* `aria-label` replaces the accessible name, as upstream's prop spread lets it.
|
|
192
|
+
* `children` replaces the visible word and keeps the arrow — upstream writes
|
|
193
|
+
* that word in the file, which an app owning its copy can edit and a package
|
|
194
|
+
* cannot.
|
|
195
|
+
*/
|
|
156
196
|
export type PaginationStepProps = Omit<
|
|
157
197
|
PaginationLinkProps,
|
|
158
|
-
"size" | "isActive"
|
|
198
|
+
"size" | "isActive"
|
|
159
199
|
>;
|
|
160
200
|
|
|
161
201
|
export const PaginationPrevious = component<PaginationStepProps>((props) =>
|
|
162
202
|
PaginationLink({
|
|
163
203
|
...props,
|
|
164
204
|
size: "default",
|
|
165
|
-
"aria-label": "
|
|
205
|
+
"aria-label": props["aria-label"] ?? paginationLabels.previousPage,
|
|
166
206
|
class: () => cn("gap-1 px-2.5 sm:pl-2.5", read(props.class)),
|
|
167
|
-
children: html`${ChevronLeftIcon({})}<span class="hidden sm:block"
|
|
207
|
+
children: html`${ChevronLeftIcon({})}<span class="hidden sm:block">${slot(props.children ?? paginationLabels.previous)}</span>`,
|
|
168
208
|
}),
|
|
169
209
|
);
|
|
170
210
|
|
|
@@ -172,13 +212,15 @@ export const PaginationNext = component<PaginationStepProps>((props) =>
|
|
|
172
212
|
PaginationLink({
|
|
173
213
|
...props,
|
|
174
214
|
size: "default",
|
|
175
|
-
"aria-label": "
|
|
215
|
+
"aria-label": props["aria-label"] ?? paginationLabels.nextPage,
|
|
176
216
|
class: () => cn("gap-1 px-2.5 sm:pr-2.5", read(props.class)),
|
|
177
|
-
children: html`<span class="hidden sm:block"
|
|
217
|
+
children: html`<span class="hidden sm:block">${slot(props.children ?? paginationLabels.next)}</span>${ChevronRightIcon({})}`,
|
|
178
218
|
}),
|
|
179
219
|
);
|
|
180
220
|
|
|
181
221
|
export interface PaginationEllipsisProps {
|
|
222
|
+
/** The hidden text. Default `"More pages"`. */
|
|
223
|
+
label?: string;
|
|
182
224
|
class?: Reactive<string>;
|
|
183
225
|
}
|
|
184
226
|
|
|
@@ -188,5 +230,5 @@ export const PaginationEllipsis = component<PaginationEllipsisProps>(
|
|
|
188
230
|
data-slot="pagination-ellipsis"
|
|
189
231
|
aria-hidden="true"
|
|
190
232
|
class="${() => cn("flex size-9 items-center justify-center", read(props.class))}"
|
|
191
|
-
>${MoreHorizontalIcon({ class: "size-4" })}<span class="sr-only"
|
|
233
|
+
>${MoreHorizontalIcon({ class: "size-4" })}<span class="sr-only">${props.label ?? paginationLabels.morePages}</span></span>`,
|
|
192
234
|
);
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PieceMap — a transfer drawn as one small square per piece.
|
|
3
|
+
*
|
|
4
|
+
* What a torrent client shows under a download: each square is a piece of the
|
|
5
|
+
* whole, coloured by where it stands — here, missing, on its way, taken from a
|
|
6
|
+
* peer. A progress bar says how much; the map says *which*, and that is what
|
|
7
|
+
* a stalled run, a missing layer or a peer serving one half shows at a glance.
|
|
8
|
+
*
|
|
9
|
+
* The states are the caller's, not a fixed set. A download, a replication and
|
|
10
|
+
* a backup do not have the same ones, so the component takes a string type of
|
|
11
|
+
* its own and a class per state — `tones` — and paints nothing it was not
|
|
12
|
+
* told about. The legend reads the same `tones`, so a square and its key can
|
|
13
|
+
* never drift apart.
|
|
14
|
+
*
|
|
15
|
+
* Pieces come in groups: each group after the first is set off by a rule — a
|
|
16
|
+
* torrent's files, an image's layers. A flat map is one group.
|
|
17
|
+
*
|
|
18
|
+
* A generic function rather than `component<P>`, as DataTable: `State` has to
|
|
19
|
+
* stay open so `tones` is checked against the caller's own states.
|
|
20
|
+
*
|
|
21
|
+
* With a `label`, the map is one image to assistive technology and the label
|
|
22
|
+
* is what it says ("12 of 40 pieces"): a screen reader walking hundreds of
|
|
23
|
+
* squares one by one learns nothing the sentence does not. Each square keeps
|
|
24
|
+
* its `title` for the pointer.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { html, type TemplateResult } from "@c9up/aurora";
|
|
28
|
+
import type { Child } from "../lib/children.js";
|
|
29
|
+
import { cn } from "../lib/cn.js";
|
|
30
|
+
import { cva, type VariantProps } from "../lib/cva.js";
|
|
31
|
+
import { type Reactive, read } from "../lib/props.js";
|
|
32
|
+
|
|
33
|
+
export const pieceVariants = cva("inline-block shrink-0 rounded-[2px]", {
|
|
34
|
+
variants: {
|
|
35
|
+
size: {
|
|
36
|
+
sm: "size-2",
|
|
37
|
+
default: "size-2.5",
|
|
38
|
+
lg: "size-3",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
defaultVariants: { size: "default" },
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export type PieceVariants = VariantProps<typeof pieceVariants>;
|
|
45
|
+
|
|
46
|
+
export interface Piece<State extends string> {
|
|
47
|
+
state: State;
|
|
48
|
+
/** The square's tooltip: which piece, how big, from where. */
|
|
49
|
+
title?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface PieceMapProps<State extends string> {
|
|
53
|
+
/**
|
|
54
|
+
* The pieces, group after group, or an accessor for pieces that change: the
|
|
55
|
+
* squares are drawn again whenever what it reads changes.
|
|
56
|
+
*/
|
|
57
|
+
groups: Reactive<readonly (readonly Piece<State>[])[]>;
|
|
58
|
+
/** The classes that paint each state: a background, a border, a pulse. */
|
|
59
|
+
tones: Readonly<Record<State, string>>;
|
|
60
|
+
size?: Reactive<PieceVariants["size"]>;
|
|
61
|
+
/** What the map says as a whole. Makes it one image; see above. */
|
|
62
|
+
label?: Reactive<string | undefined>;
|
|
63
|
+
class?: Reactive<string>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function PieceMap<State extends string>(
|
|
67
|
+
props: PieceMapProps<State>,
|
|
68
|
+
): TemplateResult {
|
|
69
|
+
return html`<div
|
|
70
|
+
data-slot="piece-map"
|
|
71
|
+
role="${() => (read(props.label) === undefined ? undefined : "img")}"
|
|
72
|
+
aria-label="${() => read(props.label)}"
|
|
73
|
+
class="${() => cn("flex flex-wrap gap-1", read(props.class))}"
|
|
74
|
+
>
|
|
75
|
+
${() =>
|
|
76
|
+
read(props.groups).map(
|
|
77
|
+
(pieces, index) => html`<span
|
|
78
|
+
data-slot="piece-map-group"
|
|
79
|
+
class="${cn("flex flex-wrap gap-0.5", index > 0 && "border-border border-s ps-1")}"
|
|
80
|
+
>
|
|
81
|
+
${pieces.map(
|
|
82
|
+
(piece) => html`<span
|
|
83
|
+
data-slot="piece"
|
|
84
|
+
data-state="${piece.state}"
|
|
85
|
+
title="${piece.title}"
|
|
86
|
+
class="${cn(pieceVariants({ size: read(props.size) }), props.tones[piece.state])}"
|
|
87
|
+
></span>`,
|
|
88
|
+
)}
|
|
89
|
+
</span>`,
|
|
90
|
+
)}
|
|
91
|
+
</div>`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface PieceMapLegendItem<State extends string> {
|
|
95
|
+
state: State;
|
|
96
|
+
label: Child;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface PieceMapLegendProps<State extends string> {
|
|
100
|
+
/** The same `tones` as the map's. */
|
|
101
|
+
tones: Readonly<Record<State, string>>;
|
|
102
|
+
/** The states to explain, in the order they are read. */
|
|
103
|
+
items: readonly PieceMapLegendItem<State>[];
|
|
104
|
+
/** Said before the keys — the size of the whole, say. */
|
|
105
|
+
children?: Child;
|
|
106
|
+
size?: Reactive<PieceVariants["size"]>;
|
|
107
|
+
class?: Reactive<string>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** What the squares' colours mean. */
|
|
111
|
+
export function PieceMapLegend<State extends string>(
|
|
112
|
+
props: PieceMapLegendProps<State>,
|
|
113
|
+
): TemplateResult {
|
|
114
|
+
// A space after each key: the gap between them is only drawn, and without
|
|
115
|
+
// one their labels run together for a screen reader and a copy.
|
|
116
|
+
return html`<p
|
|
117
|
+
data-slot="piece-map-legend"
|
|
118
|
+
class="${() =>
|
|
119
|
+
cn(
|
|
120
|
+
"text-muted-foreground flex flex-wrap gap-x-4 gap-y-1 text-xs",
|
|
121
|
+
read(props.class),
|
|
122
|
+
)}"
|
|
123
|
+
>
|
|
124
|
+
${props.children}
|
|
125
|
+
${props.items.map(
|
|
126
|
+
(item) => html`<span class="inline-flex items-center gap-1.5"
|
|
127
|
+
><span
|
|
128
|
+
aria-hidden="true"
|
|
129
|
+
data-state="${item.state}"
|
|
130
|
+
class="${() => cn(pieceVariants({ size: read(props.size) }), props.tones[item.state])}"
|
|
131
|
+
></span
|
|
132
|
+
>${item.label}</span
|
|
133
|
+
> `,
|
|
134
|
+
)}
|
|
135
|
+
</p>`;
|
|
136
|
+
}
|
|
@@ -131,6 +131,8 @@ export const ResizablePanel = component<ResizablePanelProps>((props) => {
|
|
|
131
131
|
export interface ResizableHandleProps {
|
|
132
132
|
/** Show the grip dots. */
|
|
133
133
|
withHandle?: boolean;
|
|
134
|
+
/** The separator's accessible name. Default `"Resize panes"`. */
|
|
135
|
+
label?: string;
|
|
134
136
|
class?: Reactive<string>;
|
|
135
137
|
}
|
|
136
138
|
|
|
@@ -205,7 +207,7 @@ export const ResizableHandle = component<ResizableHandleProps>((props) => {
|
|
|
205
207
|
aria-valuemin="${group.min}"
|
|
206
208
|
aria-valuemax="${group.max}"
|
|
207
209
|
aria-valuenow="${() => Math.round(group.size())}"
|
|
208
|
-
aria-label="Resize panes"
|
|
210
|
+
aria-label="${props.label ?? "Resize panes"}"
|
|
209
211
|
class="${() =>
|
|
210
212
|
cn(
|
|
211
213
|
"bg-border relative flex shrink-0 items-center justify-center outline-none",
|
package/src/molecules/index.ts
CHANGED
|
@@ -42,10 +42,12 @@ export {
|
|
|
42
42
|
export {
|
|
43
43
|
Breadcrumb,
|
|
44
44
|
BreadcrumbEllipsis,
|
|
45
|
+
type BreadcrumbEllipsisProps,
|
|
45
46
|
BreadcrumbItem,
|
|
46
47
|
BreadcrumbLink,
|
|
47
48
|
type BreadcrumbLinkProps,
|
|
48
49
|
BreadcrumbList,
|
|
50
|
+
type BreadcrumbNavProps,
|
|
49
51
|
BreadcrumbPage,
|
|
50
52
|
type BreadcrumbProps,
|
|
51
53
|
BreadcrumbSeparator,
|
|
@@ -153,8 +155,10 @@ export {
|
|
|
153
155
|
PaginationEllipsis,
|
|
154
156
|
type PaginationEllipsisProps,
|
|
155
157
|
PaginationItem,
|
|
158
|
+
type PaginationLabels,
|
|
156
159
|
PaginationLink,
|
|
157
160
|
type PaginationLinkProps,
|
|
161
|
+
type PaginationNavProps,
|
|
158
162
|
PaginationNext,
|
|
159
163
|
PaginationPrevious,
|
|
160
164
|
type PaginationProps,
|
|
@@ -162,6 +166,16 @@ export {
|
|
|
162
166
|
pageWindow,
|
|
163
167
|
} from "./Pagination.js";
|
|
164
168
|
export { Picture, type PictureProps } from "./Picture.js";
|
|
169
|
+
export {
|
|
170
|
+
type Piece,
|
|
171
|
+
PieceMap,
|
|
172
|
+
PieceMapLegend,
|
|
173
|
+
type PieceMapLegendItem,
|
|
174
|
+
type PieceMapLegendProps,
|
|
175
|
+
type PieceMapProps,
|
|
176
|
+
type PieceVariants,
|
|
177
|
+
pieceVariants,
|
|
178
|
+
} from "./PieceMap.js";
|
|
165
179
|
export {
|
|
166
180
|
RadioGroup,
|
|
167
181
|
RadioGroupItem,
|
|
@@ -37,6 +37,19 @@ export interface DateRange {
|
|
|
37
37
|
readonly to?: Date;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* The words the calendar writes itself — react-day-picker's `labels`.
|
|
42
|
+
*
|
|
43
|
+
* Month and weekday names come from `Intl` in `locale`; these two do not, and
|
|
44
|
+
* a screen reader would read them in English in the middle of a French page.
|
|
45
|
+
*/
|
|
46
|
+
export interface CalendarLabels {
|
|
47
|
+
/** The previous-month arrow. Default `"Previous month"`. */
|
|
48
|
+
previousMonth: string;
|
|
49
|
+
/** The next-month arrow. Default `"Next month"`. */
|
|
50
|
+
nextMonth: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
40
53
|
export interface CalendarProps {
|
|
41
54
|
/**
|
|
42
55
|
* `"range"` picks a span in two clicks. Default `"single"`.
|
|
@@ -63,6 +76,7 @@ export interface CalendarProps {
|
|
|
63
76
|
/** `0` Sunday, `1` Monday. Defaults to the locale's own first day. */
|
|
64
77
|
weekStartsOn?: number;
|
|
65
78
|
locale?: string;
|
|
79
|
+
labels?: Partial<CalendarLabels>;
|
|
66
80
|
class?: Reactive<string>;
|
|
67
81
|
/** `"single"` mode. */
|
|
68
82
|
onValueChange?: (date: Date) => void;
|
|
@@ -374,7 +388,7 @@ export const Calendar = component<CalendarProps>((props) => {
|
|
|
374
388
|
<div class="flex items-center justify-between pb-4">
|
|
375
389
|
<button
|
|
376
390
|
type="button"
|
|
377
|
-
aria-label="Previous month"
|
|
391
|
+
aria-label="${props.labels?.previousMonth ?? "Previous month"}"
|
|
378
392
|
class="${buttonVariants({ variant: "outline", size: "icon", class: "size-7" })}"
|
|
379
393
|
@click="${() => month(addMonths(month(), -1))}"
|
|
380
394
|
>${ChevronLeftIcon({ class: "size-4" })}</button>
|
|
@@ -383,7 +397,7 @@ export const Calendar = component<CalendarProps>((props) => {
|
|
|
383
397
|
</div>
|
|
384
398
|
<button
|
|
385
399
|
type="button"
|
|
386
|
-
aria-label="Next month"
|
|
400
|
+
aria-label="${props.labels?.nextMonth ?? "Next month"}"
|
|
387
401
|
class="${buttonVariants({ variant: "outline", size: "icon", class: "size-7" })}"
|
|
388
402
|
@click="${() => month(addMonths(month(), 1))}"
|
|
389
403
|
>${ChevronRightIcon({ class: "size-4" })}</button>
|
|
@@ -52,6 +52,8 @@ const CarouselContext = createContext<CarouselApi>("Carousel");
|
|
|
52
52
|
export interface CarouselProps {
|
|
53
53
|
/** Announced before the slides. */
|
|
54
54
|
label?: string;
|
|
55
|
+
/** What a screen reader calls the region. Default `"carousel"`. */
|
|
56
|
+
roleDescription?: string;
|
|
55
57
|
orientation?: "horizontal" | "vertical";
|
|
56
58
|
class?: Reactive<string>;
|
|
57
59
|
children?: Parts;
|
|
@@ -138,7 +140,7 @@ export const Carousel = component<CarouselProps>((props) => {
|
|
|
138
140
|
return html`<div
|
|
139
141
|
data-slot="carousel"
|
|
140
142
|
role="region"
|
|
141
|
-
aria-roledescription="carousel"
|
|
143
|
+
aria-roledescription="${props.roleDescription ?? "carousel"}"
|
|
142
144
|
aria-label="${props.label ?? "Carousel"}"
|
|
143
145
|
class="${() => cn("relative", read(props.class))}"
|
|
144
146
|
@keydown="${onKeyDown}"
|
|
@@ -168,6 +170,10 @@ export const CarouselContent = component<CarouselContentProps>((props) => {
|
|
|
168
170
|
|
|
169
171
|
export interface CarouselItemProps {
|
|
170
172
|
children?: Slot;
|
|
173
|
+
/** What a screen reader calls one slide. Default `"slide"`. */
|
|
174
|
+
roleDescription?: string;
|
|
175
|
+
/** The slide's name from its position. Default `"3 of 7"`. */
|
|
176
|
+
label?: (position: number, count: number) => string;
|
|
171
177
|
class?: Reactive<string>;
|
|
172
178
|
}
|
|
173
179
|
|
|
@@ -184,14 +190,20 @@ export const CarouselItem = component<CarouselItemProps>((props) => {
|
|
|
184
190
|
return html`<div
|
|
185
191
|
data-slot="carousel-item"
|
|
186
192
|
role="group"
|
|
187
|
-
aria-roledescription="slide"
|
|
188
|
-
aria-label="${() =>
|
|
193
|
+
aria-roledescription="${props.roleDescription ?? "slide"}"
|
|
194
|
+
aria-label="${() => (props.label ?? slideOf)(position, carousel.slideCount())}"
|
|
189
195
|
class="${() =>
|
|
190
196
|
cn("min-w-0 shrink-0 grow-0 basis-full snap-start", read(props.class))}"
|
|
191
197
|
>${slot(props.children)}</div>`;
|
|
192
198
|
});
|
|
193
199
|
|
|
200
|
+
function slideOf(position: number, count: number): string {
|
|
201
|
+
return `${position} of ${count}`;
|
|
202
|
+
}
|
|
203
|
+
|
|
194
204
|
export interface CarouselButtonProps {
|
|
205
|
+
/** The arrow's accessible name. Default `"Previous slide"` / `"Next slide"`. */
|
|
206
|
+
label?: string;
|
|
195
207
|
class?: Reactive<string>;
|
|
196
208
|
}
|
|
197
209
|
|
|
@@ -202,7 +214,7 @@ export const CarouselPrevious = component<CarouselButtonProps>((props) => {
|
|
|
202
214
|
return html`<button
|
|
203
215
|
type="button"
|
|
204
216
|
data-slot="carousel-previous"
|
|
205
|
-
aria-label="Previous slide"
|
|
217
|
+
aria-label="${props.label ?? "Previous slide"}"
|
|
206
218
|
?disabled="${() => carousel.atStart()}"
|
|
207
219
|
class="${() =>
|
|
208
220
|
cn(
|
|
@@ -222,7 +234,7 @@ export const CarouselNext = component<CarouselButtonProps>((props) => {
|
|
|
222
234
|
return html`<button
|
|
223
235
|
type="button"
|
|
224
236
|
data-slot="carousel-next"
|
|
225
|
-
aria-label="Next slide"
|
|
237
|
+
aria-label="${props.label ?? "Next slide"}"
|
|
226
238
|
?disabled="${() => carousel.atEnd()}"
|
|
227
239
|
class="${() =>
|
|
228
240
|
cn(
|
|
@@ -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
|
});
|