@robert-stackflow/oneui 0.6.23 → 0.6.24

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 CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.6.24
2
+
3
+ - Add native Segmented option counts without a separate badge surface.
4
+
5
+ - Add top-aligned Dialog placement and controlled, asynchronously populated CommandPalette search.
6
+ - Use shared EmptyState for command results and label click-triggered nested menus correctly.
7
+
1
8
  ## 0.6.23
2
9
 
3
10
  - 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 [query, setQuery] = useState(""), [active, setActive] = useState(null), [busy, setBusy] = useState(), [error, setError] = useState("");
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: "\u641C\u7D22\u547D\u4EE4",
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
  )
@@ -345,6 +345,7 @@ function ContextMenu({
345
345
  children: layers.map((menu) => /* @__PURE__ */ jsx(
346
346
  ContextMenuPanel,
347
347
  {
348
+ label: menu.level === 0 ? label : void 0,
348
349
  open: menu.open,
349
350
  onExited: () => exited(menu.key),
350
351
  onReady: (node) => {
@@ -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,
@@ -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;
@@ -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 : ""}`,
@@ -15,6 +15,10 @@
15
15
  backdrop-filter: blur(3px);
16
16
  animation: fade-in var(--popup-enter);
17
17
  }
18
+ .dialog[data-placement="top"] {
19
+ margin-top: min(10dvh, 96px);
20
+ margin-bottom: auto;
21
+ }
18
22
  .dialogHeader {
19
23
  display: flex;
20
24
  align-items: flex-start;
@@ -6,6 +6,7 @@ export declare function Segmented<T extends string>({ value, onChange, options,
6
6
  value: T;
7
7
  label: ReactNode;
8
8
  textValue?: string;
9
+ count?: number | string;
9
10
  disabled?: boolean;
10
11
  }[];
11
12
  label: string;
@@ -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__ */ jsx(
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: option.label
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robert-stackflow/oneui",
3
- "version": "0.6.23",
3
+ "version": "0.6.24",
4
4
  "description": "OneUI React components, application shell and portable visual themes",
5
5
  "type": "module",
6
6
  "sideEffects": [