@robert-stackflow/oneui 0.5.0 → 0.5.2
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 +12 -0
- package/README.md +11 -0
- package/components/AppShell.d.ts +7 -1
- package/components/AppShell.js +14 -1
- package/components/AppShell.module.css +20 -0
- package/components/Button.module.css +6 -0
- package/components/Dialog.module.css +9 -0
- package/components/Drawer.module.css +9 -0
- package/components/MultiSelect.d.ts +2 -1
- package/components/MultiSelect.js +82 -13
- package/components/MultiSelect.module.css +6 -0
- package/components/Page.d.ts +1 -1
- package/components/Page.js +2 -2
- package/components/Page.module.css +11 -0
- package/components/index.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.2 — 2026-10-29
|
|
4
|
+
|
|
5
|
+
- Page、Dialog、Drawer 与 Button 将 CSS 动画关键帧定义收进各自模块,修复 Next.js 静态导出中动画引用被局部化后找不到全局关键帧的问题;Vite 与原有减少动态效果设置保持兼容。
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## 0.5.1 — 2026-10-29
|
|
9
|
+
|
|
10
|
+
- MultiSelect 新增 `onCreate`,标签模式在同一触发框内展示已选项,支持搜索创建、连续多选、错误重试,以及关闭后忽略异步创建结果。
|
|
11
|
+
- Page 支持可选 ReactNode 标题,可为无标题的内容区复用共享入场动画。
|
|
12
|
+
- AppShell 新增 `navigationGroups`,桌面侧栏与移动导航共享分组和分隔布局;保留原有扁平导航 API。
|
|
13
|
+
|
|
14
|
+
|
|
3
15
|
## 0.5.0 — 2026-10-29
|
|
4
16
|
|
|
5
17
|
- 新增 ActionSheet,复用 IconButton、Drawer 和 MenuItem;桌面使用紧凑底部面板,手机适配底部安全区域,支持禁用和危险操作。
|
package/README.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
React 组件、应用外壳和两套可互换的主题。无 Electron、React Router、账户 API 或持久化存储依赖。
|
|
4
4
|
|
|
5
|
+
## 标签创建与导航分组(0.5.1)
|
|
6
|
+
|
|
7
|
+
`MultiSelect display="tags"` 将可移除标签放在同一个触发框内;可选 `onCreate(label)` 返回新选项值(支持 Promise)。搜索结果中显示创建入口,成功后连续多选;错误可重试,关闭或卸载后不再应用异步结果。原有摘要模式和静态选项用法保持兼容。
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
<MultiSelect label="标签" display="tags" value={tags} options={options}
|
|
11
|
+
onChange={setTags} onCreate={name => name} />
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`AppShell.navigationGroups` 支持 `{id, label?, items}` 分组,主导航、标签或其他入口共享分隔与标题样式,桌面与移动抽屉一致;不传时沿用 `navigation`。`Page.title` 可省略或传 ReactNode,可在无标题内容区复用共享入场动画。
|
|
15
|
+
|
|
5
16
|
## 操作面板(0.5.0)
|
|
6
17
|
|
|
7
18
|
`ActionSheet` 使用带无障碍名称的更多图标按钮打开底部操作面板;`items` 支持 `label`、`icon`、`disabled`、`danger` 和 `action`。选择后先完成关闭和焦点恢复,再执行操作,可安全打开另一个弹窗。桌面为紧凑面板,手机贴合底部安全区域。
|
package/components/AppShell.d.ts
CHANGED
|
@@ -14,8 +14,14 @@ export declare function ShellHeader({ title, collapsed, onToggle, onMenu, action
|
|
|
14
14
|
windowControls?: ReactNode;
|
|
15
15
|
draggable?: boolean;
|
|
16
16
|
}): import("react").JSX.Element;
|
|
17
|
+
export interface NavigationGroup {
|
|
18
|
+
id: string;
|
|
19
|
+
label?: string;
|
|
20
|
+
items: readonly NavigationItem[];
|
|
21
|
+
}
|
|
17
22
|
export interface AppShellProps {
|
|
18
23
|
navigation: readonly NavigationItem[];
|
|
24
|
+
navigationGroups?: readonly NavigationGroup[];
|
|
19
25
|
settingsItem?: NavigationItem;
|
|
20
26
|
active: string;
|
|
21
27
|
title: string;
|
|
@@ -34,4 +40,4 @@ export interface AppShellProps {
|
|
|
34
40
|
basePath?: string;
|
|
35
41
|
showHeader?: boolean;
|
|
36
42
|
}
|
|
37
|
-
export declare function AppShell({ navigation, settingsItem, active, title, collapsed, onCollapsedChange, onNavigate, children, headerActions, sidebarFooter, windowControls, draggable, brandName, brandIcon, brand, homePath, basePath, showHeader, }: AppShellProps): import("react").JSX.Element;
|
|
43
|
+
export declare function AppShell({ navigation, navigationGroups, settingsItem, active, title, collapsed, onCollapsedChange, onNavigate, children, headerActions, sidebarFooter, windowControls, draggable, brandName, brandIcon, brand, homePath, basePath, showHeader, }: AppShellProps): import("react").JSX.Element;
|
package/components/AppShell.js
CHANGED
|
@@ -57,6 +57,7 @@ function ShellHeader({
|
|
|
57
57
|
}
|
|
58
58
|
function AppShell({
|
|
59
59
|
navigation,
|
|
60
|
+
navigationGroups,
|
|
60
61
|
settingsItem,
|
|
61
62
|
active,
|
|
62
63
|
title,
|
|
@@ -117,7 +118,19 @@ function AppShell({
|
|
|
117
118
|
] })
|
|
118
119
|
}
|
|
119
120
|
),
|
|
120
|
-
/* @__PURE__ */ jsx("nav", { "aria-label": "\u4E3B\u5BFC\u822A", className: s.navigation, children:
|
|
121
|
+
/* @__PURE__ */ jsx("nav", { "aria-label": "\u4E3B\u5BFC\u822A", className: s.navigation, children: navigationGroups ? navigationGroups.map((group) => /* @__PURE__ */ jsxs(
|
|
122
|
+
"div",
|
|
123
|
+
{
|
|
124
|
+
className: s.navigationGroup,
|
|
125
|
+
role: "group",
|
|
126
|
+
"aria-label": group.label,
|
|
127
|
+
children: [
|
|
128
|
+
group.label && /* @__PURE__ */ jsx("div", { className: s.groupLabel, children: group.label }),
|
|
129
|
+
group.items.map(item)
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
group.id
|
|
133
|
+
)) : navigation.map(item) }),
|
|
121
134
|
(settingsItem || sidebarFooter) && /* @__PURE__ */ jsxs("div", { className: s.bottom, children: [
|
|
122
135
|
settingsItem && /* @__PURE__ */ jsx("nav", { "aria-label": "\u8BBE\u7F6E", className: s.navigation, children: item(settingsItem) }),
|
|
123
136
|
sidebarFooter
|
|
@@ -249,3 +249,23 @@
|
|
|
249
249
|
.header[data-window-controls="true"] {
|
|
250
250
|
padding-right: 8px;
|
|
251
251
|
}
|
|
252
|
+
|
|
253
|
+
.navigationGroup {
|
|
254
|
+
display: flex;
|
|
255
|
+
flex-direction: column;
|
|
256
|
+
gap: 4px;
|
|
257
|
+
}
|
|
258
|
+
.navigationGroup + .navigationGroup {
|
|
259
|
+
margin-top: 18px;
|
|
260
|
+
padding-top: 18px;
|
|
261
|
+
border-top: 1px solid var(--line);
|
|
262
|
+
}
|
|
263
|
+
.groupLabel {
|
|
264
|
+
color: var(--muted);
|
|
265
|
+
font-size: 11px;
|
|
266
|
+
padding: 0 12px 6px;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.shell[data-collapsed="true"] > .sidebar .groupLabel {
|
|
270
|
+
display: none;
|
|
271
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type FieldOptions } from "./field";
|
|
2
2
|
import type { SelectOption } from "./types";
|
|
3
|
-
export declare function MultiSelect({ value, onChange, options, label, disabled, readOnly, required, name, id: controlId, error, hint, maxSelected, clearable, placeholder, display, ...aria }: FieldOptions & {
|
|
3
|
+
export declare function MultiSelect({ value, onChange, options, label, disabled, readOnly, required, name, id: controlId, error, hint, maxSelected, clearable, placeholder, display, onCreate, ...aria }: FieldOptions & {
|
|
4
4
|
value: string[];
|
|
5
5
|
onChange(value: string[]): void;
|
|
6
6
|
options: SelectOption[];
|
|
@@ -10,4 +10,5 @@ export declare function MultiSelect({ value, onChange, options, label, disabled,
|
|
|
10
10
|
clearable?: boolean;
|
|
11
11
|
placeholder?: string;
|
|
12
12
|
display?: "summary" | "tags";
|
|
13
|
+
onCreate?(label: string): string | void | Promise<string | void>;
|
|
13
14
|
}): import("react").JSX.Element;
|
|
@@ -4,7 +4,7 @@ import { fieldTriggerProps, useFieldControl } from "./field.js";
|
|
|
4
4
|
import { MenuItem } from "./MenuItem.js";
|
|
5
5
|
import { SelectTrigger } from "./SelectTrigger.js";
|
|
6
6
|
import { useEffect, useId, useRef, useState } from "react";
|
|
7
|
-
import { Search } from "lucide-react";
|
|
7
|
+
import { Plus, Search } from "lucide-react";
|
|
8
8
|
import { Popover } from "./Popover.js";
|
|
9
9
|
import { usePopover } from "./usePopover.js";
|
|
10
10
|
import { Button } from "./Button.js";
|
|
@@ -28,6 +28,7 @@ function MultiSelect({
|
|
|
28
28
|
clearable = true,
|
|
29
29
|
placeholder = "\u8BF7\u9009\u62E9",
|
|
30
30
|
display = "summary",
|
|
31
|
+
onCreate,
|
|
31
32
|
...aria
|
|
32
33
|
}) {
|
|
33
34
|
const field = useFieldControl({
|
|
@@ -43,31 +44,78 @@ function MultiSelect({
|
|
|
43
44
|
});
|
|
44
45
|
const pop = usePopover(
|
|
45
46
|
field.disabled || field.readOnly
|
|
46
|
-
), [query, setQuery] = useState(""), list = useRef(null), search = useRef(null), id = useId();
|
|
47
|
+
), [query, setQuery] = useState(""), [created, setCreated] = useState([]), [creating, setCreating] = useState(false), [createError, setCreateError] = useState(""), generation = useRef(0), open = useRef(pop.open), selected = useRef(value), list = useRef(null), search = useRef(null), id = useId();
|
|
47
48
|
const { disabled: triggerDisabled, ...tagField } = fieldTriggerProps(field);
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
open.current = pop.open;
|
|
50
|
+
selected.current = value;
|
|
51
|
+
const available = [
|
|
52
|
+
...options,
|
|
53
|
+
...created.filter(
|
|
54
|
+
(item) => !options.some((option) => option.value === item.value)
|
|
55
|
+
)
|
|
56
|
+
];
|
|
57
|
+
const reserveIcon = available.some((option) => !!option.icon);
|
|
58
|
+
const filtered = available.filter(
|
|
50
59
|
(item) => item.label.toLowerCase().includes(query.toLowerCase())
|
|
51
60
|
);
|
|
52
61
|
const toggle = (option) => {
|
|
53
|
-
if (!field.disabled && !field.readOnly && !option.disabled && (value.includes(option.value) || value.length < maxSelected))
|
|
62
|
+
if (!creating && !field.disabled && !field.readOnly && !option.disabled && (value.includes(option.value) || value.length < maxSelected))
|
|
54
63
|
onChange(
|
|
55
64
|
value.includes(option.value) ? value.filter((v) => v !== option.value) : [...value, option.value]
|
|
56
65
|
);
|
|
57
66
|
};
|
|
67
|
+
const candidate = query.trim();
|
|
68
|
+
const canCreate = !!onCreate && !!candidate && !available.some(
|
|
69
|
+
(option) => option.label.toLowerCase() === candidate.toLowerCase()
|
|
70
|
+
);
|
|
71
|
+
const create = async () => {
|
|
72
|
+
if (!onCreate || !canCreate || creating || field.disabled || field.readOnly || value.length >= maxSelected)
|
|
73
|
+
return;
|
|
74
|
+
const revision = generation.current;
|
|
75
|
+
setCreating(true);
|
|
76
|
+
setCreateError("");
|
|
77
|
+
try {
|
|
78
|
+
const id2 = await onCreate(candidate) || candidate;
|
|
79
|
+
if (!open.current || revision !== generation.current) return;
|
|
80
|
+
setCreated(
|
|
81
|
+
(previous) => previous.some((option) => option.value === id2) ? previous : [...previous, { value: id2, label: candidate }]
|
|
82
|
+
);
|
|
83
|
+
if (!selected.current.includes(id2)) onChange([...selected.current, id2]);
|
|
84
|
+
setQuery("");
|
|
85
|
+
requestAnimationFrame(() => {
|
|
86
|
+
if (open.current) search.current?.focus();
|
|
87
|
+
});
|
|
88
|
+
} catch (failure) {
|
|
89
|
+
if (open.current && revision === generation.current)
|
|
90
|
+
setCreateError(
|
|
91
|
+
failure instanceof Error ? failure.message : "\u521B\u5EFA\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002"
|
|
92
|
+
);
|
|
93
|
+
} finally {
|
|
94
|
+
if (revision === generation.current) setCreating(false);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
useEffect(
|
|
98
|
+
() => () => {
|
|
99
|
+
generation.current++;
|
|
100
|
+
},
|
|
101
|
+
[]
|
|
102
|
+
);
|
|
58
103
|
useEffect(() => {
|
|
104
|
+
generation.current++;
|
|
105
|
+
setCreating(false);
|
|
106
|
+
setCreateError("");
|
|
59
107
|
if (pop.open) {
|
|
60
108
|
setQuery("");
|
|
61
109
|
search.current?.focus();
|
|
62
110
|
}
|
|
63
111
|
}, [pop.open]);
|
|
64
112
|
const remove = (id2) => {
|
|
65
|
-
if (field.disabled || field.readOnly ||
|
|
113
|
+
if (creating || field.disabled || field.readOnly || available.find((option) => option.value === id2)?.disabled)
|
|
66
114
|
return;
|
|
67
115
|
onChange(value.filter((v) => v !== id2));
|
|
68
116
|
pop.anchor.current?.focus();
|
|
69
117
|
};
|
|
70
|
-
const summary = value.length ?
|
|
118
|
+
const summary = value.length ? available.filter((item) => value.includes(item.value)).map((item) => item.label).slice(0, 2).join("\u3001") + (value.length > 2 ? ` +${value.length - 2}` : "") : placeholder;
|
|
71
119
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
72
120
|
display === "tags" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
73
121
|
/* @__PURE__ */ jsxs(
|
|
@@ -100,13 +148,13 @@ function MultiSelect({
|
|
|
100
148
|
},
|
|
101
149
|
children: [
|
|
102
150
|
value.map((id2) => {
|
|
103
|
-
const option =
|
|
151
|
+
const option = available.find((option2) => option2.value === id2);
|
|
104
152
|
return /* @__PURE__ */ jsx(
|
|
105
153
|
SelectionTag,
|
|
106
154
|
{
|
|
107
155
|
label: option?.label || id2,
|
|
108
156
|
icon: option?.icon,
|
|
109
|
-
disabled: field.disabled || option?.disabled,
|
|
157
|
+
disabled: field.disabled || creating || option?.disabled,
|
|
110
158
|
onRemove: field.readOnly ? void 0 : () => remove(id2),
|
|
111
159
|
removeLabel: "\u79FB\u9664 " + (option?.label || id2)
|
|
112
160
|
},
|
|
@@ -163,7 +211,18 @@ function MultiSelect({
|
|
|
163
211
|
"aria-label": `\u641C\u7D22${label}`,
|
|
164
212
|
placeholder: "\u641C\u7D22\u9009\u9879\u2026",
|
|
165
213
|
value: query,
|
|
166
|
-
|
|
214
|
+
disabled: creating,
|
|
215
|
+
onChange: (e) => {
|
|
216
|
+
setQuery(e.target.value);
|
|
217
|
+
setCreateError("");
|
|
218
|
+
},
|
|
219
|
+
onKeyDown: (event) => {
|
|
220
|
+
if (event.key === "Enter" && canCreate) {
|
|
221
|
+
event.preventDefault();
|
|
222
|
+
event.stopPropagation();
|
|
223
|
+
void create();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
167
226
|
}
|
|
168
227
|
)
|
|
169
228
|
] }),
|
|
@@ -188,12 +247,22 @@ function MultiSelect({
|
|
|
188
247
|
selection: "checkbox",
|
|
189
248
|
role: "option",
|
|
190
249
|
"aria-selected": value.includes(option.value),
|
|
191
|
-
disabled: option.disabled || !value.includes(option.value) && value.length >= maxSelected,
|
|
250
|
+
disabled: creating || option.disabled || !value.includes(option.value) && value.length >= maxSelected,
|
|
192
251
|
onClick: () => toggle(option)
|
|
193
252
|
},
|
|
194
253
|
option.value
|
|
195
254
|
)),
|
|
196
|
-
|
|
255
|
+
canCreate && /* @__PURE__ */ jsx(
|
|
256
|
+
MenuItem,
|
|
257
|
+
{
|
|
258
|
+
label: creating ? "\u6B63\u5728\u521B\u5EFA\u2026" : "\u521B\u5EFA\u201C" + candidate + "\u201D",
|
|
259
|
+
icon: /* @__PURE__ */ jsx(Plus, { size: 16 }),
|
|
260
|
+
disabled: creating || value.length >= maxSelected,
|
|
261
|
+
onClick: () => void create()
|
|
262
|
+
}
|
|
263
|
+
),
|
|
264
|
+
!filtered.length && !canCreate && /* @__PURE__ */ jsx("p", { className: s.noResults, children: "\u6CA1\u6709\u5339\u914D\u7684\u9009\u9879" }),
|
|
265
|
+
createError && /* @__PURE__ */ jsx("p", { className: s.createError, role: "alert", children: createError })
|
|
197
266
|
]
|
|
198
267
|
}
|
|
199
268
|
),
|
|
@@ -203,7 +272,7 @@ function MultiSelect({
|
|
|
203
272
|
{
|
|
204
273
|
variant: "ghost",
|
|
205
274
|
size: "small",
|
|
206
|
-
disabled: !value.length,
|
|
275
|
+
disabled: creating || !value.length,
|
|
207
276
|
onClick: () => onChange([]),
|
|
208
277
|
children: "\u6E05\u7A7A"
|
|
209
278
|
}
|
package/components/Page.d.ts
CHANGED
package/components/Page.js
CHANGED
|
@@ -7,9 +7,9 @@ function Page({
|
|
|
7
7
|
children
|
|
8
8
|
}) {
|
|
9
9
|
return /* @__PURE__ */ jsxs("div", { className: s.page, children: [
|
|
10
|
-
/* @__PURE__ */ jsxs("header", { className: s.heading, children: [
|
|
10
|
+
(title || description || actions) && /* @__PURE__ */ jsxs("header", { className: s.heading, children: [
|
|
11
11
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
12
|
-
/* @__PURE__ */ jsx("h1", { children: title }),
|
|
12
|
+
title && /* @__PURE__ */ jsx("h1", { children: title }),
|
|
13
13
|
description && /* @__PURE__ */ jsx("p", { children: description })
|
|
14
14
|
] }),
|
|
15
15
|
actions && /* @__PURE__ */ jsx("div", { className: s.actions, children: actions })
|
package/components/index.d.ts
CHANGED
|
@@ -151,7 +151,7 @@ export { ThemeProvider } from "./ThemeProvider";
|
|
|
151
151
|
export type { UITheme, ColorMode } from "./ThemeProvider";
|
|
152
152
|
export { ThemeStylePicker } from "./ThemeStylePicker";
|
|
153
153
|
export { AppShell, ShellHeader } from "./AppShell";
|
|
154
|
-
export type { NavigationItem, AppShellProps } from "./AppShell";
|
|
154
|
+
export type { NavigationItem, NavigationGroup, AppShellProps, } from "./AppShell";
|
|
155
155
|
export { SettingsLayout, SettingsCard } from "./SettingsLayout";
|
|
156
156
|
export { AppearanceSettings } from "./AppearanceSettings";
|
|
157
157
|
export { appearanceDefaults, normalizeAppearance } from "./appearance";
|