@robert-stackflow/oneui 0.6.23 → 0.6.25
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/CHANGELOG.md +11 -0
- package/components/CommandPalette.d.ts +7 -1
- package/components/CommandPalette.js +22 -8
- package/components/ContextMenu.js +1 -0
- package/components/ContextMenuPanel.d.ts +2 -1
- package/components/ContextMenuPanel.js +3 -2
- package/components/Dialog.d.ts +2 -1
- package/components/Dialog.js +3 -1
- package/components/Dialog.module.css +4 -0
- package/components/Menu.d.ts +4 -2
- package/components/Menu.js +18 -4
- package/components/Segmented.d.ts +1 -0
- package/components/Segmented.js +6 -3
- package/components/Segmented.module.css +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
## 0.6.25
|
|
2
|
+
|
|
3
|
+
- Add Menu disabled state and triggerRef; blocked menus close and preserve dialog return focus through the native trigger.
|
|
4
|
+
|
|
5
|
+
## 0.6.24
|
|
6
|
+
|
|
7
|
+
- Add native Segmented option counts without a separate badge surface.
|
|
8
|
+
|
|
9
|
+
- Add top-aligned Dialog placement and controlled, asynchronously populated CommandPalette search.
|
|
10
|
+
- Use shared EmptyState for command results and label click-triggered nested menus correctly.
|
|
11
|
+
|
|
1
12
|
## 0.6.23
|
|
2
13
|
|
|
3
14
|
- Align nested Sidebar selection, hover and pressed row geometry; remove redundant noncompact tooltips.
|
|
@@ -21,5 +21,11 @@ export type CommandPaletteProps = {
|
|
|
21
21
|
hotkey?: boolean;
|
|
22
22
|
closeOnSelect?: boolean;
|
|
23
23
|
emptyText?: string;
|
|
24
|
+
query?: string;
|
|
25
|
+
onQueryChange?(value: string): void;
|
|
26
|
+
filterItems?: boolean;
|
|
27
|
+
loading?: boolean;
|
|
28
|
+
showFooter?: boolean;
|
|
29
|
+
placement?: "center" | "top";
|
|
24
30
|
};
|
|
25
|
-
export declare function CommandPalette({ open, onClose, onOpen, items, onSelect, title, placeholder, hotkey, closeOnSelect, emptyText, }: CommandPaletteProps): import("react").JSX.Element;
|
|
31
|
+
export declare function CommandPalette({ open, onClose, onOpen, items, onSelect, title, placeholder, hotkey, closeOnSelect, emptyText, query: suppliedQuery, onQueryChange, filterItems, loading, showFooter, placement, }: CommandPaletteProps): import("react").JSX.Element;
|
|
@@ -13,6 +13,7 @@ import { SearchField } from "./SearchField.js";
|
|
|
13
13
|
import { MenuItem } from "./MenuItem.js";
|
|
14
14
|
import { Spinner } from "./Spinner.js";
|
|
15
15
|
import { Banner } from "./Banner.js";
|
|
16
|
+
import { EmptyState } from "./EmptyState.js";
|
|
16
17
|
import { useSurfacePortal } from "./surfacePortal.js";
|
|
17
18
|
import s from "./CommandPalette.module.css";
|
|
18
19
|
const normalize = (value) => value.normalize("NFKD").replace(/\p{Diacritic}/gu, "").toLocaleLowerCase();
|
|
@@ -26,11 +27,23 @@ function CommandPalette({
|
|
|
26
27
|
placeholder = "\u641C\u7D22\u547D\u4EE4\u2026",
|
|
27
28
|
hotkey = true,
|
|
28
29
|
closeOnSelect = true,
|
|
29
|
-
emptyText = "\u6CA1\u6709\u5339\u914D\u7684\u547D\u4EE4"
|
|
30
|
+
emptyText = "\u6CA1\u6709\u5339\u914D\u7684\u547D\u4EE4",
|
|
31
|
+
query: suppliedQuery,
|
|
32
|
+
onQueryChange,
|
|
33
|
+
filterItems = true,
|
|
34
|
+
loading = false,
|
|
35
|
+
showFooter = true,
|
|
36
|
+
placement = "center"
|
|
30
37
|
}) {
|
|
31
|
-
const [
|
|
38
|
+
const [internalQuery, setInternalQuery] = useState(""), [active, setActive] = useState(null), [busy, setBusy] = useState(), [error, setError] = useState("");
|
|
39
|
+
const query = suppliedQuery ?? internalQuery;
|
|
40
|
+
const setQuery = (value) => {
|
|
41
|
+
setInternalQuery(value);
|
|
42
|
+
onQueryChange?.(value);
|
|
43
|
+
};
|
|
32
44
|
const root = useRef(null), revision = useRef(0), controller = useRef(null), id = useId(), owner = useSurfacePortal();
|
|
33
45
|
const results = useMemo(() => {
|
|
46
|
+
if (!filterItems) return items;
|
|
34
47
|
const tokens = normalize(query).trim().split(/\s+/).filter(Boolean);
|
|
35
48
|
return items.filter((item) => {
|
|
36
49
|
const text = normalize(
|
|
@@ -44,7 +57,7 @@ function CommandPalette({
|
|
|
44
57
|
);
|
|
45
58
|
return tokens.every((token) => text.includes(token));
|
|
46
59
|
});
|
|
47
|
-
}, [items, query]);
|
|
60
|
+
}, [items, query, filterItems]);
|
|
48
61
|
const actionable = (item) => !item.disabled && !!(item.onSelect || onSelect);
|
|
49
62
|
const grouped = /* @__PURE__ */ new Map();
|
|
50
63
|
for (const item of results) {
|
|
@@ -138,8 +151,9 @@ function CommandPalette({
|
|
|
138
151
|
open,
|
|
139
152
|
onClose: close,
|
|
140
153
|
title,
|
|
154
|
+
placement,
|
|
141
155
|
wide: true,
|
|
142
|
-
footer: /* @__PURE__ */ jsxs("div", { className: s.footer, children: [
|
|
156
|
+
footer: showFooter && /* @__PURE__ */ jsxs("div", { className: s.footer, children: [
|
|
143
157
|
/* @__PURE__ */ jsxs("span", { children: [
|
|
144
158
|
/* @__PURE__ */ jsx("kbd", { children: "\u2191 \u2193" }),
|
|
145
159
|
" \u9009\u62E9 ",
|
|
@@ -157,7 +171,7 @@ function CommandPalette({
|
|
|
157
171
|
/* @__PURE__ */ jsx(
|
|
158
172
|
SearchField,
|
|
159
173
|
{
|
|
160
|
-
label:
|
|
174
|
+
label: title,
|
|
161
175
|
placeholder,
|
|
162
176
|
value: query,
|
|
163
177
|
onChange: (value) => {
|
|
@@ -166,7 +180,7 @@ function CommandPalette({
|
|
|
166
180
|
setError("");
|
|
167
181
|
},
|
|
168
182
|
disabled: !!busy,
|
|
169
|
-
loading: !!busy,
|
|
183
|
+
loading: !!busy || loading,
|
|
170
184
|
role: "combobox",
|
|
171
185
|
"aria-autocomplete": "list",
|
|
172
186
|
"aria-expanded": open,
|
|
@@ -217,7 +231,7 @@ function CommandPalette({
|
|
|
217
231
|
role: "listbox",
|
|
218
232
|
"aria-label": "\u547D\u4EE4\u7ED3\u679C",
|
|
219
233
|
id,
|
|
220
|
-
"aria-busy": !!busy,
|
|
234
|
+
"aria-busy": !!busy || loading,
|
|
221
235
|
children: [
|
|
222
236
|
[...grouped].map(([group, commands]) => /* @__PURE__ */ jsxs(
|
|
223
237
|
"div",
|
|
@@ -257,7 +271,7 @@ function CommandPalette({
|
|
|
257
271
|
},
|
|
258
272
|
group
|
|
259
273
|
)),
|
|
260
|
-
!results.length && /* @__PURE__ */ jsx("div", { className: s.empty, children: emptyText })
|
|
274
|
+
!results.length && /* @__PURE__ */ jsx("div", { className: s.empty, children: loading ? /* @__PURE__ */ jsx(Spinner, { label: title }) : /* @__PURE__ */ jsx(EmptyState, { title: emptyText }) })
|
|
261
275
|
]
|
|
262
276
|
}
|
|
263
277
|
)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type KeyboardEvent } from "react";
|
|
2
2
|
import type { ContextMenuItem, MenuAction } from "./menuTypes";
|
|
3
|
-
export declare function ContextMenuPanel({ open, onExited, onPanelEnter, onReady, items, level, point, anchor, activeId, busy, error, onHover, onChoose, onKey, onScroll, }: {
|
|
3
|
+
export declare function ContextMenuPanel({ open, onExited, onPanelEnter, onReady, items, level, point, anchor, activeId, busy, error, onHover, onChoose, onKey, onScroll, label, }: {
|
|
4
4
|
open: boolean;
|
|
5
|
+
label?: string;
|
|
5
6
|
onExited(): void;
|
|
6
7
|
onPanelEnter(): void;
|
|
7
8
|
onReady(node: HTMLDivElement): void;
|
|
@@ -22,7 +22,8 @@ function ContextMenuPanel({
|
|
|
22
22
|
onHover,
|
|
23
23
|
onChoose,
|
|
24
24
|
onKey,
|
|
25
|
-
onScroll
|
|
25
|
+
onScroll,
|
|
26
|
+
label
|
|
26
27
|
}) {
|
|
27
28
|
const reserveIcon = items.some(
|
|
28
29
|
(item) => item.type !== "separator" && !!item.icon
|
|
@@ -104,7 +105,7 @@ function ContextMenuPanel({
|
|
|
104
105
|
ref,
|
|
105
106
|
role: "menu",
|
|
106
107
|
"aria-busy": !!busy,
|
|
107
|
-
"aria-label": level ? "\u5B50\u83DC\u5355 " + level : "\u53F3\u952E\u83DC\u5355",
|
|
108
|
+
"aria-label": label || (level ? "\u5B50\u83DC\u5355 " + level : "\u53F3\u952E\u83DC\u5355"),
|
|
108
109
|
"data-menu-level": level,
|
|
109
110
|
"data-menu-state": open ? "open" : "closing",
|
|
110
111
|
onPointerEnter: onPanelEnter,
|
package/components/Dialog.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ReactNode, type RefObject } from "react";
|
|
2
|
-
export declare function Dialog({ open: requestedOpen, onClose, title, children, footer, wide, size, role, descriptionId, busy, variant, headerIcon, tone, initialFocus, onAfterClose, className, returnFocus, fallbackFocus, portalContainer, closeLabel, }: {
|
|
2
|
+
export declare function Dialog({ open: requestedOpen, onClose, title, children, footer, wide, size, role, descriptionId, busy, variant, headerIcon, tone, initialFocus, onAfterClose, className, returnFocus, fallbackFocus, portalContainer, closeLabel, placement, }: {
|
|
3
3
|
open: boolean;
|
|
4
|
+
placement?: "center" | "top";
|
|
4
5
|
onClose(): void;
|
|
5
6
|
title: ReactNode;
|
|
6
7
|
children: ReactNode;
|
package/components/Dialog.js
CHANGED
|
@@ -41,7 +41,8 @@ function Dialog({
|
|
|
41
41
|
returnFocus,
|
|
42
42
|
fallbackFocus,
|
|
43
43
|
portalContainer,
|
|
44
|
-
closeLabel = "\u5173\u95ED\u5F39\u7A97"
|
|
44
|
+
closeLabel = "\u5173\u95ED\u5F39\u7A97",
|
|
45
|
+
placement = "center"
|
|
45
46
|
}) {
|
|
46
47
|
const defaultRoot = usePortalRoot();
|
|
47
48
|
const portalRoot = portalContainer ?? defaultRoot;
|
|
@@ -119,6 +120,7 @@ function Dialog({
|
|
|
119
120
|
"aria-busy": busy || void 0,
|
|
120
121
|
role,
|
|
121
122
|
"data-variant": variant,
|
|
123
|
+
"data-placement": placement,
|
|
122
124
|
"data-tone": content.tone,
|
|
123
125
|
"data-header-icon": !!content.headerIcon,
|
|
124
126
|
className: `${s.dialog} ${className} ${wide || size === "large" ? s.wide : ""} ${size === "small" ? s.small : ""} ${closing ? s.closing : ""}`,
|
package/components/Menu.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { type ReactNode } from "react";
|
|
2
|
-
export declare function Menu({ label, items, trigger, variant, className, iconOnly, }: {
|
|
1
|
+
import { type ReactNode, type Ref } from "react";
|
|
2
|
+
export declare function Menu({ label, items, trigger, variant, className, iconOnly, disabled, triggerRef, }: {
|
|
3
3
|
label: string;
|
|
4
4
|
trigger?: ReactNode;
|
|
5
5
|
variant?: "primary" | "secondary" | "ghost" | "danger";
|
|
6
6
|
className?: string;
|
|
7
7
|
iconOnly?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
triggerRef?: Ref<HTMLButtonElement>;
|
|
8
10
|
items: {
|
|
9
11
|
label: string;
|
|
10
12
|
icon?: ReactNode;
|
package/components/Menu.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
useCallback,
|
|
5
|
+
useId
|
|
6
|
+
} from "react";
|
|
4
7
|
import { ChevronDown, MoreHorizontal } from "lucide-react";
|
|
5
8
|
import { Button } from "./Button.js";
|
|
6
9
|
import { IconButton } from "./IconButton.js";
|
|
@@ -13,14 +16,25 @@ function Menu({
|
|
|
13
16
|
trigger,
|
|
14
17
|
variant,
|
|
15
18
|
className,
|
|
16
|
-
iconOnly = false
|
|
19
|
+
iconOnly = false,
|
|
20
|
+
disabled = false,
|
|
21
|
+
triggerRef
|
|
17
22
|
}) {
|
|
18
|
-
const pop = usePopover(), id = useId();
|
|
23
|
+
const pop = usePopover(disabled), id = useId();
|
|
24
|
+
const setTrigger = useCallback(
|
|
25
|
+
(node) => {
|
|
26
|
+
pop.anchor.current = node;
|
|
27
|
+
if (typeof triggerRef === "function") triggerRef(node);
|
|
28
|
+
else if (triggerRef) triggerRef.current = node;
|
|
29
|
+
},
|
|
30
|
+
[pop.anchor, triggerRef]
|
|
31
|
+
);
|
|
19
32
|
const triggerProps = {
|
|
20
33
|
variant: variant ?? (iconOnly ? "ghost" : "secondary"),
|
|
21
34
|
className,
|
|
22
35
|
"aria-label": label,
|
|
23
|
-
ref:
|
|
36
|
+
ref: setTrigger,
|
|
37
|
+
disabled,
|
|
24
38
|
"aria-haspopup": "menu",
|
|
25
39
|
"aria-expanded": pop.open,
|
|
26
40
|
"aria-controls": id,
|
package/components/Segmented.js
CHANGED
|
@@ -63,7 +63,7 @@ function Segmented({
|
|
|
63
63
|
"aria-label": label,
|
|
64
64
|
children: [
|
|
65
65
|
/* @__PURE__ */ jsx("span", { className: s.indicator, "aria-hidden": "true", "data-segment-indicator": true }),
|
|
66
|
-
options.map((option, index) => /* @__PURE__ */
|
|
66
|
+
options.map((option, index) => /* @__PURE__ */ jsxs(
|
|
67
67
|
"button",
|
|
68
68
|
{
|
|
69
69
|
type: "button",
|
|
@@ -71,13 +71,16 @@ function Segmented({
|
|
|
71
71
|
if (node) buttons.current.set(option.value, node);
|
|
72
72
|
else buttons.current.delete(option.value);
|
|
73
73
|
},
|
|
74
|
-
"aria-label": option.textValue,
|
|
74
|
+
"aria-label": option.textValue && option.count !== void 0 ? `${option.textValue} ${option.count}` : option.textValue,
|
|
75
75
|
"aria-pressed": value === option.value,
|
|
76
76
|
disabled: option.disabled,
|
|
77
77
|
tabIndex: (options.some((item) => item.value === value && !item.disabled) ? value === option.value : option === options.find((item) => !item.disabled)) ? 0 : -1,
|
|
78
78
|
onKeyDown: (event) => keyboard(event, index),
|
|
79
79
|
onClick: () => onChange(option.value),
|
|
80
|
-
children:
|
|
80
|
+
children: [
|
|
81
|
+
option.label,
|
|
82
|
+
option.count !== void 0 && /* @__PURE__ */ jsx("span", { className: s.count, children: option.count })
|
|
83
|
+
]
|
|
81
84
|
},
|
|
82
85
|
option.value
|
|
83
86
|
))
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
border: 1px solid var(--line);
|
|
11
11
|
border-radius: calc(var(--radius) - 2px);
|
|
12
12
|
}
|
|
13
|
+
.count {
|
|
14
|
+
font-size: 0.85em;
|
|
15
|
+
font-variant-numeric: tabular-nums;
|
|
16
|
+
opacity: 0.65;
|
|
17
|
+
}
|
|
13
18
|
.indicator {
|
|
14
19
|
opacity: var(--segment-opacity, 0);
|
|
15
20
|
position: absolute;
|