@mdbase-dev/ui 0.1.0-beta.155 → 0.1.0-beta.157
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 +1 -1
- package/css/collections.css +5 -100
- package/css/controls.css +35 -36
- package/css/feedback.css +6 -6
- package/css/motion.css +50 -26
- package/css/palette.css +32 -55
- package/css/toast.css +11 -6
- package/css/tokens.css +14 -25
- package/dist/AppSwitcher.js +18 -30
- package/dist/CommandPalette.d.ts +9 -2
- package/dist/CommandPalette.js +203 -167
- package/dist/ConfirmDialog.d.ts +18 -0
- package/dist/ConfirmDialog.js +74 -0
- package/dist/Dialog.d.ts +8 -8
- package/dist/Dialog.js +90 -25
- package/dist/Feedback.js +24 -56
- package/dist/FeedbackMarkup.d.ts +2 -1
- package/dist/FeedbackMarkup.js +9 -2
- package/dist/Menu.d.ts +28 -0
- package/dist/Menu.js +64 -0
- package/dist/Select.js +6 -2
- package/dist/SelectList.js +2 -1
- package/dist/Toaster.d.ts +18 -1
- package/dist/Toaster.js +132 -50
- package/dist/brand.js +5 -3
- package/dist/collections/CollectionSwitcher.d.ts +2 -3
- package/dist/collections/CollectionSwitcher.js +14 -173
- package/dist/collections/copy.js +4 -4
- package/dist/collections/dialogs.d.ts +9 -4
- package/dist/collections/dialogs.js +84 -87
- package/dist/collections/parts.d.ts +0 -9
- package/dist/collections/parts.js +5 -77
- package/dist/locales/de/messages.json +1 -1
- package/dist/locales/en/messages.json +1 -1
- package/dist/locales/es/messages.json +1 -1
- package/dist/locales/fr/messages.json +1 -1
- package/dist/locales/it/messages.json +1 -1
- package/dist/locales/ja/messages.json +1 -1
- package/dist/locales/ko/messages.json +1 -1
- package/dist/locales/pt/messages.json +1 -1
- package/dist/locales/ru/messages.json +1 -1
- package/dist/locales/zh/messages.json +1 -1
- package/dist/overlay.d.ts +4 -0
- package/dist/overlay.js +23 -0
- package/dist/popover.d.ts +6 -1
- package/dist/popover.js +22 -16
- package/package.json +14 -2
package/dist/Dialog.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { type JSX, type ReactNode } from "react";
|
|
2
|
-
|
|
3
|
-
* A modal dialog on the native <dialog>: the browser keeps focus inside it and the page
|
|
4
|
-
* behind it inert. Escape, the close button or a press on the backdrop closes it.
|
|
5
|
-
*/
|
|
6
|
-
export declare function Dialog({ open, onClose, title, className, closeDisabled, children }: {
|
|
1
|
+
import { type JSX, type ReactNode, type RefObject } from "react";
|
|
2
|
+
export declare function Dialog({ open, onClose, title, descriptionId, className, closeDisabled, returnFocusRef, initialFocusRef, role, children }: {
|
|
7
3
|
readonly open: boolean;
|
|
8
4
|
readonly onClose: () => void;
|
|
9
|
-
readonly title:
|
|
5
|
+
readonly title: ReactNode;
|
|
6
|
+
readonly descriptionId?: string | undefined;
|
|
10
7
|
readonly className?: string | undefined;
|
|
11
8
|
readonly closeDisabled?: boolean;
|
|
9
|
+
readonly returnFocusRef?: RefObject<HTMLElement | null> | undefined;
|
|
10
|
+
readonly initialFocusRef?: RefObject<HTMLElement | null> | undefined;
|
|
11
|
+
readonly role?: "dialog" | "alertdialog";
|
|
12
12
|
readonly children: ReactNode;
|
|
13
|
-
}): JSX.Element;
|
|
13
|
+
}): JSX.Element | null;
|
package/dist/Dialog.js
CHANGED
|
@@ -1,54 +1,119 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { i18n as _i18n } from "@lingui/core";
|
|
3
|
+
import { useId, useLayoutEffect, useRef } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
3
5
|
import { useLocaleRevision } from "./i18n.js";
|
|
4
|
-
import {
|
|
5
|
-
/**
|
|
6
|
-
* A modal dialog on the native <dialog>: the browser keeps focus inside it and the page
|
|
7
|
-
* behind it inert. Escape, the close button or a press on the backdrop closes it.
|
|
8
|
-
*/
|
|
6
|
+
import { useOverlay } from "./overlay.js";
|
|
9
7
|
export function Dialog({
|
|
10
8
|
open,
|
|
11
9
|
onClose,
|
|
12
10
|
title,
|
|
11
|
+
descriptionId,
|
|
13
12
|
className,
|
|
14
13
|
closeDisabled = false,
|
|
14
|
+
returnFocusRef,
|
|
15
|
+
initialFocusRef,
|
|
16
|
+
role = "dialog",
|
|
15
17
|
children
|
|
16
18
|
}) {
|
|
17
19
|
useLocaleRevision();
|
|
18
|
-
const
|
|
20
|
+
const {
|
|
21
|
+
ref,
|
|
22
|
+
present
|
|
23
|
+
} = useOverlay(open);
|
|
24
|
+
const invoker = useRef(null);
|
|
25
|
+
const titleId = useId();
|
|
19
26
|
useLayoutEffect(() => {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
const dialog = ref.current;
|
|
28
|
+
if (!dialog || !open || dialog.open) return;
|
|
29
|
+
invoker.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
30
|
+
dialog.showModal();
|
|
31
|
+
const focus = () => {
|
|
32
|
+
const scope = initialFocusRef?.current ?? dialog;
|
|
33
|
+
return scope.querySelector(initialFocusRef ? 'button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex="0"]' : "[data-autofocus]");
|
|
24
34
|
};
|
|
25
|
-
|
|
26
|
-
|
|
35
|
+
const first = focus();
|
|
36
|
+
if (first) first.focus({
|
|
37
|
+
preventScroll: true
|
|
38
|
+
});else if (initialFocusRef) dialog.focus({
|
|
39
|
+
preventScroll: true
|
|
40
|
+
});
|
|
41
|
+
if (!initialFocusRef || first) return;
|
|
42
|
+
const observer = new MutationObserver(() => {
|
|
43
|
+
if (document.activeElement !== dialog) return;
|
|
44
|
+
const control = focus();
|
|
45
|
+
if (control) {
|
|
46
|
+
control.focus({
|
|
47
|
+
preventScroll: true
|
|
48
|
+
});
|
|
49
|
+
observer.disconnect();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
observer.observe(dialog, {
|
|
53
|
+
childList: true,
|
|
54
|
+
subtree: true
|
|
55
|
+
});
|
|
56
|
+
return () => observer.disconnect();
|
|
57
|
+
}, [open, ref, initialFocusRef]);
|
|
27
58
|
useLayoutEffect(() => {
|
|
28
59
|
const dialog = ref.current;
|
|
29
|
-
if (!dialog) return;
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
60
|
+
if (!dialog || !open) return;
|
|
61
|
+
if (closeDisabled && (!dialog.contains(document.activeElement) || document.activeElement?.matches(":disabled"))) dialog.focus({
|
|
62
|
+
preventScroll: true
|
|
63
|
+
});
|
|
64
|
+
if (!closeDisabled && document.activeElement === dialog) dialog.querySelector("[data-autofocus]:not(:disabled)")?.focus({
|
|
65
|
+
preventScroll: true
|
|
66
|
+
});
|
|
67
|
+
}, [closeDisabled, open, ref]);
|
|
68
|
+
useLayoutEffect(() => {
|
|
69
|
+
const dialog = ref.current;
|
|
70
|
+
return () => {
|
|
71
|
+
const wasOpen = dialog?.open;
|
|
72
|
+
dialog?.close();
|
|
73
|
+
if (wasOpen) (returnFocusRef?.current ?? invoker.current)?.focus({
|
|
74
|
+
preventScroll: true
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
}, [present, ref, returnFocusRef]);
|
|
78
|
+
if (!present) return null;
|
|
79
|
+
return createPortal(_jsx("dialog", {
|
|
33
80
|
ref: ref,
|
|
34
|
-
className: ["mdbase-dialog", className].filter(Boolean).join(" "),
|
|
35
|
-
"
|
|
36
|
-
|
|
81
|
+
className: ["mdbase-dialog mdbase-overlay", className].filter(Boolean).join(" "),
|
|
82
|
+
"data-open": open,
|
|
83
|
+
role: role,
|
|
84
|
+
"aria-modal": "true",
|
|
85
|
+
"aria-labelledby": titleId,
|
|
86
|
+
"aria-describedby": descriptionId,
|
|
87
|
+
tabIndex: -1,
|
|
88
|
+
onKeyDown: event => {
|
|
89
|
+
event.stopPropagation();
|
|
90
|
+
if (event.key === "Escape") {
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
if (!closeDisabled) onClose();
|
|
93
|
+
}
|
|
94
|
+
if (event.key === "Tab" && closeDisabled) {
|
|
95
|
+
const controls = [...event.currentTarget.querySelectorAll('button:not(:disabled), a[href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex="0"]')].filter(control => control.getClientRects().length > 0);
|
|
96
|
+
const current = controls.indexOf(document.activeElement);
|
|
97
|
+
const next = current < 0 ? event.shiftKey ? controls.length - 1 : 0 : (current + (event.shiftKey ? -1 : 1) + controls.length) % controls.length;
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
(controls.length ? controls[next] : event.currentTarget)?.focus({
|
|
100
|
+
preventScroll: true
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
},
|
|
37
104
|
onCancel: event => {
|
|
38
105
|
event.preventDefault();
|
|
39
106
|
if (!closeDisabled) onClose();
|
|
40
107
|
},
|
|
41
|
-
|
|
42
|
-
if (!closeDisabled) onClose();
|
|
43
|
-
},
|
|
44
|
-
onMouseDown: event => {
|
|
108
|
+
onClick: event => {
|
|
45
109
|
if (!closeDisabled && event.target === event.currentTarget) onClose();
|
|
46
110
|
},
|
|
47
|
-
children:
|
|
111
|
+
children: _jsxs("div", {
|
|
48
112
|
className: "mdbase-dialog-body",
|
|
49
113
|
children: [_jsxs("header", {
|
|
50
114
|
className: "mdbase-dialog-header",
|
|
51
115
|
children: [_jsx("h2", {
|
|
116
|
+
id: titleId,
|
|
52
117
|
children: title
|
|
53
118
|
}), _jsx("button", {
|
|
54
119
|
type: "button",
|
|
@@ -75,5 +140,5 @@ export function Dialog({
|
|
|
75
140
|
})]
|
|
76
141
|
}), children]
|
|
77
142
|
})
|
|
78
|
-
});
|
|
143
|
+
}), document.body);
|
|
79
144
|
}
|
package/dist/Feedback.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { flushSync } from "react-dom";
|
|
2
3
|
import { i18n as _i18n } from "@lingui/core";
|
|
3
4
|
import { useLocaleRevision } from "./i18n.js";
|
|
4
5
|
import { createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
6
|
+
import { Dialog } from "./Dialog.js";
|
|
5
7
|
import { FeedbackMarkup } from "./FeedbackMarkup.js";
|
|
6
8
|
import { FeedbackVerification } from "./FeedbackVerification.js";
|
|
7
9
|
import { FEEDBACK_ERROR_CODES, FEEDBACK_MAX_MESSAGE_LENGTH, captureFeedbackScreenshot, feedbackDiagnostics, feedbackEvents, feedbackTopics, readFeedbackScreenshot, resolveFeedbackEndpoint, screenshotUrl, sendFeedback } from "./feedback-data.js";
|
|
@@ -96,12 +98,10 @@ export function FeedbackProvider({
|
|
|
96
98
|
}) {
|
|
97
99
|
useLocaleRevision();
|
|
98
100
|
const endpoint = resolveFeedbackEndpoint(configuredEndpoint ?? undefined);
|
|
99
|
-
const dialog = useRef(null);
|
|
100
101
|
const content = useRef(null);
|
|
101
|
-
const messageField = useRef(null);
|
|
102
102
|
const successHeading = useRef(null);
|
|
103
|
+
const messageField = useRef(null);
|
|
103
104
|
const body = useRef(null);
|
|
104
|
-
const trigger = useRef(null);
|
|
105
105
|
const events = useRef([]);
|
|
106
106
|
const lastWiggle = useRef(-Infinity);
|
|
107
107
|
const imageOperation = useRef(null);
|
|
@@ -125,6 +125,9 @@ export function FeedbackProvider({
|
|
|
125
125
|
const [submitError, setSubmitError] = useState("");
|
|
126
126
|
const [submitting, setSubmitting] = useState(false);
|
|
127
127
|
const [submitted, setSubmitted] = useState(null);
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
if (submitted) successHeading.current?.focus();
|
|
130
|
+
}, [submitted]);
|
|
128
131
|
const [turnstileToken, setTurnstileToken] = useState("");
|
|
129
132
|
const [verificationAttempt, setVerificationAttempt] = useState(0);
|
|
130
133
|
const [wiggle, setWiggle] = useState(0);
|
|
@@ -148,7 +151,6 @@ export function FeedbackProvider({
|
|
|
148
151
|
}, [wiggle]);
|
|
149
152
|
const openFeedback = useCallback(next => {
|
|
150
153
|
if (!endpoint) return;
|
|
151
|
-
trigger.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
152
154
|
if (next) setTopic(next);
|
|
153
155
|
setDiagnostics(feedbackDiagnostics(events.current));
|
|
154
156
|
setOpen(true);
|
|
@@ -175,17 +177,6 @@ export function FeedbackProvider({
|
|
|
175
177
|
reportError,
|
|
176
178
|
wiggle
|
|
177
179
|
}), [endpoint, openFeedback, reportError, wiggle]);
|
|
178
|
-
useLayoutEffect(() => {
|
|
179
|
-
if (!dialog.current) return;
|
|
180
|
-
if (open && !capturing) {
|
|
181
|
-
if (!dialog.current.open) dialog.current.showModal();
|
|
182
|
-
if (submitted) successHeading.current?.focus({
|
|
183
|
-
preventScroll: true
|
|
184
|
-
});else messageField.current?.focus({
|
|
185
|
-
preventScroll: true
|
|
186
|
-
});
|
|
187
|
-
} else if (dialog.current.open) dialog.current.close();
|
|
188
|
-
}, [open, capturing, submitted]);
|
|
189
180
|
function resetDraft() {
|
|
190
181
|
setTopic("problem");
|
|
191
182
|
setMessage("");
|
|
@@ -211,10 +202,6 @@ export function FeedbackProvider({
|
|
|
211
202
|
setTurnstileToken("");
|
|
212
203
|
setVerificationAttempt(value => value + 1);
|
|
213
204
|
if (submitted) resetDraft();
|
|
214
|
-
dialog.current?.close();
|
|
215
|
-
trigger.current?.focus({
|
|
216
|
-
preventScroll: true
|
|
217
|
-
});
|
|
218
205
|
}
|
|
219
206
|
async function capture() {
|
|
220
207
|
if (imageOperation.current || submitting) return;
|
|
@@ -222,11 +209,9 @@ export function FeedbackProvider({
|
|
|
222
209
|
imageOperation.current = controller;
|
|
223
210
|
const scroll = body.current?.scrollTop ?? 0;
|
|
224
211
|
setImageBusy(true);
|
|
225
|
-
setCapturing(true);
|
|
212
|
+
flushSync(() => setCapturing(true));
|
|
226
213
|
setScreenshotError("");
|
|
227
214
|
setCaptureStatus("");
|
|
228
|
-
// Close synchronously, before either the picker or capture stream sees this native modal.
|
|
229
|
-
dialog.current?.close();
|
|
230
215
|
if (content.current) content.current.inert = true;
|
|
231
216
|
try {
|
|
232
217
|
const next = await captureFeedbackScreenshot(controller.signal);
|
|
@@ -260,7 +245,6 @@ export function FeedbackProvider({
|
|
|
260
245
|
if (!controller.signal.aborted && live.current) {
|
|
261
246
|
setCapturing(false);
|
|
262
247
|
setImageBusy(false);
|
|
263
|
-
if (dialog.current && !dialog.current.open) dialog.current.showModal();
|
|
264
248
|
if (body.current) body.current.scrollTop = scroll;
|
|
265
249
|
}
|
|
266
250
|
}
|
|
@@ -373,38 +357,20 @@ export function FeedbackProvider({
|
|
|
373
357
|
id: "7qrUoz",
|
|
374
358
|
message: "A problem occurred. You can use Send feedback to report it."
|
|
375
359
|
}) : ""
|
|
376
|
-
}), endpoint &&
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
360
|
+
}), endpoint && _jsx(Dialog, {
|
|
361
|
+
open: open && !capturing && !markup,
|
|
362
|
+
title: _i18n._(
|
|
363
|
+
/** i18n */
|
|
364
|
+
{
|
|
365
|
+
id: "RoafuO",
|
|
366
|
+
message: "Send feedback"
|
|
367
|
+
}),
|
|
368
|
+
onClose: () => {
|
|
369
|
+
if (!markup) close();
|
|
384
370
|
},
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
id: `${id}-title`,
|
|
389
|
-
children: _i18n._(
|
|
390
|
-
/** i18n */
|
|
391
|
-
{
|
|
392
|
-
id: "RoafuO",
|
|
393
|
-
message: "Send feedback"
|
|
394
|
-
})
|
|
395
|
-
}), _jsx("button", {
|
|
396
|
-
type: "button",
|
|
397
|
-
disabled: submitting,
|
|
398
|
-
onClick: close,
|
|
399
|
-
"aria-label": _i18n._(
|
|
400
|
-
/** i18n */
|
|
401
|
-
{
|
|
402
|
-
id: "lnj9gP",
|
|
403
|
-
message: "Close feedback"
|
|
404
|
-
}),
|
|
405
|
-
children: "\u00D7"
|
|
406
|
-
})]
|
|
407
|
-
}), submitted ? _jsxs("section", {
|
|
371
|
+
closeDisabled: submitting,
|
|
372
|
+
className: `mdbase-feedback-dialog${capturing ? " is-capturing" : ""}`,
|
|
373
|
+
children: submitted ? _jsxs("section", {
|
|
408
374
|
className: "mdbase-feedback-success",
|
|
409
375
|
children: [_jsx("h3", {
|
|
410
376
|
ref: successHeading,
|
|
@@ -460,6 +426,7 @@ export function FeedbackProvider({
|
|
|
460
426
|
children: [_jsx("span", {
|
|
461
427
|
children: config.prompt
|
|
462
428
|
}), _jsx("textarea", {
|
|
429
|
+
"data-autofocus": true,
|
|
463
430
|
ref: messageField,
|
|
464
431
|
required: true,
|
|
465
432
|
maxLength: FEEDBACK_MAX_MESSAGE_LENGTH,
|
|
@@ -750,8 +717,9 @@ export function FeedbackProvider({
|
|
|
750
717
|
})
|
|
751
718
|
})]
|
|
752
719
|
})]
|
|
753
|
-
})
|
|
754
|
-
}),
|
|
720
|
+
})
|
|
721
|
+
}), screenshot && _jsx(FeedbackMarkup, {
|
|
722
|
+
open: markup,
|
|
755
723
|
screenshot: screenshot,
|
|
756
724
|
onClose: () => {
|
|
757
725
|
setMarkup(false);
|
package/dist/FeedbackMarkup.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ export interface FeedbackMark {
|
|
|
10
10
|
}
|
|
11
11
|
/** Redactions render last and replace whole pixels. Export is a flattened raster, never layers. */
|
|
12
12
|
export declare function paintFeedbackMarks(context: CanvasRenderingContext2D, image: CanvasImageSource, marks: readonly FeedbackMark[]): void;
|
|
13
|
-
export declare function FeedbackMarkup({ screenshot, onApply, onClose }: {
|
|
13
|
+
export declare function FeedbackMarkup({ open, screenshot, onApply, onClose }: {
|
|
14
|
+
open: boolean;
|
|
14
15
|
screenshot: FeedbackScreenshot;
|
|
15
16
|
onApply(screenshot: FeedbackScreenshot, count: number): void;
|
|
16
17
|
onClose(): void;
|
package/dist/FeedbackMarkup.js
CHANGED
|
@@ -36,6 +36,7 @@ export function paintFeedbackMarks(context, image, marks) {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
export function FeedbackMarkup({
|
|
39
|
+
open,
|
|
39
40
|
screenshot,
|
|
40
41
|
onApply,
|
|
41
42
|
onClose
|
|
@@ -65,6 +66,12 @@ export function FeedbackMarkup({
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
useEffect(() => {
|
|
69
|
+
if (!open) return;
|
|
70
|
+
setReady(false);
|
|
71
|
+
setTool("draw");
|
|
72
|
+
setCount(0);
|
|
73
|
+
setError("");
|
|
74
|
+
cursor.current = null;
|
|
68
75
|
let live = true;
|
|
69
76
|
const decoded = new Image();
|
|
70
77
|
decoded.src = screenshotUrl(screenshot);
|
|
@@ -89,7 +96,7 @@ export function FeedbackMarkup({
|
|
|
89
96
|
marks.current = [];
|
|
90
97
|
current.current = null;
|
|
91
98
|
};
|
|
92
|
-
}, [screenshot]);
|
|
99
|
+
}, [open, screenshot]);
|
|
93
100
|
function finish() {
|
|
94
101
|
if (current.current && current.current.points.length > 1 && marks.current.length < 100) marks.current.push(current.current);
|
|
95
102
|
current.current = null;
|
|
@@ -105,7 +112,7 @@ export function FeedbackMarkup({
|
|
|
105
112
|
};
|
|
106
113
|
}
|
|
107
114
|
return _jsxs(Dialog, {
|
|
108
|
-
open:
|
|
115
|
+
open: open,
|
|
109
116
|
onClose: onClose,
|
|
110
117
|
closeDisabled: busy,
|
|
111
118
|
title: _i18n._(
|
package/dist/Menu.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type KeyboardEvent, type ReactNode, type RefObject } from "react";
|
|
2
|
+
export declare function Menu({ open, triggerRef, onClose, id, label, className, children, point }: {
|
|
3
|
+
readonly open: boolean;
|
|
4
|
+
readonly triggerRef: RefObject<HTMLElement | null>;
|
|
5
|
+
readonly onClose: (refocus: boolean) => void;
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly label?: string;
|
|
8
|
+
readonly className?: string;
|
|
9
|
+
readonly children: ReactNode;
|
|
10
|
+
readonly point?: {
|
|
11
|
+
readonly left: number;
|
|
12
|
+
readonly top: number;
|
|
13
|
+
} | undefined;
|
|
14
|
+
}): import("react").JSX.Element | null;
|
|
15
|
+
export declare function useMenuTrigger(): {
|
|
16
|
+
id: string;
|
|
17
|
+
open: boolean;
|
|
18
|
+
close: (refocus: boolean) => void;
|
|
19
|
+
trigger: RefObject<HTMLButtonElement | null>;
|
|
20
|
+
triggerProps: {
|
|
21
|
+
ref: RefObject<HTMLButtonElement | null>;
|
|
22
|
+
"aria-haspopup": "menu";
|
|
23
|
+
"aria-expanded": boolean;
|
|
24
|
+
"aria-controls": string | undefined;
|
|
25
|
+
onClick: () => void;
|
|
26
|
+
onKeyDown: (event: KeyboardEvent) => void;
|
|
27
|
+
};
|
|
28
|
+
};
|
package/dist/Menu.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useRef, useState } from "react";
|
|
3
|
+
import { moveMenuFocus, useMenuPopover } from "./popover.js";
|
|
4
|
+
import { useOverlay } from "./overlay.js";
|
|
5
|
+
export function Menu({
|
|
6
|
+
open,
|
|
7
|
+
triggerRef,
|
|
8
|
+
onClose,
|
|
9
|
+
id,
|
|
10
|
+
label,
|
|
11
|
+
className = "mdbase-menu",
|
|
12
|
+
children,
|
|
13
|
+
point
|
|
14
|
+
}) {
|
|
15
|
+
const {
|
|
16
|
+
ref,
|
|
17
|
+
present
|
|
18
|
+
} = useOverlay(open);
|
|
19
|
+
useMenuPopover(ref, triggerRef, onClose, {
|
|
20
|
+
align: "end",
|
|
21
|
+
open,
|
|
22
|
+
point
|
|
23
|
+
});
|
|
24
|
+
return present ? _jsx("div", {
|
|
25
|
+
ref: ref,
|
|
26
|
+
id: id,
|
|
27
|
+
className: `${className} mdbase-overlay`,
|
|
28
|
+
"data-open": open,
|
|
29
|
+
popover: "manual",
|
|
30
|
+
role: "menu",
|
|
31
|
+
"aria-label": label,
|
|
32
|
+
tabIndex: -1,
|
|
33
|
+
onKeyDown: event => moveMenuFocus(event, ref.current),
|
|
34
|
+
children: children
|
|
35
|
+
}) : null;
|
|
36
|
+
}
|
|
37
|
+
export function useMenuTrigger() {
|
|
38
|
+
const id = useId();
|
|
39
|
+
const [open, setOpen] = useState(false);
|
|
40
|
+
const trigger = useRef(null);
|
|
41
|
+
const close = refocus => {
|
|
42
|
+
setOpen(false);
|
|
43
|
+
if (refocus) trigger.current?.focus();
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
id,
|
|
47
|
+
open,
|
|
48
|
+
close,
|
|
49
|
+
trigger,
|
|
50
|
+
triggerProps: {
|
|
51
|
+
ref: trigger,
|
|
52
|
+
"aria-haspopup": "menu",
|
|
53
|
+
"aria-expanded": open,
|
|
54
|
+
"aria-controls": open ? id : undefined,
|
|
55
|
+
onClick: () => setOpen(value => !value),
|
|
56
|
+
onKeyDown: event => {
|
|
57
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
setOpen(true);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
package/dist/Select.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useId, useLayoutEffect, useRef, useState } from "react";
|
|
3
3
|
import { edgeOption, extendTypeahead, flattenOptions, stepOption, typeaheadOption } from "./select-model.js";
|
|
4
|
+
import { useOverlay } from "./overlay.js";
|
|
4
5
|
import { SelectList } from "./SelectList.js";
|
|
5
6
|
import { useSelectPopover } from "./popover.js";
|
|
6
7
|
/**
|
|
@@ -27,10 +28,13 @@ export function Select({
|
|
|
27
28
|
"aria-labelledby": ariaLabelledBy
|
|
28
29
|
} = trigger;
|
|
29
30
|
const triggerRef = useRef(null);
|
|
30
|
-
const listRef = useRef(null);
|
|
31
31
|
const options = flattenOptions(items);
|
|
32
32
|
const selected = options.findIndex(option => option.value === value);
|
|
33
33
|
const state = useSelectState(options, selected, value, onChange, disabled, triggerRef);
|
|
34
|
+
const {
|
|
35
|
+
ref: listRef,
|
|
36
|
+
present
|
|
37
|
+
} = useOverlay(state.open);
|
|
34
38
|
useSelectPopover(state.open, triggerRef, listRef, () => state.close(false));
|
|
35
39
|
useLayoutEffect(() => {
|
|
36
40
|
if (state.open && listRef.current) {
|
|
@@ -76,7 +80,7 @@ export function Select({
|
|
|
76
80
|
d: "m7 10 5 5 5-5"
|
|
77
81
|
})
|
|
78
82
|
})]
|
|
79
|
-
}), _jsx(SelectList, {
|
|
83
|
+
}), present && _jsx(SelectList, {
|
|
80
84
|
id: id,
|
|
81
85
|
listRef: listRef,
|
|
82
86
|
items: items,
|
package/dist/SelectList.js
CHANGED
|
@@ -37,7 +37,8 @@ export function SelectList({
|
|
|
37
37
|
return _jsx("div", {
|
|
38
38
|
ref: listRef,
|
|
39
39
|
id: `${id}-list`,
|
|
40
|
-
className: "mdbase-select-list",
|
|
40
|
+
className: "mdbase-select-list mdbase-overlay",
|
|
41
|
+
"data-open": open,
|
|
41
42
|
popover: "manual",
|
|
42
43
|
role: "listbox",
|
|
43
44
|
tabIndex: -1,
|
package/dist/Toaster.d.ts
CHANGED
|
@@ -1,2 +1,19 @@
|
|
|
1
|
+
export interface ToastItem {
|
|
2
|
+
id: string;
|
|
3
|
+
message: string;
|
|
4
|
+
tone?: "info" | "success" | "error";
|
|
5
|
+
action?: {
|
|
6
|
+
label: string;
|
|
7
|
+
onAction: () => void;
|
|
8
|
+
busy?: boolean;
|
|
9
|
+
dismiss?: boolean;
|
|
10
|
+
};
|
|
11
|
+
sticky?: boolean;
|
|
12
|
+
dismissible?: boolean;
|
|
13
|
+
durationMs?: number;
|
|
14
|
+
}
|
|
1
15
|
export declare function toast(message: string, undo?: () => void): void;
|
|
2
|
-
export declare function Toaster(
|
|
16
|
+
export declare function Toaster({ items, onDismiss }: {
|
|
17
|
+
items?: readonly ToastItem[];
|
|
18
|
+
onDismiss?: (id: string) => void;
|
|
19
|
+
}): import("react").JSX.Element;
|