@robert-stackflow/oneui 0.4.1 → 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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0 — 2026-10-29
4
+
5
+ - 新增 ActionSheet,复用 IconButton、Drawer 和 MenuItem;桌面使用紧凑底部面板,手机适配底部安全区域,支持禁用和危险操作。
6
+ - Drawer 新增 `onAfterClose`,在关闭动画与焦点恢复完成后执行后续操作,避免操作面板与新弹窗重叠。
7
+ - 横向 FormField 包含多行输入时,标签靠上对齐;单行控件和手机纵向布局保持原有排列。
8
+
9
+ ## 0.4.2 — 2026-10-29
10
+
11
+ - 图标、Emoji 和符号目录改用可被构建工具识别的异步 JSON 导入,修复 npm 包在 Vite 开发预打包后资源相对路径失效的问题;生产构建继续按需加载。
12
+ - Card 新增 `description` 与无正文模式,标题和正文使用一致的横向间距,避免只含概览和操作时产生空白正文。
13
+ - 独立 tarball 消费测试增加开发模式预打包下的三套完整目录加载验证。
14
+
3
15
  ## 0.4.1 — 2026-10-29
4
16
 
5
17
  - Dialog、Drawer 统一处理普通关闭和条件卸载后的焦点恢复,兼容 StrictMode、嵌套与替换弹窗,不抢夺其他弹窗的焦点。
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
@@ -57,6 +70,10 @@ export function App() {
57
70
 
58
71
  以上 API 从 0.2.0 起提供。
59
72
 
73
+ ## 概览卡片与内置目录(0.4.2)
74
+
75
+ `Card` 可通过 `title`、`description`、`action` 组合概览与操作;省略 `children` 时不会渲染空白正文。图标选择器不传 `options` 即使用库内置的完整目录;`valuePrefix="lucide:"` 可保留宿主保存值的前缀。图标、Emoji 和符号资源均由组件库按需加载,支持 Vite 的开发预打包与生产构建,宿主无需维护另一套选项或资源加载器。
76
+
60
77
  ## 弹窗焦点与分页(0.4.1)
61
78
 
62
79
  `Dialog` 和 `Drawer` 在普通关闭、条件卸载时都会恢复触发控件的焦点,支持 StrictMode 和嵌套弹窗。异步打开导致触发按钮在加载期间失焦时,可传入 `returnFocus={triggerRef}` 明确返回位置;已卸载、禁用或位于其他模态层之外的目标不会被聚焦。
@@ -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
+ }
@@ -1,8 +1,9 @@
1
1
  import type { ReactNode } from "react";
2
- export declare function Card({ title, action, children, className, onClick, }: {
2
+ export declare function Card({ title, description, action, children, className, onClick, }: {
3
3
  title?: string;
4
+ description?: ReactNode;
4
5
  action?: ReactNode;
5
- children: ReactNode;
6
+ children?: ReactNode;
6
7
  className?: string;
7
8
  onClick?(): void;
8
9
  }): import("react").JSX.Element;
@@ -2,27 +2,33 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import s from "./Card.module.css";
3
3
  function Card({
4
4
  title,
5
+ description,
5
6
  action,
6
7
  children,
7
8
  className = "",
8
9
  onClick
9
10
  }) {
11
+ const hasBody = children != null && children !== false;
12
+ const classes = `${s.card} ${!hasBody ? s.headerOnly : ""} ${className}`;
10
13
  const content = /* @__PURE__ */ jsxs(Fragment, { children: [
11
- (title || action) && /* @__PURE__ */ jsxs("header", { className: s.header, children: [
12
- /* @__PURE__ */ jsx("h2", { children: title }),
14
+ (title || description || action) && /* @__PURE__ */ jsxs("header", { className: s.header, children: [
15
+ /* @__PURE__ */ jsxs("div", { className: s.heading, children: [
16
+ title && /* @__PURE__ */ jsx("h2", { children: title }),
17
+ description && /* @__PURE__ */ jsx("div", { className: s.description, children: description })
18
+ ] }),
13
19
  action
14
20
  ] }),
15
- /* @__PURE__ */ jsx("div", { className: s.body, "data-card-body": true, children })
21
+ hasBody && /* @__PURE__ */ jsx("div", { className: s.body, "data-card-body": true, children })
16
22
  ] });
17
23
  return onClick ? /* @__PURE__ */ jsx(
18
24
  "button",
19
25
  {
20
26
  type: "button",
21
- className: `${s.card} ${s.interactive} ${className}`,
27
+ className: `${classes} ${s.interactive}`,
22
28
  onClick,
23
29
  children: content
24
30
  }
25
- ) : /* @__PURE__ */ jsx("section", { className: s.card + " " + className, children: content });
31
+ ) : /* @__PURE__ */ jsx("section", { className: classes, children: content });
26
32
  }
27
33
  export {
28
34
  Card
@@ -29,7 +29,24 @@
29
29
  align-items: center;
30
30
  justify-content: space-between;
31
31
  gap: 12px;
32
- padding: 20px 24px 0;
32
+ flex-wrap: wrap;
33
+ padding: 20px var(--card-space) 0;
34
+ }
35
+ .heading {
36
+ flex: 1;
37
+ min-width: 0;
38
+ }
39
+ .heading h2 {
40
+ color: var(--fg);
41
+ }
42
+ .description {
43
+ margin-top: 6px;
44
+ color: var(--muted);
45
+ font-size: 13px;
46
+ line-height: 1.65;
47
+ }
48
+ .headerOnly .header {
49
+ padding-bottom: var(--card-space);
33
50
  }
34
51
  .body {
35
52
  padding: var(--card-space);
@@ -44,4 +61,7 @@
44
61
  .body {
45
62
  padding: 18px;
46
63
  }
64
+ .headerOnly .header {
65
+ padding-bottom: 18px;
66
+ }
47
67
  }
@@ -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;
@@ -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 { ButtonHTMLAttributes } from "react";
2
- export declare function IconButton({ label, loading, children, variant, size, ...props }: ButtonHTMLAttributes<HTMLButtonElement> & {
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";
@@ -1,14 +1,9 @@
1
1
  import { useEffect, useState } from "react";
2
- const emojiUrl = new URL("../assets/emoji.json", import.meta.url).href;
3
- const symbolsUrl = new URL("../assets/symbols.json", import.meta.url).href;
4
2
  import metadata from "../assets/character-metadata.json";
5
3
  const cache = {}, pending = {};
6
4
  const labels = metadata.groups, aliases = metadata.aliases;
7
5
  function load(kind) {
8
- return pending[kind] ||= fetch(kind === "emoji" ? emojiUrl : symbolsUrl).then((r) => {
9
- if (!r.ok) throw Error("\u5B57\u7B26\u52A0\u8F7D\u5931\u8D25");
10
- return r.json();
11
- }).then((rows) => {
6
+ return pending[kind] ||= (kind === "emoji" ? import("../assets/emoji.json") : import("../assets/symbols.json")).then(({ default: rows }) => rows).then((rows) => {
12
7
  const groups = /* @__PURE__ */ new Map();
13
8
  for (const [glyph, title, group, detail] of rows) {
14
9
  if (!glyph.trim()) continue;
@@ -1,12 +1,8 @@
1
1
  import { useEffect, useState } from "react";
2
- const url = new URL("../assets/icon-catalog.json", import.meta.url).href;
3
2
  let cache;
4
3
  let pending;
5
4
  function loadCatalog() {
6
- return pending ||= fetch(url).then((r) => {
7
- if (!r.ok) throw Error("\u56FE\u6807\u52A0\u8F7D\u5931\u8D25");
8
- return r.json();
9
- }).then((data) => cache = data).catch((e) => {
5
+ return pending ||= import("../assets/icon-catalog.json").then(({ default: data }) => cache = data).catch((e) => {
10
6
  pending = void 0;
11
7
  throw e;
12
8
  });
@@ -1,4 +1,5 @@
1
1
  export { Badge } from "./Badge";
2
+ export { ActionSheet, type ActionSheetItem } from "./ActionSheet";
2
3
  export { Button } from "./Button";
3
4
  export { Checkbox } from "./Checkbox";
4
5
  export { ColorField } from "./ColorField";
@@ -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.4.1",
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": {