@oaiz/app-kit 0.1.4240 → 0.1.4250
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/package.json
CHANGED
|
@@ -63,7 +63,7 @@ export type ListViewProps<Row> = {
|
|
|
63
63
|
onFocusedChange?: (row: Row | null) => void;
|
|
64
64
|
/** Adds a row to a group; each group header shows a + button. */
|
|
65
65
|
onAddToGroup?: (groupKey: string) => void;
|
|
66
|
-
/** Menu items for a right-click on a row, such as `DropdownMenuItem`s. */
|
|
66
|
+
/** Menu items for a right-click or Shift+F10 on a row, such as `DropdownMenuItem`s. */
|
|
67
67
|
rowMenu?: (row: Row) => ReactNode;
|
|
68
68
|
/** Shown when no group has rows. */
|
|
69
69
|
empty: ReactNode;
|
|
@@ -88,7 +88,7 @@ function typingOrOverlay(target: EventTarget | null): boolean {
|
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* A dense, grouped list in the style of Linear. J and K (or the arrow keys) move the focus, X
|
|
91
|
-
* selects the focused row, Enter opens it, and a right-click opens `rowMenu`. Group headers
|
|
91
|
+
* selects the focused row, Enter opens it, and a right-click or Shift+F10 opens `rowMenu`. Group headers
|
|
92
92
|
* collapse and show their count.
|
|
93
93
|
*/
|
|
94
94
|
export function ListView<Row>({
|
|
@@ -27,7 +27,7 @@ const badgeVariants = cva(
|
|
|
27
27
|
'success-subtle':
|
|
28
28
|
'border-transparent bg-badge-success text-badge-success-foreground font-medium',
|
|
29
29
|
'warning-subtle':
|
|
30
|
-
'border-transparent bg-
|
|
30
|
+
'border-transparent bg-warning-bg-subtle text-warning-text font-medium',
|
|
31
31
|
'destructive-subtle':
|
|
32
32
|
'border-transparent bg-destructive-bg-subtle text-destructive-text font-medium',
|
|
33
33
|
neutral:
|
|
@@ -13,6 +13,11 @@ import {
|
|
|
13
13
|
const LONG_PRESS_MS = 500;
|
|
14
14
|
/** A touch that drifts further than this is a scroll or a drag, not a press. */
|
|
15
15
|
const LONG_PRESS_SLOP_PX = 10;
|
|
16
|
+
/**
|
|
17
|
+
* Windows and Linux browsers follow a Shift+F10 keydown with their own
|
|
18
|
+
* contextmenu event; one arriving this soon after belongs to that keypress.
|
|
19
|
+
*/
|
|
20
|
+
const KEYBOARD_CONTEXTMENU_WINDOW_MS = 1000;
|
|
16
21
|
|
|
17
22
|
interface ContextMenuContextValue {
|
|
18
23
|
openAt: (x: number, y: number) => void;
|
|
@@ -128,6 +133,7 @@ const ContextMenuTrigger = React.forwardRef<
|
|
|
128
133
|
onPointerUp,
|
|
129
134
|
onPointerCancel,
|
|
130
135
|
onClickCapture,
|
|
136
|
+
onKeyDown,
|
|
131
137
|
...props
|
|
132
138
|
},
|
|
133
139
|
ref,
|
|
@@ -139,6 +145,7 @@ const ContextMenuTrigger = React.forwardRef<
|
|
|
139
145
|
timer: ReturnType<typeof setTimeout>;
|
|
140
146
|
} | null>(null);
|
|
141
147
|
const openedByPress = React.useRef(false);
|
|
148
|
+
const openedByKeyAt = React.useRef<number | null>(null);
|
|
142
149
|
|
|
143
150
|
const cancelPress = () => {
|
|
144
151
|
if (press.current) clearTimeout(press.current.timer);
|
|
@@ -156,6 +163,13 @@ const ContextMenuTrigger = React.forwardRef<
|
|
|
156
163
|
if (disabled || event.defaultPrevented || !isInside(event)) return;
|
|
157
164
|
event.preventDefault();
|
|
158
165
|
cancelPress();
|
|
166
|
+
const keyOpenedAt = openedByKeyAt.current;
|
|
167
|
+
openedByKeyAt.current = null;
|
|
168
|
+
if (
|
|
169
|
+
keyOpenedAt !== null &&
|
|
170
|
+
event.timeStamp - keyOpenedAt < KEYBOARD_CONTEXTMENU_WINDOW_MS
|
|
171
|
+
)
|
|
172
|
+
return;
|
|
159
173
|
// The Menu key and Shift+F10 report no pointer position.
|
|
160
174
|
if (event.clientX === 0 && event.clientY === 0) {
|
|
161
175
|
const rect = event.currentTarget.getBoundingClientRect();
|
|
@@ -164,6 +178,28 @@ const ContextMenuTrigger = React.forwardRef<
|
|
|
164
178
|
openAt(event.clientX, event.clientY);
|
|
165
179
|
}
|
|
166
180
|
}}
|
|
181
|
+
// macOS browsers send no contextmenu event for Shift+F10, so the
|
|
182
|
+
// standard keyboard shortcut opens the menu here on every platform.
|
|
183
|
+
onKeyDown={(event: React.KeyboardEvent<HTMLElement>) => {
|
|
184
|
+
onKeyDown?.(event);
|
|
185
|
+
if (
|
|
186
|
+
disabled ||
|
|
187
|
+
event.defaultPrevented ||
|
|
188
|
+
event.key !== 'F10' ||
|
|
189
|
+
!event.shiftKey ||
|
|
190
|
+
!isInside(event)
|
|
191
|
+
)
|
|
192
|
+
return;
|
|
193
|
+
event.preventDefault();
|
|
194
|
+
cancelPress();
|
|
195
|
+
const target =
|
|
196
|
+
event.target instanceof HTMLElement
|
|
197
|
+
? event.target
|
|
198
|
+
: event.currentTarget;
|
|
199
|
+
const rect = target.getBoundingClientRect();
|
|
200
|
+
openedByKeyAt.current = event.timeStamp;
|
|
201
|
+
openAt(rect.left + 8, rect.top + 8);
|
|
202
|
+
}}
|
|
167
203
|
onPointerDown={(event: React.PointerEvent<HTMLElement>) => {
|
|
168
204
|
onPointerDown?.(event);
|
|
169
205
|
openedByPress.current = false;
|
|
@@ -72,6 +72,7 @@ export function RadioGroup({
|
|
|
72
72
|
disabled={disabled === true || option.disabled === true}
|
|
73
73
|
required={required}
|
|
74
74
|
aria-labelledby={`${id}-${index}-label`}
|
|
75
|
+
// oxlint-disable-next-line jsx-a11y/role-supports-aria-props -- ARIA 1.2 makes aria-invalid global, and screen readers announce it on native radios.
|
|
75
76
|
aria-invalid={error ? true : undefined}
|
|
76
77
|
aria-describedby={
|
|
77
78
|
[
|
|
@@ -80,9 +80,9 @@ const ToastClose = React.forwardRef<
|
|
|
80
80
|
className,
|
|
81
81
|
)}
|
|
82
82
|
toast-close=""
|
|
83
|
-
// The icon is decorative, so the button needs its own name.
|
|
84
|
-
aria-label="Dismiss"
|
|
85
83
|
{...props}
|
|
84
|
+
// The icon is decorative, so the button needs its own name.
|
|
85
|
+
aria-label={props['aria-label'] ?? 'Dismiss'}
|
|
86
86
|
>
|
|
87
87
|
<X className="h-4 w-4" />
|
|
88
88
|
</ToastPrimitives.Close>
|
|
@@ -34,8 +34,19 @@ function ToastText({
|
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export
|
|
37
|
+
export interface ToasterLabels {
|
|
38
|
+
/** Name of each toast's close button. */
|
|
39
|
+
close: string;
|
|
40
|
+
/** Announced with each toast, such as "Notification". */
|
|
41
|
+
toast: string;
|
|
42
|
+
/** Name of the toast region; `{hotkey}` is replaced with its shortcut (F8). */
|
|
43
|
+
viewport: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Pass translated `labels`; without them the labels are English. */
|
|
47
|
+
export function Toaster({ labels }: { labels?: ToasterLabels } = {}) {
|
|
38
48
|
const { toasts, dismiss } = useToast();
|
|
49
|
+
const closeLabel = labels?.close;
|
|
39
50
|
|
|
40
51
|
// Cmd+Z or Ctrl+Z undoes the newest open toast that offers Undo. Text
|
|
41
52
|
// fields keep their own undo.
|
|
@@ -62,7 +73,7 @@ export function Toaster() {
|
|
|
62
73
|
}, [dismiss, undoable]);
|
|
63
74
|
|
|
64
75
|
return (
|
|
65
|
-
<ToastProvider>
|
|
76
|
+
<ToastProvider label={labels?.toast}>
|
|
66
77
|
{toasts.map(function ({
|
|
67
78
|
id,
|
|
68
79
|
title,
|
|
@@ -94,7 +105,10 @@ export function Toaster() {
|
|
|
94
105
|
</div>
|
|
95
106
|
) : null}
|
|
96
107
|
</div>
|
|
97
|
-
<ToastClose
|
|
108
|
+
<ToastClose
|
|
109
|
+
className="top-1/2 -translate-y-1/2"
|
|
110
|
+
aria-label={closeLabel}
|
|
111
|
+
/>
|
|
98
112
|
</Toast>
|
|
99
113
|
);
|
|
100
114
|
}
|
|
@@ -108,11 +122,11 @@ export function Toaster() {
|
|
|
108
122
|
>
|
|
109
123
|
<ToastText title={title} description={description} />
|
|
110
124
|
{action}
|
|
111
|
-
<ToastClose />
|
|
125
|
+
<ToastClose aria-label={closeLabel} />
|
|
112
126
|
</Toast>
|
|
113
127
|
);
|
|
114
128
|
})}
|
|
115
|
-
<ToastViewport />
|
|
129
|
+
<ToastViewport label={labels?.viewport} />
|
|
116
130
|
</ToastProvider>
|
|
117
131
|
);
|
|
118
132
|
}
|