@mdbase-dev/ui 0.1.0-beta.155 → 0.1.0-beta.156
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 +32 -33
- package/css/feedback.css +6 -6
- package/css/motion.css +50 -26
- package/css/palette.css +22 -54
- package/css/toast.css +10 -5
- package/css/tokens.css +11 -25
- package/dist/AppSwitcher.js +18 -30
- package/dist/CommandPalette.d.ts +5 -2
- package/dist/CommandPalette.js +157 -152
- package/dist/ConfirmDialog.d.ts +14 -0
- package/dist/ConfirmDialog.js +65 -0
- package/dist/Dialog.d.ts +5 -7
- package/dist/Dialog.js +46 -24
- package/dist/Feedback.js +24 -56
- package/dist/FeedbackMarkup.d.ts +2 -1
- package/dist/FeedbackMarkup.js +8 -2
- package/dist/Menu.d.ts +10 -0
- package/dist/Menu.js +33 -0
- package/dist/Select.js +6 -2
- package/dist/SelectList.js +2 -1
- package/dist/Toaster.js +72 -44
- package/dist/brand.js +5 -3
- package/dist/collections/CollectionSwitcher.d.ts +2 -3
- package/dist/collections/CollectionSwitcher.js +14 -173
- package/dist/collections/dialogs.d.ts +9 -4
- package/dist/collections/dialogs.js +83 -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 +2 -1
- package/dist/popover.js +6 -13
- package/package.json +14 -2
package/dist/AppSwitcher.js
CHANGED
|
@@ -5,9 +5,7 @@ import { useId, useRef, useState } from "react";
|
|
|
5
5
|
import { mdbaseAppHref, withAppUrls } from "./apps.js";
|
|
6
6
|
import { MdbaseAppMark, Wordmark } from "./brand.js";
|
|
7
7
|
import { useMdbaseMarkActivity } from "./mark-activity.js";
|
|
8
|
-
import {
|
|
9
|
-
/** The switcher plays its entrance once per page, not every time it remounts. */
|
|
10
|
-
let entrancePlayed = false;
|
|
8
|
+
import { Menu } from "./Menu.js";
|
|
11
9
|
/**
|
|
12
10
|
* The product wordmark as a menu for opening the current collection in the other mdbase apps.
|
|
13
11
|
* Each opens in a new tab so the current app stays where it is.
|
|
@@ -24,11 +22,6 @@ export function AppSwitcher({
|
|
|
24
22
|
const menuId = useId();
|
|
25
23
|
const triggerRef = useRef(null);
|
|
26
24
|
const [open, setOpen] = useState(false);
|
|
27
|
-
const [entrance] = useState(() => {
|
|
28
|
-
if (motion || entrancePlayed || typeof window === "undefined") return undefined;
|
|
29
|
-
entrancePlayed = true;
|
|
30
|
-
return "keys-first";
|
|
31
|
-
});
|
|
32
25
|
const activity = useMdbaseMarkActivity();
|
|
33
26
|
const close = refocus => {
|
|
34
27
|
setOpen(false);
|
|
@@ -66,7 +59,7 @@ export function AppSwitcher({
|
|
|
66
59
|
},
|
|
67
60
|
children: [_jsx(Wordmark, {
|
|
68
61
|
app: current,
|
|
69
|
-
motion: activity.busy ?? motion ??
|
|
62
|
+
motion: activity.busy ?? motion ?? "keys-first",
|
|
70
63
|
signal: activity.signal,
|
|
71
64
|
progress: activity.progress
|
|
72
65
|
}), _jsx("svg", {
|
|
@@ -77,28 +70,31 @@ export function AppSwitcher({
|
|
|
77
70
|
d: "m7 10 5 5 5-5"
|
|
78
71
|
})
|
|
79
72
|
})]
|
|
80
|
-
}),
|
|
73
|
+
}), _jsx(Menu, {
|
|
74
|
+
open: open,
|
|
81
75
|
id: menuId,
|
|
82
|
-
apps: withAppUrls(urls),
|
|
83
|
-
current: current,
|
|
84
76
|
triggerRef: triggerRef,
|
|
85
|
-
onClose: close
|
|
86
|
-
|
|
77
|
+
onClose: close,
|
|
78
|
+
label: _i18n._(
|
|
79
|
+
/** i18n */
|
|
80
|
+
{
|
|
81
|
+
id: "vDwCOr",
|
|
82
|
+
message: "mdbase apps"
|
|
83
|
+
}),
|
|
84
|
+
children: _jsx(AppMenu, {
|
|
85
|
+
apps: withAppUrls(urls),
|
|
86
|
+
current: current,
|
|
87
|
+
onClose: close
|
|
88
|
+
})
|
|
89
|
+
})]
|
|
87
90
|
});
|
|
88
91
|
}
|
|
89
92
|
function AppMenu({
|
|
90
|
-
id,
|
|
91
93
|
apps,
|
|
92
94
|
current,
|
|
93
|
-
triggerRef,
|
|
94
95
|
onClose
|
|
95
96
|
}) {
|
|
96
97
|
useLocaleRevision();
|
|
97
|
-
const menuRef = useRef(null);
|
|
98
|
-
useMenuPopover(menuRef, triggerRef, onClose, {
|
|
99
|
-
width: 320,
|
|
100
|
-
focus: 'a[role="menuitem"]'
|
|
101
|
-
});
|
|
102
98
|
const heading = new URL(location.href).searchParams.has("collection") ? _i18n._(
|
|
103
99
|
/** i18n */
|
|
104
100
|
{
|
|
@@ -110,15 +106,7 @@ function AppMenu({
|
|
|
110
106
|
id: "vDwCOr",
|
|
111
107
|
message: "mdbase apps"
|
|
112
108
|
});
|
|
113
|
-
return _jsxs(
|
|
114
|
-
ref: menuRef,
|
|
115
|
-
id: id,
|
|
116
|
-
className: "mdbase-menu",
|
|
117
|
-
popover: "manual",
|
|
118
|
-
role: "menu",
|
|
119
|
-
"aria-label": heading,
|
|
120
|
-
tabIndex: -1,
|
|
121
|
-
onKeyDown: event => moveMenuFocus(event, menuRef.current),
|
|
109
|
+
return _jsxs(_Fragment, {
|
|
122
110
|
children: [_jsx("div", {
|
|
123
111
|
className: "mdbase-menu-heading",
|
|
124
112
|
role: "presentation",
|
package/dist/CommandPalette.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { type JSX } from "react";
|
|
1
|
+
import { type JSX, type RefObject, type ReactNode } from "react";
|
|
2
2
|
export interface Command {
|
|
3
3
|
readonly id: string;
|
|
4
4
|
readonly label: string;
|
|
5
5
|
readonly detail?: string | undefined;
|
|
6
|
+
readonly icon?: ReactNode;
|
|
6
7
|
/** Stable group ID; headings follow first appearance and may be presented by groupLabel. */
|
|
7
8
|
readonly group: string;
|
|
8
9
|
readonly keywords?: string | undefined;
|
|
@@ -27,7 +28,7 @@ export declare function matchingCommands(commands: readonly Command[], query: st
|
|
|
27
28
|
* Find or run anything: every mdbase app opens it with Mod+K. Typing filters commands; the
|
|
28
29
|
* arrows move, Enter runs, Shift+Enter runs a command's alternate, Escape closes.
|
|
29
30
|
*/
|
|
30
|
-
export declare function CommandPalette({ open, commands, onClose, label, placeholder, showAll, groupLabel }: {
|
|
31
|
+
export declare function CommandPalette({ open, commands, onClose, label, placeholder, showAll, groupLabel, returnFocusRef, emptyState }: {
|
|
31
32
|
readonly open: boolean;
|
|
32
33
|
readonly commands: readonly Command[];
|
|
33
34
|
readonly onClose: () => void;
|
|
@@ -36,4 +37,6 @@ export declare function CommandPalette({ open, commands, onClose, label, placeho
|
|
|
36
37
|
readonly showAll?: readonly string[] | undefined;
|
|
37
38
|
/** Presentation only: translate headings without changing group or showAll IDs. */
|
|
38
39
|
readonly groupLabel?: ((group: string) => string) | undefined;
|
|
40
|
+
readonly returnFocusRef?: RefObject<HTMLElement | null> | undefined;
|
|
41
|
+
readonly emptyState?: ReactNode;
|
|
39
42
|
}): JSX.Element | null;
|
package/dist/CommandPalette.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { i18n as _i18n } from "@lingui/core";
|
|
3
3
|
import { useLocaleRevision } from "./i18n.js";
|
|
4
|
+
import { Dialog } from "./Dialog.js";
|
|
4
5
|
import { Fragment, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
5
6
|
export function isApplePlatform() {
|
|
6
7
|
return typeof navigator !== "undefined" && /Mac|iPhone|iPad/u.test(navigator.platform || navigator.userAgent);
|
|
7
8
|
}
|
|
8
9
|
/** "mod+shift+f" as the platform writes it: ⌘⇧F on Apple systems, Ctrl+Shift+F elsewhere. */
|
|
9
10
|
export function shortcutLabel(shortcut) {
|
|
11
|
+
if (/^[a-z] [a-z]$/iu.test(shortcut)) return shortcut.toUpperCase();
|
|
10
12
|
const apple = isApplePlatform();
|
|
11
13
|
return shortcut.split("+").map(part => {
|
|
12
14
|
switch (part.toLowerCase()) {
|
|
13
15
|
case "mod":
|
|
14
16
|
return apple ? "⌘" : "Ctrl";
|
|
17
|
+
case "ctrl":
|
|
18
|
+
return apple ? "⌃" : "Ctrl";
|
|
15
19
|
case "shift":
|
|
16
20
|
return apple ? "⇧" : "Shift";
|
|
17
21
|
case "alt":
|
|
@@ -41,10 +45,12 @@ export function matchingCommands(commands, query, showAll = []) {
|
|
|
41
45
|
const content = `${command.label} ${command.detail ?? ""} ${command.group} ${command.keywords ?? ""}`.toLocaleLowerCase();
|
|
42
46
|
return terms.every(term => content.includes(term));
|
|
43
47
|
});
|
|
44
|
-
const
|
|
48
|
+
const names = matches.filter(command => terms.every(term => command.label.toLocaleLowerCase().includes(term)));
|
|
49
|
+
const selected = [...names, ...matches.filter(command => !names.includes(command))].slice(0, searchLimit);
|
|
50
|
+
const groups = [...new Set(selected.map(({
|
|
45
51
|
group
|
|
46
52
|
}) => group))];
|
|
47
|
-
return groups.flatMap(group =>
|
|
53
|
+
return groups.flatMap(group => selected.filter(command => command.group === group));
|
|
48
54
|
}
|
|
49
55
|
/**
|
|
50
56
|
* Find or run anything: every mdbase app opens it with Mod+K. Typing filters commands; the
|
|
@@ -67,192 +73,183 @@ export function CommandPalette({
|
|
|
67
73
|
message: "Search commands"
|
|
68
74
|
}),
|
|
69
75
|
showAll,
|
|
70
|
-
groupLabel
|
|
76
|
+
groupLabel,
|
|
77
|
+
returnFocusRef,
|
|
78
|
+
emptyState
|
|
71
79
|
}) {
|
|
72
80
|
useLocaleRevision();
|
|
73
|
-
return
|
|
74
|
-
|
|
81
|
+
return _jsx(Dialog, {
|
|
82
|
+
open: open,
|
|
83
|
+
title: label,
|
|
75
84
|
onClose: onClose,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
returnFocusRef: returnFocusRef,
|
|
86
|
+
className: "mdbase-command-palette",
|
|
87
|
+
children: _jsx(OpenCommandPalette, {
|
|
88
|
+
open: open,
|
|
89
|
+
commands: commands,
|
|
90
|
+
onClose: onClose,
|
|
91
|
+
label: label,
|
|
92
|
+
placeholder: placeholder,
|
|
93
|
+
showAll: showAll,
|
|
94
|
+
groupLabel: groupLabel,
|
|
95
|
+
returnFocusRef: returnFocusRef,
|
|
96
|
+
emptyState: emptyState
|
|
97
|
+
})
|
|
98
|
+
});
|
|
81
99
|
}
|
|
82
100
|
function OpenCommandPalette({
|
|
101
|
+
open,
|
|
83
102
|
commands,
|
|
84
103
|
onClose,
|
|
85
104
|
label,
|
|
86
105
|
placeholder,
|
|
87
106
|
showAll,
|
|
88
|
-
groupLabel
|
|
107
|
+
groupLabel,
|
|
108
|
+
returnFocusRef,
|
|
109
|
+
emptyState
|
|
89
110
|
}) {
|
|
90
111
|
useLocaleRevision();
|
|
91
112
|
const [query, setQuery] = useState("");
|
|
92
113
|
const [active, setActive] = useState(0);
|
|
93
114
|
const inputRef = useRef(null);
|
|
94
|
-
const paletteRef = useRef(null);
|
|
95
115
|
const matches = useMemo(() => matchingCommands(commands, query, showAll), [commands, query, showAll]);
|
|
116
|
+
const resultHeight = Math.min(380, Math.max(152, Math.ceil((matches.length * 38 + new Set(matches.map(command => command.group)).size * 30 + 12) / 76) * 76));
|
|
96
117
|
useEffect(() => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
118
|
+
if (open) {
|
|
119
|
+
setQuery("");
|
|
120
|
+
setActive(0);
|
|
121
|
+
}
|
|
122
|
+
}, [open]);
|
|
101
123
|
const run = (command, alternate = false) => {
|
|
124
|
+
inputRef.current?.closest("dialog")?.close();
|
|
125
|
+
returnFocusRef?.current?.focus({
|
|
126
|
+
preventScroll: true
|
|
127
|
+
});
|
|
102
128
|
onClose();
|
|
103
129
|
(alternate && command.alternate ? command.alternate.run : command.run)();
|
|
104
130
|
};
|
|
105
131
|
const hintId = useId();
|
|
106
|
-
return _jsxs(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
132
|
+
return _jsxs(_Fragment, {
|
|
133
|
+
children: [_jsxs("label", {
|
|
134
|
+
className: "mdbase-command-search",
|
|
135
|
+
children: [_jsxs("svg", {
|
|
136
|
+
viewBox: "0 0 24 24",
|
|
137
|
+
"aria-hidden": "true",
|
|
138
|
+
fill: "none",
|
|
139
|
+
stroke: "currentColor",
|
|
140
|
+
strokeWidth: "1.6",
|
|
141
|
+
children: [_jsx("circle", {
|
|
142
|
+
cx: "11",
|
|
143
|
+
cy: "11",
|
|
144
|
+
r: "6.5"
|
|
145
|
+
}), _jsx("path", {
|
|
146
|
+
d: "m16 16 4 4"
|
|
147
|
+
})]
|
|
148
|
+
}), _jsx("span", {
|
|
149
|
+
className: "mdbase-visually-hidden",
|
|
150
|
+
children: placeholder
|
|
151
|
+
}), _jsx("input", {
|
|
152
|
+
ref: inputRef,
|
|
153
|
+
"data-autofocus": true,
|
|
154
|
+
value: query,
|
|
155
|
+
placeholder: placeholder,
|
|
156
|
+
onChange: event => {
|
|
157
|
+
setQuery(event.target.value);
|
|
158
|
+
setActive(0);
|
|
159
|
+
},
|
|
160
|
+
role: "combobox",
|
|
161
|
+
"aria-autocomplete": "list",
|
|
162
|
+
"aria-expanded": "true",
|
|
163
|
+
"aria-controls": `${hintId}-results`,
|
|
164
|
+
"aria-activedescendant": matches[active] ? `${hintId}-${matches[active].id}` : undefined,
|
|
165
|
+
onKeyDown: event => {
|
|
166
|
+
if (!event.nativeEvent.isComposing) handleKeys(event, matches, active, setActive, run, onClose);
|
|
167
|
+
}
|
|
168
|
+
})]
|
|
169
|
+
}), _jsx("div", {
|
|
170
|
+
id: `${hintId}-results`,
|
|
171
|
+
className: "mdbase-command-results",
|
|
172
|
+
style: {
|
|
173
|
+
height: resultHeight
|
|
174
|
+
},
|
|
175
|
+
role: "listbox",
|
|
112
176
|
"aria-label": _i18n._(
|
|
113
177
|
/** i18n */
|
|
114
178
|
{
|
|
115
|
-
id: "
|
|
116
|
-
message: "
|
|
117
|
-
values: {
|
|
118
|
-
label: label
|
|
119
|
-
}
|
|
179
|
+
id: "kx0s-n",
|
|
180
|
+
message: "Results"
|
|
120
181
|
}),
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
} else if (event.key === "Tab") {
|
|
133
|
-
trapFocus(event, paletteRef.current);
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
children: [_jsxs("label", {
|
|
137
|
-
className: "mdbase-command-search",
|
|
138
|
-
children: [_jsxs("svg", {
|
|
139
|
-
viewBox: "0 0 24 24",
|
|
140
|
-
"aria-hidden": "true",
|
|
141
|
-
fill: "none",
|
|
142
|
-
stroke: "currentColor",
|
|
143
|
-
strokeWidth: "1.6",
|
|
144
|
-
children: [_jsx("circle", {
|
|
145
|
-
cx: "11",
|
|
146
|
-
cy: "11",
|
|
147
|
-
r: "6.5"
|
|
148
|
-
}), _jsx("path", {
|
|
149
|
-
d: "m16 16 4 4"
|
|
150
|
-
})]
|
|
151
|
-
}), _jsx("span", {
|
|
152
|
-
className: "mdbase-visually-hidden",
|
|
153
|
-
children: placeholder
|
|
154
|
-
}), _jsx("input", {
|
|
155
|
-
ref: inputRef,
|
|
156
|
-
value: query,
|
|
157
|
-
placeholder: placeholder,
|
|
158
|
-
onChange: event => {
|
|
159
|
-
setQuery(event.target.value);
|
|
160
|
-
setActive(0);
|
|
161
|
-
},
|
|
162
|
-
onKeyDown: event => handleKeys(event, matches, active, setActive, run, onClose)
|
|
182
|
+
"aria-describedby": hintId,
|
|
183
|
+
children: matches.length > 0 ? matches.map((command, index) => _jsxs(Fragment, {
|
|
184
|
+
children: [command.group !== matches[index - 1]?.group ? _jsx("div", {
|
|
185
|
+
className: "mdbase-command-group",
|
|
186
|
+
role: "presentation",
|
|
187
|
+
children: groupLabel ? groupLabel(command.group) : command.group
|
|
188
|
+
}) : null, _jsx(CommandRow, {
|
|
189
|
+
id: `${hintId}-${command.id}`,
|
|
190
|
+
command: command,
|
|
191
|
+
active: index === active,
|
|
192
|
+
onRun: run
|
|
163
193
|
})]
|
|
164
|
-
}
|
|
165
|
-
className: "mdbase-command-
|
|
166
|
-
role: "
|
|
167
|
-
|
|
194
|
+
}, command.id)) : _jsx("div", {
|
|
195
|
+
className: "mdbase-command-empty",
|
|
196
|
+
role: "status",
|
|
197
|
+
children: emptyState ?? _i18n._(
|
|
198
|
+
/** i18n */
|
|
199
|
+
{
|
|
200
|
+
id: "DViXWV",
|
|
201
|
+
message: "Nothing matches"
|
|
202
|
+
})
|
|
203
|
+
})
|
|
204
|
+
}), _jsxs("footer", {
|
|
205
|
+
className: "mdbase-command-footer",
|
|
206
|
+
id: hintId,
|
|
207
|
+
children: [_jsxs("span", {
|
|
208
|
+
children: [_jsx("kbd", {
|
|
209
|
+
children: "\u2191"
|
|
210
|
+
}), _jsx("kbd", {
|
|
211
|
+
children: "\u2193"
|
|
212
|
+
}), " ", _i18n._(
|
|
168
213
|
/** i18n */
|
|
169
214
|
{
|
|
170
|
-
id: "
|
|
171
|
-
message: "
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
children:
|
|
175
|
-
children:
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
215
|
+
id: "2UA-qq",
|
|
216
|
+
message: "to move"
|
|
217
|
+
})]
|
|
218
|
+
}), _jsxs("span", {
|
|
219
|
+
children: [_jsx("kbd", {
|
|
220
|
+
children: "\u21B5"
|
|
221
|
+
}), " ", _i18n._(
|
|
222
|
+
/** i18n */
|
|
223
|
+
{
|
|
224
|
+
id: "2cqK5k",
|
|
225
|
+
message: "to open"
|
|
226
|
+
})]
|
|
227
|
+
}), matches[active]?.alternate ? _jsxs("span", {
|
|
228
|
+
children: [_jsx("kbd", {
|
|
229
|
+
children: shortcutLabel("shift")
|
|
230
|
+
}), _jsx("kbd", {
|
|
231
|
+
children: "\u21B5"
|
|
232
|
+
}), " ", matches[active].alternate.label.toLocaleLowerCase()]
|
|
233
|
+
}) : null, _jsxs("span", {
|
|
234
|
+
children: [_jsx("kbd", {
|
|
186
235
|
children: _i18n._(
|
|
187
236
|
/** i18n */
|
|
188
237
|
{
|
|
189
|
-
id: "
|
|
190
|
-
message: "
|
|
238
|
+
id: "zO1gmR",
|
|
239
|
+
message: "Esc"
|
|
191
240
|
})
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
children: [_jsx("kbd", {
|
|
198
|
-
children: "\u2191"
|
|
199
|
-
}), _jsx("kbd", {
|
|
200
|
-
children: "\u2193"
|
|
201
|
-
}), " ", _i18n._(
|
|
202
|
-
/** i18n */
|
|
203
|
-
{
|
|
204
|
-
id: "2UA-qq",
|
|
205
|
-
message: "to move"
|
|
206
|
-
})]
|
|
207
|
-
}), _jsxs("span", {
|
|
208
|
-
children: [_jsx("kbd", {
|
|
209
|
-
children: "\u21B5"
|
|
210
|
-
}), " ", _i18n._(
|
|
211
|
-
/** i18n */
|
|
212
|
-
{
|
|
213
|
-
id: "2cqK5k",
|
|
214
|
-
message: "to open"
|
|
215
|
-
})]
|
|
216
|
-
}), matches[active]?.alternate ? _jsxs("span", {
|
|
217
|
-
children: [_jsx("kbd", {
|
|
218
|
-
children: shortcutLabel("shift")
|
|
219
|
-
}), _jsx("kbd", {
|
|
220
|
-
children: "\u21B5"
|
|
221
|
-
}), " ", matches[active].alternate.label.toLocaleLowerCase()]
|
|
222
|
-
}) : null, _jsxs("span", {
|
|
223
|
-
children: [_jsx("kbd", {
|
|
224
|
-
children: _i18n._(
|
|
225
|
-
/** i18n */
|
|
226
|
-
{
|
|
227
|
-
id: "zO1gmR",
|
|
228
|
-
message: "Esc"
|
|
229
|
-
})
|
|
230
|
-
}), " ", _i18n._(
|
|
231
|
-
/** i18n */
|
|
232
|
-
{
|
|
233
|
-
id: "UbVgIu",
|
|
234
|
-
message: "to close"
|
|
235
|
-
})]
|
|
241
|
+
}), " ", _i18n._(
|
|
242
|
+
/** i18n */
|
|
243
|
+
{
|
|
244
|
+
id: "UbVgIu",
|
|
245
|
+
message: "to close"
|
|
236
246
|
})]
|
|
237
247
|
})]
|
|
238
248
|
})]
|
|
239
249
|
});
|
|
240
250
|
}
|
|
241
|
-
function trapFocus(event, container) {
|
|
242
|
-
if (!container) return;
|
|
243
|
-
const items = [...container.querySelectorAll("input, button, [tabindex]:not([tabindex='-1'])")];
|
|
244
|
-
const first = items[0];
|
|
245
|
-
const last = items.at(-1);
|
|
246
|
-
if (!first || !last) return;
|
|
247
|
-
if (event.shiftKey && document.activeElement === first) {
|
|
248
|
-
event.preventDefault();
|
|
249
|
-
last.focus();
|
|
250
|
-
} else if (!event.shiftKey && document.activeElement === last) {
|
|
251
|
-
event.preventDefault();
|
|
252
|
-
first.focus();
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
251
|
function CommandRow({
|
|
252
|
+
id,
|
|
256
253
|
command,
|
|
257
254
|
active,
|
|
258
255
|
onRun
|
|
@@ -265,12 +262,20 @@ function CommandRow({
|
|
|
265
262
|
});
|
|
266
263
|
}, [active]);
|
|
267
264
|
return _jsxs("button", {
|
|
265
|
+
id: id,
|
|
268
266
|
ref: ref,
|
|
267
|
+
tabIndex: -1,
|
|
269
268
|
type: "button",
|
|
270
269
|
role: "option",
|
|
271
270
|
"aria-selected": active,
|
|
272
|
-
onMouseDown: event =>
|
|
273
|
-
|
|
271
|
+
onMouseDown: event => event.preventDefault(),
|
|
272
|
+
onClick: event => onRun(command, event.shiftKey),
|
|
273
|
+
children: [command.icon && _jsx("span", {
|
|
274
|
+
className: "mdbase-command-icon",
|
|
275
|
+
"aria-hidden": "true",
|
|
276
|
+
children: command.icon
|
|
277
|
+
}), _jsxs("span", {
|
|
278
|
+
className: "mdbase-command-copy",
|
|
274
279
|
children: [_jsx("strong", {
|
|
275
280
|
children: command.label
|
|
276
281
|
}), command.detail ? _jsx("small", {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ReactNode, type RefObject } from "react";
|
|
2
|
+
export declare function ConfirmDialog({ open, title, consequence, confirmLabel, pendingLabel, busy, disabled, onConfirm, onClose, returnFocusRef, children }: {
|
|
3
|
+
readonly open: boolean;
|
|
4
|
+
readonly title: string;
|
|
5
|
+
readonly consequence?: string;
|
|
6
|
+
readonly confirmLabel: string;
|
|
7
|
+
readonly pendingLabel: string;
|
|
8
|
+
readonly busy?: boolean;
|
|
9
|
+
readonly disabled?: boolean;
|
|
10
|
+
readonly onConfirm: () => void | Promise<unknown>;
|
|
11
|
+
readonly onClose: () => void;
|
|
12
|
+
readonly returnFocusRef?: RefObject<HTMLElement | null> | undefined;
|
|
13
|
+
readonly children?: ReactNode;
|
|
14
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { i18n as _i18n } from "@lingui/core";
|
|
3
|
+
import { useId, useState } from "react";
|
|
4
|
+
import { Dialog } from "./Dialog.js";
|
|
5
|
+
import { useLocaleRevision } from "./i18n.js";
|
|
6
|
+
export function ConfirmDialog({
|
|
7
|
+
open,
|
|
8
|
+
title,
|
|
9
|
+
consequence,
|
|
10
|
+
confirmLabel,
|
|
11
|
+
pendingLabel,
|
|
12
|
+
busy = false,
|
|
13
|
+
disabled = false,
|
|
14
|
+
onConfirm,
|
|
15
|
+
onClose,
|
|
16
|
+
returnFocusRef,
|
|
17
|
+
children
|
|
18
|
+
}) {
|
|
19
|
+
useLocaleRevision();
|
|
20
|
+
const [pending, setPending] = useState(false);
|
|
21
|
+
const descriptionId = useId();
|
|
22
|
+
const working = busy || pending;
|
|
23
|
+
return _jsxs(Dialog, {
|
|
24
|
+
open: open,
|
|
25
|
+
title: title,
|
|
26
|
+
descriptionId: consequence ? descriptionId : undefined,
|
|
27
|
+
onClose: onClose,
|
|
28
|
+
closeDisabled: working,
|
|
29
|
+
returnFocusRef: returnFocusRef,
|
|
30
|
+
className: "mdbase-confirm-dialog",
|
|
31
|
+
children: [consequence && _jsx("p", {
|
|
32
|
+
id: descriptionId,
|
|
33
|
+
children: consequence
|
|
34
|
+
}), children, _jsxs("footer", {
|
|
35
|
+
className: "mdbase-dialog-actions",
|
|
36
|
+
children: [_jsx("button", {
|
|
37
|
+
type: "button",
|
|
38
|
+
className: "mdbase-button is-tertiary",
|
|
39
|
+
"data-autofocus": true,
|
|
40
|
+
disabled: working,
|
|
41
|
+
onClick: onClose,
|
|
42
|
+
children: _i18n._(
|
|
43
|
+
/** i18n */
|
|
44
|
+
{
|
|
45
|
+
id: "dEgA5A",
|
|
46
|
+
message: "Cancel"
|
|
47
|
+
})
|
|
48
|
+
}), _jsx("button", {
|
|
49
|
+
type: "button",
|
|
50
|
+
className: "mdbase-button is-danger",
|
|
51
|
+
"aria-busy": working || undefined,
|
|
52
|
+
disabled: working || disabled,
|
|
53
|
+
onClick: async () => {
|
|
54
|
+
setPending(true);
|
|
55
|
+
try {
|
|
56
|
+
await onConfirm();
|
|
57
|
+
} finally {
|
|
58
|
+
setPending(false);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
children: working ? pendingLabel : confirmLabel
|
|
62
|
+
})]
|
|
63
|
+
})]
|
|
64
|
+
});
|
|
65
|
+
}
|
package/dist/Dialog.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
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, children }: {
|
|
7
3
|
readonly open: boolean;
|
|
8
4
|
readonly onClose: () => void;
|
|
9
5
|
readonly title: string;
|
|
6
|
+
readonly descriptionId?: string | undefined;
|
|
10
7
|
readonly className?: string | undefined;
|
|
11
8
|
readonly closeDisabled?: boolean;
|
|
9
|
+
readonly returnFocusRef?: RefObject<HTMLElement | null> | undefined;
|
|
12
10
|
readonly children: ReactNode;
|
|
13
|
-
}): JSX.Element;
|
|
11
|
+
}): JSX.Element | null;
|