@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
|
@@ -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>
|
|
@@ -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
|
|
package/src/organisms/Select.ts
CHANGED
|
@@ -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:
|
|
@@ -42,12 +51,16 @@
|
|
|
42
51
|
import {
|
|
43
52
|
component,
|
|
44
53
|
createContext,
|
|
54
|
+
effect,
|
|
45
55
|
html,
|
|
46
56
|
inject,
|
|
57
|
+
onMount,
|
|
47
58
|
onUnmount,
|
|
48
59
|
provide,
|
|
60
|
+
render,
|
|
49
61
|
signal,
|
|
50
62
|
type TemplateResult,
|
|
63
|
+
untrack,
|
|
51
64
|
} from "@c9up/aurora";
|
|
52
65
|
import type { Child, Parts, Slot } from "../lib/children.js";
|
|
53
66
|
import { slot } from "../lib/children.js";
|
|
@@ -55,7 +68,7 @@ import { cn } from "../lib/cn.js";
|
|
|
55
68
|
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "../lib/icons.js";
|
|
56
69
|
import { uid } from "../lib/id.js";
|
|
57
70
|
import { slideInFromSide, zoomInOut } from "../lib/motion.js";
|
|
58
|
-
import { type Reactive, read, readOr } from "../lib/props.js";
|
|
71
|
+
import { accessor, type Reactive, read, readOr } from "../lib/props.js";
|
|
59
72
|
import { controllable } from "../primitives/controllable.js";
|
|
60
73
|
import type { Align, Placement, Side } from "../primitives/floating.js";
|
|
61
74
|
import { floatingSurface } from "../primitives/floatingSurface.js";
|
|
@@ -91,7 +104,12 @@ interface RegisteredContent {
|
|
|
91
104
|
}
|
|
92
105
|
|
|
93
106
|
interface SelectApi {
|
|
94
|
-
|
|
107
|
+
/**
|
|
108
|
+
* The trigger's id: the one it was given, or one minted here. Claimed as the
|
|
109
|
+
* trigger is built, which is before anything that reads it — the anchor,
|
|
110
|
+
* the list's `aria-labelledby`, the focus return — first runs.
|
|
111
|
+
*/
|
|
112
|
+
claimTriggerId(id: string | undefined): string;
|
|
95
113
|
readonly listId: string;
|
|
96
114
|
readonly open: () => boolean;
|
|
97
115
|
readonly value: () => string | undefined;
|
|
@@ -108,6 +126,12 @@ interface SelectApi {
|
|
|
108
126
|
setActive(value: string | undefined): void;
|
|
109
127
|
onTriggerKeyDown(event: KeyboardEvent): void;
|
|
110
128
|
registerItem(item: RegisteredItem): void;
|
|
129
|
+
/**
|
|
130
|
+
* An option's element is in a mounted list; the returned function says it
|
|
131
|
+
* left. Counted, because the list can be mounted twice for a moment — the
|
|
132
|
+
* closing panel still fading out, the closed copy already in place.
|
|
133
|
+
*/
|
|
134
|
+
attachItem(value: string): () => void;
|
|
111
135
|
registerContent(content: RegisteredContent): void;
|
|
112
136
|
}
|
|
113
137
|
|
|
@@ -126,9 +150,25 @@ export interface SelectProps {
|
|
|
126
150
|
}
|
|
127
151
|
|
|
128
152
|
export const Select = component<SelectProps>((props) => {
|
|
129
|
-
|
|
153
|
+
let triggerId = uid("select-trigger");
|
|
130
154
|
const listId = uid("select-list");
|
|
131
|
-
|
|
155
|
+
/** What each value's option is called, latest registration first. */
|
|
156
|
+
const registry = new Map<string, RegisteredItem>();
|
|
157
|
+
/** Moves whenever an option registers, so the chosen label follows. */
|
|
158
|
+
const revision = signal(0);
|
|
159
|
+
/** How many mounted lists hold each value's option. */
|
|
160
|
+
const attached = new Map<string, number>();
|
|
161
|
+
/** Whether a list has been mounted at all — never, on the server. */
|
|
162
|
+
let mountedOnce = false;
|
|
163
|
+
// Untracked read: called while the accessor building an option runs, and
|
|
164
|
+
// reading the counter there would make that accessor re-run on every change.
|
|
165
|
+
const bump = (): void => {
|
|
166
|
+
revision(untrack(() => revision()) + 1);
|
|
167
|
+
};
|
|
168
|
+
/** The open panel, once it has rendered. */
|
|
169
|
+
let panel: HTMLElement | null = null;
|
|
170
|
+
/** Where the list is mounted while closed — outside the document. */
|
|
171
|
+
let closedHost: HTMLElement | null = null;
|
|
132
172
|
/** Per instance, not per module: two selects may offer the same value. */
|
|
133
173
|
const optionIds = new Map<string, string>();
|
|
134
174
|
let content: RegisteredContent | undefined;
|
|
@@ -144,8 +184,26 @@ export const Select = component<SelectProps>((props) => {
|
|
|
144
184
|
/** The option the keyboard is on. Distinct from the selected one. */
|
|
145
185
|
const active = signal<string | undefined>(undefined);
|
|
146
186
|
|
|
187
|
+
/**
|
|
188
|
+
* The options the list holds now, in its order. Read from the mounted list,
|
|
189
|
+
* which is what drops an option a signal removed and places one it added;
|
|
190
|
+
* before anything is mounted (on the server), in registration order.
|
|
191
|
+
*/
|
|
192
|
+
function items(): readonly RegisteredItem[] {
|
|
193
|
+
const root = open() && panel?.isConnected === true ? panel : closedHost;
|
|
194
|
+
if (root === null) return [...registry.values()];
|
|
195
|
+
const out: RegisteredItem[] = [];
|
|
196
|
+
for (const element of root.querySelectorAll<HTMLElement>(
|
|
197
|
+
"[data-slot=select-item]",
|
|
198
|
+
)) {
|
|
199
|
+
const item = registry.get(element.dataset.value ?? "");
|
|
200
|
+
if (item !== undefined && item.id === element.id) out.push(item);
|
|
201
|
+
}
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
|
|
147
205
|
const enabled = (): readonly RegisteredItem[] =>
|
|
148
|
-
items.filter((item) => !item.disabled);
|
|
206
|
+
items().filter((item) => !item.disabled);
|
|
149
207
|
|
|
150
208
|
function choose(value: string): void {
|
|
151
209
|
selection.set(value);
|
|
@@ -235,7 +293,10 @@ export const Select = component<SelectProps>((props) => {
|
|
|
235
293
|
}
|
|
236
294
|
|
|
237
295
|
provide<SelectApi>(SelectContext, {
|
|
238
|
-
|
|
296
|
+
claimTriggerId(id) {
|
|
297
|
+
if (id !== undefined) triggerId = id;
|
|
298
|
+
return triggerId;
|
|
299
|
+
},
|
|
239
300
|
listId,
|
|
240
301
|
open: () => open(),
|
|
241
302
|
value: () => selection.current(),
|
|
@@ -243,8 +304,15 @@ export const Select = component<SelectProps>((props) => {
|
|
|
243
304
|
disabled: () => readOr(props.disabled, false),
|
|
244
305
|
invalid: () => read(props.invalid) === true,
|
|
245
306
|
required: props.required === true,
|
|
246
|
-
chosenLabel: () =>
|
|
247
|
-
|
|
307
|
+
chosenLabel: () => {
|
|
308
|
+
revision();
|
|
309
|
+
const current = selection.current();
|
|
310
|
+
if (current === undefined) return undefined;
|
|
311
|
+
// An option a signal removed keeps its registration, but not its
|
|
312
|
+
// place in a list: its label must not stay on the trigger.
|
|
313
|
+
if (mountedOnce && !attached.has(current)) return undefined;
|
|
314
|
+
return registry.get(current)?.textValue;
|
|
315
|
+
},
|
|
248
316
|
itemId(value) {
|
|
249
317
|
let id = optionIds.get(value);
|
|
250
318
|
if (id === undefined) {
|
|
@@ -261,7 +329,19 @@ export const Select = component<SelectProps>((props) => {
|
|
|
261
329
|
setActive: (value) => active(value),
|
|
262
330
|
onTriggerKeyDown,
|
|
263
331
|
registerItem(item) {
|
|
264
|
-
|
|
332
|
+
registry.set(item.value, item);
|
|
333
|
+
bump();
|
|
334
|
+
},
|
|
335
|
+
attachItem(value) {
|
|
336
|
+
mountedOnce = true;
|
|
337
|
+
attached.set(value, (attached.get(value) ?? 0) + 1);
|
|
338
|
+
bump();
|
|
339
|
+
return () => {
|
|
340
|
+
const left = (attached.get(value) ?? 1) - 1;
|
|
341
|
+
if (left > 0) attached.set(value, left);
|
|
342
|
+
else attached.delete(value);
|
|
343
|
+
bump();
|
|
344
|
+
};
|
|
265
345
|
},
|
|
266
346
|
registerContent(registered) {
|
|
267
347
|
content = registered;
|
|
@@ -288,7 +368,32 @@ export const Select = component<SelectProps>((props) => {
|
|
|
288
368
|
// Focus never enters the panel — the listbox pattern keeps it on the
|
|
289
369
|
// trigger — so nothing here traps or moves it.
|
|
290
370
|
content: () => renderList(registered, { listId, triggerId }),
|
|
291
|
-
onOpened:
|
|
371
|
+
onOpened: (element) => {
|
|
372
|
+
panel = element;
|
|
373
|
+
scrollActiveIntoView(element);
|
|
374
|
+
},
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
onMount(() => {
|
|
378
|
+
let unmountClosed: (() => void) | null = null;
|
|
379
|
+
const stop = effect(() => {
|
|
380
|
+
if (open()) {
|
|
381
|
+
unmountClosed?.();
|
|
382
|
+
unmountClosed = null;
|
|
383
|
+
closedHost = null;
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (unmountClosed !== null) return;
|
|
387
|
+
const host = document.createElement("div");
|
|
388
|
+
// Untracked: what the options read belongs to their own bindings,
|
|
389
|
+
// not to this effect, which only follows `open`.
|
|
390
|
+
unmountClosed = untrack(() => render(html`${registered.body}`, host));
|
|
391
|
+
closedHost = host;
|
|
392
|
+
});
|
|
393
|
+
return () => {
|
|
394
|
+
stop();
|
|
395
|
+
unmountClosed?.();
|
|
396
|
+
};
|
|
292
397
|
});
|
|
293
398
|
}
|
|
294
399
|
|
|
@@ -301,7 +406,7 @@ export const Select = component<SelectProps>((props) => {
|
|
|
301
406
|
function scrollActiveIntoView(panel: HTMLElement): void {
|
|
302
407
|
const current = active() ?? selection.current();
|
|
303
408
|
if (current === undefined) return;
|
|
304
|
-
const id =
|
|
409
|
+
const id = registry.get(current)?.id;
|
|
305
410
|
if (id === undefined) return;
|
|
306
411
|
panel
|
|
307
412
|
.querySelector(`#${CSS.escape(id)}`)
|
|
@@ -318,9 +423,19 @@ export const Select = component<SelectProps>((props) => {
|
|
|
318
423
|
/></div>`;
|
|
319
424
|
});
|
|
320
425
|
|
|
426
|
+
/**
|
|
427
|
+
* `id`, `label` and `describedBy` as on `Input`: upstream's trigger takes every
|
|
428
|
+
* button prop, and these are the ones that name it — a `FieldLabel` points its
|
|
429
|
+
* `for` at the `id`, and a `<label for>` names a `<button>`. Without them the
|
|
430
|
+
* combobox's only name was the value it showed.
|
|
431
|
+
*/
|
|
321
432
|
export interface SelectTriggerProps {
|
|
322
433
|
children?: Slot;
|
|
323
434
|
size?: "default" | "sm";
|
|
435
|
+
id?: string;
|
|
436
|
+
/** Accessible name (`aria-label`), for a select no `<label>` names. */
|
|
437
|
+
label?: Reactive<string | undefined>;
|
|
438
|
+
describedBy?: Reactive<string | undefined>;
|
|
324
439
|
class?: Reactive<string>;
|
|
325
440
|
}
|
|
326
441
|
|
|
@@ -329,7 +444,9 @@ export const SelectTrigger = component<SelectTriggerProps>((props) => {
|
|
|
329
444
|
return html`<button
|
|
330
445
|
type="button"
|
|
331
446
|
data-slot="select-trigger"
|
|
332
|
-
id="${select.
|
|
447
|
+
id="${select.claimTriggerId(props.id)}"
|
|
448
|
+
aria-label="${accessor(props.label, undefined)}"
|
|
449
|
+
aria-describedby="${accessor(props.describedBy, undefined)}"
|
|
333
450
|
role="combobox"
|
|
334
451
|
aria-haspopup="listbox"
|
|
335
452
|
aria-expanded="${() => (select.open() ? "true" : "false")}"
|
|
@@ -449,6 +566,10 @@ export const SelectItem = component<SelectItemProps>((props) => {
|
|
|
449
566
|
disabled: props.disabled === true,
|
|
450
567
|
});
|
|
451
568
|
|
|
569
|
+
// On each mount, not once: the same option is mounted again every time the
|
|
570
|
+
// list opens or closes, and unmounted when a signal drops it.
|
|
571
|
+
onMount(() => select.attachItem(props.value));
|
|
572
|
+
|
|
452
573
|
const chosen = (): boolean => select.value() === props.value;
|
|
453
574
|
return html`<div
|
|
454
575
|
data-slot="select-item"
|
package/src/organisms/Sheet.ts
CHANGED
|
@@ -51,6 +51,7 @@ interface RegisteredContent {
|
|
|
51
51
|
readonly body: Child;
|
|
52
52
|
readonly side: Side;
|
|
53
53
|
readonly showCloseButton: boolean;
|
|
54
|
+
readonly closeLabel: string;
|
|
54
55
|
readonly class?: Reactive<string>;
|
|
55
56
|
}
|
|
56
57
|
|
|
@@ -197,6 +198,8 @@ export interface SheetContentProps {
|
|
|
197
198
|
/** Which edge it comes from. Default `"right"`. */
|
|
198
199
|
side?: Side;
|
|
199
200
|
showCloseButton?: boolean;
|
|
201
|
+
/** The corner cross's accessible name. Default `"Close"`. */
|
|
202
|
+
closeLabel?: string;
|
|
200
203
|
class?: Reactive<string>;
|
|
201
204
|
}
|
|
202
205
|
|
|
@@ -216,6 +219,7 @@ export const SheetContent = component<SheetContentProps>((props) => {
|
|
|
216
219
|
body,
|
|
217
220
|
side: props.side ?? "right",
|
|
218
221
|
showCloseButton: props.showCloseButton ?? true,
|
|
222
|
+
closeLabel: props.closeLabel ?? "Close",
|
|
219
223
|
class: props.class,
|
|
220
224
|
});
|
|
221
225
|
return html``;
|
|
@@ -289,7 +293,7 @@ function renderSurface(
|
|
|
289
293
|
data-slot="sheet-close"
|
|
290
294
|
class="${closeButtonClasses}"
|
|
291
295
|
@click="${() => ids.close()}"
|
|
292
|
-
>${XIcon({ class: "size-4" })}<span class="sr-only"
|
|
296
|
+
>${XIcon({ class: "size-4" })}<span class="sr-only">${registered.closeLabel}</span></button>`
|
|
293
297
|
: null;
|
|
294
298
|
return html`<div data-slot="sheet-portal" class="${cn("fixed inset-0 z-50", fadeInOut)}">
|
|
295
299
|
<div data-slot="sheet-overlay" class="${dialogBackdropClasses}"></div>
|
package/src/organisms/Sidebar.ts
CHANGED
|
@@ -175,6 +175,8 @@ export interface SidebarProps {
|
|
|
175
175
|
collapsible?: "icon" | "offcanvas" | "none";
|
|
176
176
|
/** Announced as the navigation landmark's name. */
|
|
177
177
|
label?: string;
|
|
178
|
+
/** The close cross of the sheet it turns into on mobile. Default `"Close"`. */
|
|
179
|
+
closeLabel?: string;
|
|
178
180
|
class?: Reactive<string>;
|
|
179
181
|
}
|
|
180
182
|
|
|
@@ -192,6 +194,7 @@ export const Sidebar = component<SidebarProps>((props) => {
|
|
|
192
194
|
children: () =>
|
|
193
195
|
SheetContent({
|
|
194
196
|
side,
|
|
197
|
+
closeLabel: props.closeLabel,
|
|
195
198
|
class: "bg-sidebar text-sidebar-foreground w-[18rem] p-0",
|
|
196
199
|
children: () =>
|
|
197
200
|
html`${SheetHeader({
|
|
@@ -210,7 +213,11 @@ export const Sidebar = component<SidebarProps>((props) => {
|
|
|
210
213
|
data-slot="sidebar"
|
|
211
214
|
data-state="${() => sidebar.state()}"
|
|
212
215
|
data-side="${side}"
|
|
213
|
-
data-collapsible="${
|
|
216
|
+
data-collapsible="${() =>
|
|
217
|
+
// The mode only once collapsed, as upstream: every
|
|
218
|
+
// `group-data-[collapsible=icon]:` class keys off it, and set
|
|
219
|
+
// while expanded it squeezed the full-width bar to icons.
|
|
220
|
+
sidebar.state() === "collapsed" ? collapsible : ""}"
|
|
214
221
|
aria-label="${props.label ?? "Sidebar"}"
|
|
215
222
|
class="${() =>
|
|
216
223
|
cn(
|
|
@@ -234,6 +241,8 @@ export const Sidebar = component<SidebarProps>((props) => {
|
|
|
234
241
|
export interface SidebarTriggerProps {
|
|
235
242
|
/** Overrides the provider's toggle — for a trigger outside the shell. */
|
|
236
243
|
onToggle?: () => void;
|
|
244
|
+
/** The button's accessible name. Default `"Toggle sidebar"`. */
|
|
245
|
+
label?: string;
|
|
237
246
|
class?: Reactive<string>;
|
|
238
247
|
}
|
|
239
248
|
|
|
@@ -241,7 +250,7 @@ export const SidebarTrigger = component<SidebarTriggerProps>((props) =>
|
|
|
241
250
|
Button({
|
|
242
251
|
variant: "ghost",
|
|
243
252
|
size: "icon",
|
|
244
|
-
label: "Toggle sidebar",
|
|
253
|
+
label: props.label ?? "Toggle sidebar",
|
|
245
254
|
class: () => cn("size-7", read(props.class)),
|
|
246
255
|
onClick: () => {
|
|
247
256
|
if (props.onToggle !== undefined) {
|
|
@@ -255,6 +264,8 @@ export const SidebarTrigger = component<SidebarTriggerProps>((props) =>
|
|
|
255
264
|
);
|
|
256
265
|
|
|
257
266
|
export interface SidebarRailProps {
|
|
267
|
+
/** Accessible name and tooltip. Default `"Toggle sidebar"`. */
|
|
268
|
+
label?: string;
|
|
258
269
|
class?: Reactive<string>;
|
|
259
270
|
}
|
|
260
271
|
|
|
@@ -270,9 +281,9 @@ export const SidebarRail = component<SidebarRailProps>(
|
|
|
270
281
|
(props) => html`<button
|
|
271
282
|
type="button"
|
|
272
283
|
data-slot="sidebar-rail"
|
|
273
|
-
aria-label="Toggle sidebar"
|
|
284
|
+
aria-label="${props.label ?? "Toggle sidebar"}"
|
|
274
285
|
tabindex="-1"
|
|
275
|
-
title="Toggle sidebar"
|
|
286
|
+
title="${props.label ?? "Toggle sidebar"}"
|
|
276
287
|
class="${() =>
|
|
277
288
|
cn(
|
|
278
289
|
"hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex",
|
package/src/organisms/Toaster.ts
CHANGED
|
@@ -327,6 +327,8 @@ const variantClasses: Record<ToastVariant, string> = {
|
|
|
327
327
|
export interface ToasterProps {
|
|
328
328
|
/** Which corner. Default `"bottom-right"`. */
|
|
329
329
|
position?: "top-right" | "top-left" | "bottom-right" | "bottom-left";
|
|
330
|
+
/** The dismiss cross's accessible name, as sonner names the prop. */
|
|
331
|
+
closeButtonAriaLabel?: string;
|
|
330
332
|
class?: Reactive<string>;
|
|
331
333
|
}
|
|
332
334
|
|
|
@@ -346,6 +348,8 @@ const positionClasses: Record<NonNullable<ToasterProps["position"]>, string> = {
|
|
|
346
348
|
*/
|
|
347
349
|
export const Toaster = component<ToasterProps>((props) => {
|
|
348
350
|
const position = props.position ?? "bottom-right";
|
|
351
|
+
const closeLabel = props.closeButtonAriaLabel ?? "Dismiss notification";
|
|
352
|
+
const render = (entry: ActiveToast): Child => renderToast(entry, closeLabel);
|
|
349
353
|
|
|
350
354
|
return html`<div
|
|
351
355
|
data-slot="toaster"
|
|
@@ -363,18 +367,18 @@ export const Toaster = component<ToasterProps>((props) => {
|
|
|
363
367
|
${() =>
|
|
364
368
|
queue()
|
|
365
369
|
.filter((entry) => entry.variant !== "error")
|
|
366
|
-
.map(
|
|
370
|
+
.map(render)}
|
|
367
371
|
</div>
|
|
368
372
|
<div role="alert" aria-live="assertive" aria-atomic="false" class="contents">
|
|
369
373
|
${() =>
|
|
370
374
|
queue()
|
|
371
375
|
.filter((entry) => entry.variant === "error")
|
|
372
|
-
.map(
|
|
376
|
+
.map(render)}
|
|
373
377
|
</div>
|
|
374
378
|
</div>`;
|
|
375
379
|
});
|
|
376
380
|
|
|
377
|
-
function renderToast(entry: ActiveToast): Child {
|
|
381
|
+
function renderToast(entry: ActiveToast, closeLabel: string): Child {
|
|
378
382
|
return html`<div
|
|
379
383
|
data-slot="toast"
|
|
380
384
|
data-variant="${entry.variant}"
|
|
@@ -412,7 +416,7 @@ function renderToast(entry: ActiveToast): Child {
|
|
|
412
416
|
}
|
|
413
417
|
<button
|
|
414
418
|
type="button"
|
|
415
|
-
aria-label="
|
|
419
|
+
aria-label="${closeLabel}"
|
|
416
420
|
class="opacity-60 transition-opacity hover:opacity-100"
|
|
417
421
|
@click="${() => dismiss(entry.id)}"
|
|
418
422
|
>${XIcon({ class: "size-4" })}</button>
|
package/src/organisms/index.ts
CHANGED
|
@@ -37,6 +37,7 @@ export {
|
|
|
37
37
|
addDays,
|
|
38
38
|
addMonths,
|
|
39
39
|
Calendar,
|
|
40
|
+
type CalendarLabels,
|
|
40
41
|
type CalendarProps,
|
|
41
42
|
type DateRange,
|
|
42
43
|
isSameDay,
|
|
@@ -120,7 +121,12 @@ export {
|
|
|
120
121
|
type ContextMenuTriggerProps,
|
|
121
122
|
} from "./ContextMenu.js";
|
|
122
123
|
export { type Column, DataTable, type DataTableProps } from "./DataTable.js";
|
|
123
|
-
export {
|
|
124
|
+
export {
|
|
125
|
+
DatePicker,
|
|
126
|
+
type DatePickerLabels,
|
|
127
|
+
type DatePickerProps,
|
|
128
|
+
toISODate,
|
|
129
|
+
} from "./DatePicker.js";
|
|
124
130
|
export {
|
|
125
131
|
DateRangePicker,
|
|
126
132
|
type DateRangePickerProps,
|
|
@@ -360,6 +360,32 @@ export interface AutoPositionOptions extends PositionOptions {
|
|
|
360
360
|
onPositioned?: (position: Position) => void;
|
|
361
361
|
}
|
|
362
362
|
|
|
363
|
+
/**
|
|
364
|
+
* The surface's size as laid out, before any transform.
|
|
365
|
+
*
|
|
366
|
+
* `getBoundingClientRect()` includes transforms, and every surface opens under
|
|
367
|
+
* `zoom-in-95`: measured on its first frame it is 5% short, and one placed on
|
|
368
|
+
* the `top` side lands that much too low, over the control that opened it. A
|
|
369
|
+
* transform never changes layout, so the `ResizeObserver` would not correct it
|
|
370
|
+
* afterwards either. floating-ui reads the same two sources in the same order
|
|
371
|
+
* (`getCssDimensions`): the computed size, which keeps sub-pixel widths, and
|
|
372
|
+
* the integer offset size when the two disagree.
|
|
373
|
+
*/
|
|
374
|
+
function layoutRect(element: HTMLElement): Rect {
|
|
375
|
+
const box = element.getBoundingClientRect();
|
|
376
|
+
const css = getComputedStyle(element);
|
|
377
|
+
let width = Number.parseFloat(css.width) || 0;
|
|
378
|
+
let height = Number.parseFloat(css.height) || 0;
|
|
379
|
+
if (
|
|
380
|
+
Math.round(width) !== element.offsetWidth ||
|
|
381
|
+
Math.round(height) !== element.offsetHeight
|
|
382
|
+
) {
|
|
383
|
+
width = element.offsetWidth;
|
|
384
|
+
height = element.offsetHeight;
|
|
385
|
+
}
|
|
386
|
+
return { x: box.x, y: box.y, width, height };
|
|
387
|
+
}
|
|
388
|
+
|
|
363
389
|
export interface AutoPosition {
|
|
364
390
|
/** Recompute and rewrite the styles now. */
|
|
365
391
|
update(): void;
|
|
@@ -390,7 +416,7 @@ export function autoPosition(
|
|
|
390
416
|
floating.style.width = `${anchorRect.width}px`;
|
|
391
417
|
}
|
|
392
418
|
|
|
393
|
-
const floatingRect = floating
|
|
419
|
+
const floatingRect = layoutRect(floating);
|
|
394
420
|
const position = resolvePosition(
|
|
395
421
|
anchorRect,
|
|
396
422
|
floatingRect,
|