@robert-stackflow/oneui 0.4.2 → 0.5.0
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 +6 -0
- package/README.md +13 -0
- package/components/ActionSheet.d.ts +14 -0
- package/components/ActionSheet.js +78 -0
- package/components/ActionSheet.module.css +27 -0
- package/components/Drawer.d.ts +2 -1
- package/components/Drawer.js +4 -0
- package/components/FormField.module.css +8 -0
- package/components/IconButton.d.ts +2 -2
- package/components/index.d.ts +1 -0
- package/components/index.js +2 -0
- package/package.json +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0 — 2026-10-29
|
|
4
|
+
|
|
5
|
+
- 新增 ActionSheet,复用 IconButton、Drawer 和 MenuItem;桌面使用紧凑底部面板,手机适配底部安全区域,支持禁用和危险操作。
|
|
6
|
+
- Drawer 新增 `onAfterClose`,在关闭动画与焦点恢复完成后执行后续操作,避免操作面板与新弹窗重叠。
|
|
7
|
+
- 横向 FormField 包含多行输入时,标签靠上对齐;单行控件和手机纵向布局保持原有排列。
|
|
8
|
+
|
|
3
9
|
## 0.4.2 — 2026-10-29
|
|
4
10
|
|
|
5
11
|
- 图标、Emoji 和符号目录改用可被构建工具识别的异步 JSON 导入,修复 npm 包在 Vite 开发预打包后资源相对路径失效的问题;生产构建继续按需加载。
|
package/README.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
React 组件、应用外壳和两套可互换的主题。无 Electron、React Router、账户 API 或持久化存储依赖。
|
|
4
4
|
|
|
5
|
+
## 操作面板(0.5.0)
|
|
6
|
+
|
|
7
|
+
`ActionSheet` 使用带无障碍名称的更多图标按钮打开底部操作面板;`items` 支持 `label`、`icon`、`disabled`、`danger` 和 `action`。选择后先完成关闭和焦点恢复,再执行操作,可安全打开另一个弹窗。桌面为紧凑面板,手机贴合底部安全区域。
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
<ActionSheet label="图片操作 1" title="图片操作" items={[
|
|
11
|
+
{ label: '编辑图片', action: editPhoto },
|
|
12
|
+
{ label: '移除图片', danger: true, action: removePhoto },
|
|
13
|
+
]} />
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
横向 `FormField` 内包含 `Textarea` 时,标签自动靠上排列;手机仍使用纵向布局。`Drawer.onAfterClose` 可在关闭动画与焦点恢复完成后执行后续操作。
|
|
17
|
+
|
|
5
18
|
## 使用
|
|
6
19
|
|
|
7
20
|
```sh
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type ActionSheetItem = {
|
|
3
|
+
label: string;
|
|
4
|
+
icon?: ReactNode;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
danger?: boolean;
|
|
7
|
+
action(): void;
|
|
8
|
+
};
|
|
9
|
+
export declare function ActionSheet({ label, title, items, disabled, }: {
|
|
10
|
+
label: string;
|
|
11
|
+
title?: string;
|
|
12
|
+
items: ActionSheetItem[];
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
import { MoreHorizontal } from "lucide-react";
|
|
4
|
+
import { Button } from "./Button.js";
|
|
5
|
+
import { Drawer } from "./Drawer.js";
|
|
6
|
+
import { IconButton } from "./IconButton.js";
|
|
7
|
+
import { MenuItem } from "./MenuItem.js";
|
|
8
|
+
import s from "./ActionSheet.module.css";
|
|
9
|
+
function ActionSheet({
|
|
10
|
+
label,
|
|
11
|
+
title = label,
|
|
12
|
+
items,
|
|
13
|
+
disabled = false
|
|
14
|
+
}) {
|
|
15
|
+
const [open, setOpen] = useState(false);
|
|
16
|
+
const [rendered, setRendered] = useState(false);
|
|
17
|
+
const trigger = useRef(null);
|
|
18
|
+
const pending = useRef(null);
|
|
19
|
+
const cancel = () => {
|
|
20
|
+
pending.current = null;
|
|
21
|
+
setOpen(false);
|
|
22
|
+
};
|
|
23
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
24
|
+
/* @__PURE__ */ jsx(
|
|
25
|
+
IconButton,
|
|
26
|
+
{
|
|
27
|
+
ref: trigger,
|
|
28
|
+
label,
|
|
29
|
+
disabled,
|
|
30
|
+
"aria-haspopup": "dialog",
|
|
31
|
+
"aria-expanded": open,
|
|
32
|
+
onClick: () => {
|
|
33
|
+
setRendered(true);
|
|
34
|
+
setOpen(true);
|
|
35
|
+
},
|
|
36
|
+
children: /* @__PURE__ */ jsx(MoreHorizontal, { size: 18 })
|
|
37
|
+
}
|
|
38
|
+
),
|
|
39
|
+
rendered && /* @__PURE__ */ jsx(
|
|
40
|
+
Drawer,
|
|
41
|
+
{
|
|
42
|
+
open,
|
|
43
|
+
onClose: cancel,
|
|
44
|
+
title,
|
|
45
|
+
placement: "bottom",
|
|
46
|
+
size: "auto",
|
|
47
|
+
closable: false,
|
|
48
|
+
returnFocus: trigger,
|
|
49
|
+
className: s.sheet,
|
|
50
|
+
onAfterClose: () => {
|
|
51
|
+
setRendered(false);
|
|
52
|
+
const action = pending.current;
|
|
53
|
+
pending.current = null;
|
|
54
|
+
action?.();
|
|
55
|
+
},
|
|
56
|
+
footer: /* @__PURE__ */ jsx(Button, { className: s.cancel, onClick: cancel, children: "\u53D6\u6D88" }),
|
|
57
|
+
children: /* @__PURE__ */ jsx("div", { className: s.actions, children: items.map((item) => /* @__PURE__ */ jsx(
|
|
58
|
+
MenuItem,
|
|
59
|
+
{
|
|
60
|
+
label: item.label,
|
|
61
|
+
icon: item.icon,
|
|
62
|
+
reserveIcon: items.some((entry) => !!entry.icon),
|
|
63
|
+
disabled: item.disabled,
|
|
64
|
+
tone: item.danger ? "danger" : "default",
|
|
65
|
+
onClick: () => {
|
|
66
|
+
pending.current = item.action;
|
|
67
|
+
setOpen(false);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
item.label
|
|
71
|
+
)) })
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
] });
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
ActionSheet
|
|
78
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
dialog.sheet[data-placement="bottom"] {
|
|
2
|
+
inset: auto 16px 16px;
|
|
3
|
+
margin: 0 auto;
|
|
4
|
+
width: min(480px, calc(100vw - 32px));
|
|
5
|
+
height: auto;
|
|
6
|
+
max-height: min(80dvh, 640px);
|
|
7
|
+
border-radius: var(--card-radius);
|
|
8
|
+
}
|
|
9
|
+
.sheet [data-drawer-body] {
|
|
10
|
+
padding: 12px;
|
|
11
|
+
}
|
|
12
|
+
.actions {
|
|
13
|
+
display: grid;
|
|
14
|
+
gap: 1px;
|
|
15
|
+
}
|
|
16
|
+
.cancel {
|
|
17
|
+
width: 100%;
|
|
18
|
+
}
|
|
19
|
+
@media (max-width: 600px) {
|
|
20
|
+
dialog.sheet[data-placement="bottom"] {
|
|
21
|
+
inset: auto 0 0;
|
|
22
|
+
width: 100vw;
|
|
23
|
+
max-height: 85dvh;
|
|
24
|
+
border-radius: var(--card-radius) var(--card-radius) 0 0;
|
|
25
|
+
padding-bottom: env(safe-area-inset-bottom);
|
|
26
|
+
}
|
|
27
|
+
}
|
package/components/Drawer.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type DrawerPlacement = "left" | "right" | "top" | "bottom";
|
|
|
3
3
|
export type DrawerProps = {
|
|
4
4
|
open: boolean;
|
|
5
5
|
onClose(): void;
|
|
6
|
+
onAfterClose?(): void;
|
|
6
7
|
title: string;
|
|
7
8
|
description?: ReactNode;
|
|
8
9
|
children: ReactNode;
|
|
@@ -16,4 +17,4 @@ export type DrawerProps = {
|
|
|
16
17
|
returnFocus?: RefObject<HTMLElement | null>;
|
|
17
18
|
className?: string;
|
|
18
19
|
};
|
|
19
|
-
export declare function Drawer({ open: requestedOpen, onClose, title, description, children, footer, placement, size, closable, closeOnEscape, closeOnBackdrop, initialFocus, returnFocus, className, }: DrawerProps): import("react").ReactPortal;
|
|
20
|
+
export declare function Drawer({ open: requestedOpen, onClose, onAfterClose, title, description, children, footer, placement, size, closable, closeOnEscape, closeOnBackdrop, initialFocus, returnFocus, className, }: DrawerProps): import("react").ReactPortal;
|
package/components/Drawer.js
CHANGED
|
@@ -28,6 +28,7 @@ const offsets = {
|
|
|
28
28
|
function Drawer({
|
|
29
29
|
open: requestedOpen,
|
|
30
30
|
onClose,
|
|
31
|
+
onAfterClose,
|
|
31
32
|
title,
|
|
32
33
|
description,
|
|
33
34
|
children,
|
|
@@ -46,6 +47,8 @@ function Drawer({
|
|
|
46
47
|
const { rememberFocus, restoreFocus } = useModalFocus(ref, returnFocus);
|
|
47
48
|
const opened = useRef(open), backdropDown = useRef(false), titleId = useId(), descriptionId = useId();
|
|
48
49
|
const [closing, setClosing] = useState(false);
|
|
50
|
+
const afterClose = useRef(onAfterClose);
|
|
51
|
+
afterClose.current = onAfterClose;
|
|
49
52
|
useModalScrollLock(open || closing);
|
|
50
53
|
opened.current = open;
|
|
51
54
|
useEffect(() => {
|
|
@@ -87,6 +90,7 @@ function Drawer({
|
|
|
87
90
|
node.close();
|
|
88
91
|
restoreFocus();
|
|
89
92
|
setClosing(false);
|
|
93
|
+
afterClose.current?.();
|
|
90
94
|
});
|
|
91
95
|
}, [open, placement, initialFocus, rememberFocus, restoreFocus]);
|
|
92
96
|
const outside = (event) => {
|
|
@@ -110,6 +110,14 @@
|
|
|
110
110
|
.field[data-disabled="true"] .inlineLabel > .labelRow {
|
|
111
111
|
opacity: 0.55;
|
|
112
112
|
}
|
|
113
|
+
@media (min-width: 701px) {
|
|
114
|
+
.field[data-layout="inline"]:has(textarea) {
|
|
115
|
+
align-items: start;
|
|
116
|
+
}
|
|
117
|
+
.field[data-layout="inline"]:has(textarea) > .inlineLabel {
|
|
118
|
+
padding-top: max(0px, calc((var(--control-height) - 1lh) / 2));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
113
121
|
@media (max-width: 700px) {
|
|
114
122
|
.field[data-layout="inline"] {
|
|
115
123
|
display: flex;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function IconButton({ label, loading, children, variant, size, ...props }:
|
|
1
|
+
import type { ComponentPropsWithRef } from "react";
|
|
2
|
+
export declare function IconButton({ label, loading, children, variant, size, ...props }: ComponentPropsWithRef<"button"> & {
|
|
3
3
|
label: string;
|
|
4
4
|
loading?: boolean;
|
|
5
5
|
variant?: "primary" | "secondary" | "ghost" | "danger";
|
package/components/index.d.ts
CHANGED
package/components/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Badge } from "./Badge.js";
|
|
2
|
+
import { ActionSheet } from "./ActionSheet.js";
|
|
2
3
|
import { Button } from "./Button.js";
|
|
3
4
|
import { Checkbox } from "./Checkbox.js";
|
|
4
5
|
import { ColorField } from "./ColorField.js";
|
|
@@ -117,6 +118,7 @@ import {
|
|
|
117
118
|
export {
|
|
118
119
|
Accordion,
|
|
119
120
|
AccountItem,
|
|
121
|
+
ActionSheet,
|
|
120
122
|
Alert,
|
|
121
123
|
AppShell,
|
|
122
124
|
AppearanceSettings,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robert-stackflow/oneui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "OneUI React components, application shell and portable visual themes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -14,6 +14,12 @@
|
|
|
14
14
|
},
|
|
15
15
|
"./styles/*": "./styles/*",
|
|
16
16
|
"./assets/*": "./assets/*",
|
|
17
|
+
"./ActionSheet": {
|
|
18
|
+
"types": "./components/ActionSheet.d.ts",
|
|
19
|
+
"import": "./components/ActionSheet.js",
|
|
20
|
+
"default": "./components/ActionSheet.js"
|
|
21
|
+
},
|
|
22
|
+
"./ActionSheet.module.css": "./components/ActionSheet.module.css",
|
|
17
23
|
"./Accessibility.module.css": "./components/Accessibility.module.css",
|
|
18
24
|
"./Accordion.module.css": "./components/Accordion.module.css",
|
|
19
25
|
"./Accordion": {
|