@robert-stackflow/oneui 0.6.17 → 0.6.19
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 +8 -0
- package/README.md +3 -0
- package/components/Combobox.d.ts +4 -2
- package/components/Combobox.js +9 -3
- package/components/Menu.d.ts +2 -1
- package/components/Menu.js +25 -26
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# 0.6.19
|
|
2
|
+
|
|
3
|
+
- Add opt-in Combobox allowCustomValue input mode: preserve freely typed text on blur, Enter, and async loading or failure; only explicit option selection commits an option. Pass the selected option as the optional second onChange argument.
|
|
4
|
+
|
|
5
|
+
# 0.6.18
|
|
6
|
+
|
|
7
|
+
- Add Menu iconOnly triggers backed by the shared IconButton, preserving tooltip, focus restoration and keyboard menu interaction without a normal button border or minimum height.
|
|
8
|
+
|
|
1
9
|
# 0.6.17
|
|
2
10
|
|
|
3
11
|
- Prevent the animated SideBar selection highlight from expanding scrollable overflow while a preceding group collapses; preserve group and selection motion in both themes and color modes.
|
package/README.md
CHANGED
|
@@ -191,6 +191,7 @@ export function App() {
|
|
|
191
191
|
- `TreeSelect variant="category"` 在原有树选择交互上增加图标底块、子项数量与层级连线;默认 `variant="tree"` 保留简洁样式。两种样式均支持搜索、父子联动、多选、禁用、异步加载及键盘操作。`HierarchyOption.count` 可单独提供数量。
|
|
192
192
|
- `TreeTable` 复用 `Table` 的列定义,接收 `rows`、`rowKey`、`getChildren`、`rowLabel`;通过 `expanded` / `onExpandedChange` 控制展开,或使用 `defaultExpanded` / `defaultExpandAll`。`treeColumn` 默认为第一列,支持多级连线、方向键导航及独立行操作。`Column.align`、`Column.width` 可用于对齐和列宽。
|
|
193
193
|
- `Combobox mode="input"` 直接在触发框输入并在下方显示候选,保留 `loadOptions`、`onCreate` 和键盘选择。输入中的文本只用于搜索;选择候选或创建成功才提交选项值,关闭时恢复已选标签。默认 `mode="panel"` 继续使用弹层内搜索。
|
|
194
|
+
- 需要自由文本补全时加 `allowCustomValue`:每次输入直接更新值,失焦或回车不会强制替换成候选;方向键后回车或点击仍可选择候选。`onChange(value, option?)` 在主动选择时提供对应选项,自由输入时不提供选项,可用于区分手写地点与带坐标的地点候选。
|
|
194
195
|
- `MultiSelect display="tags"` 在触发框内展示可移除标签,复用 `TagInput` 的标签样式;默认 `display="summary"` 保留文字摘要。两种模式共享连续选择、搜索、数量限制和表单值。只读标签不可移除,禁用选项保持不可操作。
|
|
195
196
|
|
|
196
197
|
菜单项间距统一为 `--menu-item-spacing: 1px`,菜单快捷键为靠右的纯文字提示,不预留空的指示器位置。Desktop 与 Web 共用示例:`/pickers?view=hierarchy`、`/forms?view=advanced`、`/data?view=hierarchy`;层级表格中的增删改仅更新示例内存数据。以上扩展从 0.2.0 起提供。
|
|
@@ -253,3 +254,5 @@ AccountItem 接受标题、图标、描述、元数据及操作。PasskeyItem
|
|
|
253
254
|
扩展 Menu 的自定义触发内容、NumberInput 单位、Pagination 汇总显隐、Badge 原生属性、Tooltip 禁用选项及 Button 文字链接。修复日历月份标签碰撞和宽度适配,表格容器继承外框圆角。既有导出与默认 API 保持兼容。
|
|
254
255
|
|
|
255
256
|
验证:`npm run test:sidebar-navigation`、`npm run test:visual-foundations`、`npm run test:account-forms`、`npm run test:modal-pagination`、`npm run test:package`。新增回归覆盖 React 间距覆盖、正文颜色、表格圆角与文字按钮、现有 Combobox 键盘筛选、日期标签和窄屏溢出。
|
|
257
|
+
|
|
258
|
+
Menu 支持 iconOnly:`<Menu iconOnly label="更多操作" items={items} />` 复用 IconButton,默认显示更多图标;trigger 可替换图标,variant 可设置按钮类型。
|
package/components/Combobox.d.ts
CHANGED
|
@@ -2,12 +2,14 @@ import { type FieldOptions } from "./field";
|
|
|
2
2
|
import type { SelectOption } from "./types";
|
|
3
3
|
export type ComboboxProps = FieldOptions & {
|
|
4
4
|
value: string;
|
|
5
|
-
onChange(value: string): void;
|
|
5
|
+
onChange(value: string, option?: SelectOption): void;
|
|
6
6
|
options?: SelectOption[];
|
|
7
7
|
loadOptions?(query: string, signal: AbortSignal): Promise<SelectOption[]>;
|
|
8
8
|
onCreate?(label: string): string | void | Promise<string | void>;
|
|
9
9
|
label?: string;
|
|
10
10
|
placeholder?: string;
|
|
11
11
|
mode?: "panel" | "input";
|
|
12
|
+
/** In input mode, keep typed text as the value without requiring a choice. */
|
|
13
|
+
allowCustomValue?: boolean;
|
|
12
14
|
};
|
|
13
|
-
export declare function Combobox({ value, onChange, options, loadOptions, onCreate, label, placeholder, mode, ...props }: ComboboxProps): import("react").JSX.Element;
|
|
15
|
+
export declare function Combobox({ value, onChange, options, loadOptions, onCreate, label, placeholder, mode, allowCustomValue, ...props }: ComboboxProps): import("react").JSX.Element;
|
package/components/Combobox.js
CHANGED
|
@@ -31,13 +31,14 @@ function Combobox({
|
|
|
31
31
|
label = "\u641C\u7D22\u9009\u62E9",
|
|
32
32
|
placeholder = "\u8BF7\u9009\u62E9",
|
|
33
33
|
mode = "panel",
|
|
34
|
+
allowCustomValue = false,
|
|
34
35
|
...props
|
|
35
36
|
}) {
|
|
36
37
|
const field = useFieldControl({ ...props, label }), anchor = useRef(null), list = useRef(null), id = useId();
|
|
37
38
|
const [open, setOpen] = useState(false), [query, setQuery] = useState(""), [editing, setEditing] = useState(false), [remote, setRemote] = useState([]), [loading, setLoading] = useState(false), [error, setError] = useState(""), [failure, setFailure] = useState("load"), [active, setActive] = useState(-1), [created, setCreated] = useState(), [chosen, setChosen] = useState(), [creating, setCreating] = useState(false), [retry, setRetry] = useState(0);
|
|
38
39
|
const generation = useRef(0), restoring = useRef(false), loader = useRef(loadOptions);
|
|
39
40
|
loader.current = loadOptions;
|
|
40
|
-
const inline = mode === "input", async = !!loadOptions;
|
|
41
|
+
const inline = mode === "input", freeText = inline && allowCustomValue, async = !!loadOptions;
|
|
41
42
|
const close = useCallback(() => {
|
|
42
43
|
generation.current++;
|
|
43
44
|
setOpen(false);
|
|
@@ -95,7 +96,7 @@ function Combobox({
|
|
|
95
96
|
const choose = (item) => {
|
|
96
97
|
if (item.disabled || field.disabled || field.readOnly) return;
|
|
97
98
|
setChosen(item);
|
|
98
|
-
onChange(item.value);
|
|
99
|
+
onChange(item.value, item);
|
|
99
100
|
close();
|
|
100
101
|
anchor.current?.focus();
|
|
101
102
|
};
|
|
@@ -114,6 +115,7 @@ function Combobox({
|
|
|
114
115
|
generation.current++;
|
|
115
116
|
setLoading(async);
|
|
116
117
|
setQuery(text);
|
|
118
|
+
if (freeText) onChange(text);
|
|
117
119
|
setEditing(true);
|
|
118
120
|
setActive(inline ? -1 : 0);
|
|
119
121
|
setError("");
|
|
@@ -122,7 +124,7 @@ function Combobox({
|
|
|
122
124
|
useEffect(() => {
|
|
123
125
|
list.current?.querySelector('[data-active="true"]')?.scrollIntoView({ block: "nearest" });
|
|
124
126
|
}, [activeIndex, query, loading]);
|
|
125
|
-
const canCreate = !!onCreate && !!query.trim() && !filtered.some(
|
|
127
|
+
const canCreate = !freeText && !!onCreate && !!query.trim() && !filtered.some(
|
|
126
128
|
(item) => item.label.toLowerCase() === query.trim().toLowerCase()
|
|
127
129
|
);
|
|
128
130
|
const create = async () => {
|
|
@@ -171,6 +173,10 @@ function Combobox({
|
|
|
171
173
|
}
|
|
172
174
|
} else if (event.key === "Enter" && open) {
|
|
173
175
|
event.preventDefault();
|
|
176
|
+
if (freeText && activeIndex < 0) {
|
|
177
|
+
close();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
174
180
|
if (!loading && !creating && !error) {
|
|
175
181
|
const item = filtered[activeIndex < 0 ? first : activeIndex];
|
|
176
182
|
if (item) choose(item);
|
package/components/Menu.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
-
export declare function Menu({ label, items, trigger, variant, className, }: {
|
|
2
|
+
export declare function Menu({ label, items, trigger, variant, className, iconOnly, }: {
|
|
3
3
|
label: string;
|
|
4
4
|
trigger?: ReactNode;
|
|
5
5
|
variant?: "primary" | "secondary" | "ghost" | "danger";
|
|
6
6
|
className?: string;
|
|
7
|
+
iconOnly?: boolean;
|
|
7
8
|
items: {
|
|
8
9
|
label: string;
|
|
9
10
|
icon?: ReactNode;
|
package/components/Menu.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useId } from "react";
|
|
3
|
-
import { ChevronDown } from "lucide-react";
|
|
3
|
+
import { ChevronDown, MoreHorizontal } from "lucide-react";
|
|
4
4
|
import { Button } from "./Button.js";
|
|
5
|
+
import { IconButton } from "./IconButton.js";
|
|
5
6
|
import { MenuItem } from "./MenuItem.js";
|
|
6
7
|
import { Popover } from "./Popover.js";
|
|
7
8
|
import { usePopover } from "./usePopover.js";
|
|
@@ -9,34 +10,32 @@ function Menu({
|
|
|
9
10
|
label,
|
|
10
11
|
items,
|
|
11
12
|
trigger,
|
|
12
|
-
variant
|
|
13
|
-
className
|
|
13
|
+
variant,
|
|
14
|
+
className,
|
|
15
|
+
iconOnly = false
|
|
14
16
|
}) {
|
|
15
17
|
const pop = usePopover(), id = useId();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
30
|
-
event.preventDefault();
|
|
31
|
-
pop.show();
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
children: trigger ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
35
|
-
label,
|
|
36
|
-
/* @__PURE__ */ jsx(ChevronDown, { size: 14 })
|
|
37
|
-
] })
|
|
18
|
+
const triggerProps = {
|
|
19
|
+
variant: variant ?? (iconOnly ? "ghost" : "secondary"),
|
|
20
|
+
className,
|
|
21
|
+
"aria-label": label,
|
|
22
|
+
ref: pop.anchor,
|
|
23
|
+
"aria-haspopup": "menu",
|
|
24
|
+
"aria-expanded": pop.open,
|
|
25
|
+
"aria-controls": id,
|
|
26
|
+
onClick: pop.toggle,
|
|
27
|
+
onKeyDown: (event) => {
|
|
28
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
pop.show();
|
|
38
31
|
}
|
|
39
|
-
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
35
|
+
iconOnly ? /* @__PURE__ */ jsx(IconButton, { ...triggerProps, label, children: trigger ?? /* @__PURE__ */ jsx(MoreHorizontal, { size: 18 }) }) : /* @__PURE__ */ jsx(Button, { ...triggerProps, children: trigger ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
36
|
+
label,
|
|
37
|
+
/* @__PURE__ */ jsx(ChevronDown, { size: 14 })
|
|
38
|
+
] }) }),
|
|
40
39
|
/* @__PURE__ */ jsx(
|
|
41
40
|
Popover,
|
|
42
41
|
{
|