@robert-stackflow/oneui 0.4.0 → 0.4.1
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 +11 -0
- package/components/Dialog.d.ts +4 -2
- package/components/Dialog.js +7 -9
- package/components/Drawer.d.ts +2 -1
- package/components/Drawer.js +7 -10
- package/components/FormField.js +4 -4
- package/components/Pagination.d.ts +5 -1
- package/components/Pagination.js +117 -107
- package/components/Pagination.module.css +39 -0
- package/components/useModalFocus.d.ts +6 -0
- package/components/useModalFocus.js +35 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.1 — 2026-10-29
|
|
4
|
+
|
|
5
|
+
- Dialog、Drawer 统一处理普通关闭和条件卸载后的焦点恢复,兼容 StrictMode、嵌套与替换弹窗,不抢夺其他弹窗的焦点。
|
|
6
|
+
- 新增 `returnFocus` 引用,可为异步打开的弹窗明确指定关闭后返回的控件。
|
|
7
|
+
- 修复 FormField 在卸载失焦时访问已清空引用的运行错误,避免 StrictMode 模拟清理触发额外失焦。
|
|
8
|
+
- Pagination 新增 `compact`、`size="small"` 和 `className`;紧凑排列、尺寸及窄屏换行由组件管理,宿主不再依赖内部 DOM 覆盖样式。
|
|
9
|
+
- 增加独立构建包的双主题、深浅色、1280/390/320px 焦点和分页交互验证。
|
|
10
|
+
|
|
3
11
|
## 0.4.0 — 2026-10-29
|
|
4
12
|
|
|
5
13
|
- 新增 AccountItem、PasskeyItem、SessionItem,统一账户设备列表的图标、元数据、操作按钮和移动布局;业务与日期格式由宿主负责。
|
package/README.md
CHANGED
|
@@ -57,6 +57,17 @@ export function App() {
|
|
|
57
57
|
|
|
58
58
|
以上 API 从 0.2.0 起提供。
|
|
59
59
|
|
|
60
|
+
## 弹窗焦点与分页(0.4.1)
|
|
61
|
+
|
|
62
|
+
`Dialog` 和 `Drawer` 在普通关闭、条件卸载时都会恢复触发控件的焦点,支持 StrictMode 和嵌套弹窗。异步打开导致触发按钮在加载期间失焦时,可传入 `returnFocus={triggerRef}` 明确返回位置;已卸载、禁用或位于其他模态层之外的目标不会被聚焦。
|
|
63
|
+
|
|
64
|
+
`Pagination` 的 `total` 是总条数,`pageSize` 是每页条数。`compact` 移除外层留白并在窄屏重排页码、统计和跳转,`size="small"` 使用当前主题的小尺寸控件;正常和紧凑模式均支持长页码列表换行。宿主可通过 `className` 调整外层位置。
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
<Pagination compact size="small" page={page} pageSize={10}
|
|
68
|
+
total={records.total} onPageChange={setPage} />
|
|
69
|
+
```
|
|
70
|
+
|
|
60
71
|
## 层级选择、补全与标签
|
|
61
72
|
|
|
62
73
|
- `TreeSelect variant="category"` 在原有树选择交互上增加图标底块、子项数量与层级连线;默认 `variant="tree"` 保留简洁样式。两种样式均支持搜索、父子联动、多选、禁用、异步加载及键盘操作。`HierarchyOption.count` 可单独提供数量。
|
package/components/Dialog.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type ReactNode } from "react";
|
|
2
|
-
export declare function Dialog({ open: requestedOpen, onClose, title, children, footer, wide, size, role, descriptionId, busy, variant, }: {
|
|
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, returnFocus, }: {
|
|
3
3
|
open: boolean;
|
|
4
4
|
onClose(): void;
|
|
5
5
|
title: string;
|
|
@@ -11,4 +11,6 @@ export declare function Dialog({ open: requestedOpen, onClose, title, children,
|
|
|
11
11
|
descriptionId?: string;
|
|
12
12
|
busy?: boolean;
|
|
13
13
|
variant?: "default" | "message" | "confirm" | "form";
|
|
14
|
+
/** Trigger to focus after closing, including surfaces opened asynchronously. */
|
|
15
|
+
returnFocus?: RefObject<HTMLElement | null>;
|
|
14
16
|
}): import("react").ReactPortal;
|
package/components/Dialog.js
CHANGED
|
@@ -13,6 +13,7 @@ import { surfaceMotion, cancelMotion } from "./motion.js";
|
|
|
13
13
|
import s from "./Dialog.module.css";
|
|
14
14
|
import { FieldContext } from "./field.js";
|
|
15
15
|
import { useModalScrollLock } from "./useModalScrollLock.js";
|
|
16
|
+
import { useModalFocus } from "./useModalFocus.js";
|
|
16
17
|
import {
|
|
17
18
|
SurfacePortalContext,
|
|
18
19
|
useSurfaceHost,
|
|
@@ -29,12 +30,13 @@ function Dialog({
|
|
|
29
30
|
role = "dialog",
|
|
30
31
|
descriptionId,
|
|
31
32
|
busy = false,
|
|
32
|
-
variant = "default"
|
|
33
|
+
variant = "default",
|
|
34
|
+
returnFocus
|
|
33
35
|
}) {
|
|
34
36
|
const owner = useSurfacePortal(), open = requestedOpen && owner?.active !== false;
|
|
35
37
|
const { ref, host, setRef } = useSurfaceHost();
|
|
36
38
|
const titleId = useId();
|
|
37
|
-
const
|
|
39
|
+
const { rememberFocus, restoreFocus } = useModalFocus(ref, returnFocus);
|
|
38
40
|
const [closing, setClosing] = useState(false);
|
|
39
41
|
useModalScrollLock(open || closing);
|
|
40
42
|
const opened = useRef(open);
|
|
@@ -55,7 +57,7 @@ function Dialog({
|
|
|
55
57
|
element.inert = false;
|
|
56
58
|
setClosing(false);
|
|
57
59
|
if (!element.open) {
|
|
58
|
-
|
|
60
|
+
rememberFocus();
|
|
59
61
|
element.showModal();
|
|
60
62
|
element.querySelector(
|
|
61
63
|
"[data-dialog-initial-focus]:not(:disabled)"
|
|
@@ -74,14 +76,10 @@ function Dialog({
|
|
|
74
76
|
void surfaceMotion(element, "exit", "0 4px").then((done) => {
|
|
75
77
|
if (!done || opened.current) return;
|
|
76
78
|
element.close();
|
|
77
|
-
|
|
78
|
-
...document.querySelectorAll("dialog:modal")
|
|
79
|
-
].at(-1);
|
|
80
|
-
if (previousFocus.current?.isConnected && (!modal || modal.contains(previousFocus.current)))
|
|
81
|
-
previousFocus.current.focus({ preventScroll: true });
|
|
79
|
+
restoreFocus();
|
|
82
80
|
setClosing(false);
|
|
83
81
|
});
|
|
84
|
-
}, [open]);
|
|
82
|
+
}, [open, rememberFocus, restoreFocus]);
|
|
85
83
|
const backdropDown = useRef(false);
|
|
86
84
|
const outside = (event) => {
|
|
87
85
|
const rect = event.currentTarget.getBoundingClientRect();
|
package/components/Drawer.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export type DrawerProps = {
|
|
|
13
13
|
closeOnEscape?: boolean;
|
|
14
14
|
closeOnBackdrop?: boolean;
|
|
15
15
|
initialFocus?: RefObject<HTMLElement | null>;
|
|
16
|
+
returnFocus?: RefObject<HTMLElement | null>;
|
|
16
17
|
className?: string;
|
|
17
18
|
};
|
|
18
|
-
export declare function Drawer({ open: requestedOpen, onClose, title, description, children, footer, placement, size, closable, closeOnEscape, closeOnBackdrop, initialFocus, className, }: DrawerProps): import("react").ReactPortal;
|
|
19
|
+
export declare function Drawer({ open: requestedOpen, onClose, title, description, children, footer, placement, size, closable, closeOnEscape, closeOnBackdrop, initialFocus, returnFocus, className, }: DrawerProps): import("react").ReactPortal;
|
package/components/Drawer.js
CHANGED
|
@@ -11,6 +11,7 @@ import { X } from "lucide-react";
|
|
|
11
11
|
import { IconButton } from "./IconButton.js";
|
|
12
12
|
import { FieldContext } from "./field.js";
|
|
13
13
|
import { useModalScrollLock } from "./useModalScrollLock.js";
|
|
14
|
+
import { useModalFocus } from "./useModalFocus.js";
|
|
14
15
|
import { cancelMotion, surfaceMotion } from "./motion.js";
|
|
15
16
|
import s from "./Drawer.module.css";
|
|
16
17
|
import {
|
|
@@ -37,11 +38,13 @@ function Drawer({
|
|
|
37
38
|
closeOnEscape = true,
|
|
38
39
|
closeOnBackdrop = true,
|
|
39
40
|
initialFocus,
|
|
41
|
+
returnFocus,
|
|
40
42
|
className = ""
|
|
41
43
|
}) {
|
|
42
44
|
const owner = useSurfacePortal(), open = requestedOpen && owner?.active !== false;
|
|
43
45
|
const { ref, host, setRef } = useSurfaceHost();
|
|
44
|
-
const
|
|
46
|
+
const { rememberFocus, restoreFocus } = useModalFocus(ref, returnFocus);
|
|
47
|
+
const opened = useRef(open), backdropDown = useRef(false), titleId = useId(), descriptionId = useId();
|
|
45
48
|
const [closing, setClosing] = useState(false);
|
|
46
49
|
useModalScrollLock(open || closing);
|
|
47
50
|
opened.current = open;
|
|
@@ -52,7 +55,6 @@ function Drawer({
|
|
|
52
55
|
const node = ref.current;
|
|
53
56
|
return () => {
|
|
54
57
|
cancelMotion(node);
|
|
55
|
-
if (node.open) node.close();
|
|
56
58
|
};
|
|
57
59
|
}, []);
|
|
58
60
|
useLayoutEffect(() => {
|
|
@@ -63,7 +65,7 @@ function Drawer({
|
|
|
63
65
|
const justOpened = !node.open;
|
|
64
66
|
const body = node.querySelector("[data-drawer-body]");
|
|
65
67
|
if (justOpened) {
|
|
66
|
-
|
|
68
|
+
rememberFocus();
|
|
67
69
|
node.showModal();
|
|
68
70
|
if (body) body.scrollTop = 0;
|
|
69
71
|
}
|
|
@@ -83,15 +85,10 @@ function Drawer({
|
|
|
83
85
|
void surfaceMotion(node, "exit", offsets[placement]).then((done) => {
|
|
84
86
|
if (!done || opened.current) return;
|
|
85
87
|
node.close();
|
|
86
|
-
|
|
87
|
-
const modal = [
|
|
88
|
-
...document.querySelectorAll("dialog:modal")
|
|
89
|
-
].at(-1);
|
|
90
|
-
if (focus?.isConnected && (!modal || modal.contains(focus)))
|
|
91
|
-
focus.focus({ preventScroll: true });
|
|
88
|
+
restoreFocus();
|
|
92
89
|
setClosing(false);
|
|
93
90
|
});
|
|
94
|
-
}, [open, placement, initialFocus]);
|
|
91
|
+
}, [open, placement, initialFocus, rememberFocus, restoreFocus]);
|
|
95
92
|
const outside = (event) => {
|
|
96
93
|
const rect = event.currentTarget.getBoundingClientRect();
|
|
97
94
|
return event.target === event.currentTarget && (event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom);
|
package/components/FormField.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useUIConfig } from "./UIProvider.js";
|
|
3
3
|
import { FieldMessages } from "./FieldMessages.js";
|
|
4
4
|
import { Spinner } from "./Spinner.js";
|
|
5
|
-
import { useContext
|
|
5
|
+
import { useContext } from "react";
|
|
6
6
|
import { FieldContext, useFieldControl } from "./field.js";
|
|
7
7
|
import { FieldLabel } from "./FieldLabel.js";
|
|
8
8
|
import s from "./FormField.module.css";
|
|
@@ -18,7 +18,7 @@ function FormField({
|
|
|
18
18
|
...options
|
|
19
19
|
}) {
|
|
20
20
|
const config = useUIConfig(), inherited = useContext(FormLayoutContext);
|
|
21
|
-
const field = useFieldControl(options)
|
|
21
|
+
const field = useFieldControl(options);
|
|
22
22
|
const showLabel = !!field.label || pending, layout = showLabel ? suppliedLayout ?? inherited.layout ?? "stacked" : "stacked", labelWidth = suppliedLabelWidth ?? inherited.labelWidth;
|
|
23
23
|
const label = showLabel ? /* @__PURE__ */ jsxs("div", { className: s.labelRow, children: [
|
|
24
24
|
field.label && /* @__PURE__ */ jsx(
|
|
@@ -37,7 +37,6 @@ function FormField({
|
|
|
37
37
|
return /* @__PURE__ */ jsx(FieldContext, { value: field, children: /* @__PURE__ */ jsx(
|
|
38
38
|
"div",
|
|
39
39
|
{
|
|
40
|
-
ref: root,
|
|
41
40
|
className: s.field,
|
|
42
41
|
"data-invalid": !!field.error,
|
|
43
42
|
"data-disabled": field.disabled || void 0,
|
|
@@ -46,7 +45,8 @@ function FormField({
|
|
|
46
45
|
"--field-label-width": typeof labelWidth === "number" ? labelWidth + "px" : labelWidth
|
|
47
46
|
},
|
|
48
47
|
onBlur: (event) => {
|
|
49
|
-
const next = event.relatedTarget, node =
|
|
48
|
+
const next = event.relatedTarget, node = event.currentTarget;
|
|
49
|
+
if (!node.isConnected) return;
|
|
50
50
|
if (next && node.contains(next)) return;
|
|
51
51
|
const portals = [...node.querySelectorAll("[aria-controls]")].map(
|
|
52
52
|
(control) => document.getElementById(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
-
export declare function Pagination({ page, pageSize, total, onPageChange, onPageSizeChange, pageSizes, summary, resetPageOnSizeChange, }: {
|
|
2
|
+
export declare function Pagination({ page, pageSize, total, onPageChange, onPageSizeChange, pageSizes, summary, resetPageOnSizeChange, compact, size: controlSize, className, }: {
|
|
3
3
|
page: number;
|
|
4
4
|
pageSize: number;
|
|
5
5
|
total: number;
|
|
@@ -8,4 +8,8 @@ export declare function Pagination({ page, pageSize, total, onPageChange, onPage
|
|
|
8
8
|
pageSizes?: number[];
|
|
9
9
|
summary?: ReactNode;
|
|
10
10
|
resetPageOnSizeChange?: boolean;
|
|
11
|
+
/** Removes outer spacing and groups controls for dialogs and dense toolbars. */
|
|
12
|
+
compact?: boolean;
|
|
13
|
+
size?: "default" | "small";
|
|
14
|
+
className?: string;
|
|
11
15
|
}): import("react").JSX.Element;
|
package/components/Pagination.js
CHANGED
|
@@ -18,7 +18,10 @@ function Pagination({
|
|
|
18
18
|
onPageSizeChange,
|
|
19
19
|
pageSizes = [5, 10, 20, 50],
|
|
20
20
|
summary,
|
|
21
|
-
resetPageOnSizeChange = true
|
|
21
|
+
resetPageOnSizeChange = true,
|
|
22
|
+
compact = false,
|
|
23
|
+
size: controlSize = "default",
|
|
24
|
+
className = ""
|
|
22
25
|
}) {
|
|
23
26
|
const size = Math.max(1, pageSize), pages = Math.max(1, Math.ceil(total / size)), current = Math.min(pages, Math.max(1, page)), id = useId(), [draft, setDraft] = useState(String(current));
|
|
24
27
|
useEffect(() => setDraft(String(current)), [current]);
|
|
@@ -41,119 +44,126 @@ function Pagination({
|
|
|
41
44
|
pages
|
|
42
45
|
])
|
|
43
46
|
].sort((a, b) => a - b);
|
|
44
|
-
return /* @__PURE__ */ jsxs(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
" "
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (resetPageOnSizeChange) onPageChange(1);
|
|
62
|
-
},
|
|
63
|
-
options: [.../* @__PURE__ */ new Set([...pageSizes, size])].sort((a, b) => a - b).map((n) => ({ value: String(n), label: n + " / \u9875" }))
|
|
64
|
-
}
|
|
65
|
-
),
|
|
66
|
-
/* @__PURE__ */ jsxs("div", { className: s.pages, children: [
|
|
67
|
-
/* @__PURE__ */ jsx(
|
|
68
|
-
Button,
|
|
69
|
-
{
|
|
70
|
-
className: s.arrow,
|
|
71
|
-
"aria-label": "\u7B2C\u4E00\u9875",
|
|
72
|
-
disabled: current === 1,
|
|
73
|
-
onClick: () => onPageChange(1),
|
|
74
|
-
children: /* @__PURE__ */ jsx(ChevronsLeft, {})
|
|
75
|
-
}
|
|
76
|
-
),
|
|
77
|
-
/* @__PURE__ */ jsx(
|
|
78
|
-
Button,
|
|
79
|
-
{
|
|
80
|
-
className: s.arrow,
|
|
81
|
-
"aria-label": "\u4E0A\u4E00\u9875",
|
|
82
|
-
disabled: current === 1,
|
|
83
|
-
onClick: () => onPageChange(current - 1),
|
|
84
|
-
children: /* @__PURE__ */ jsx(ChevronLeft, {})
|
|
85
|
-
}
|
|
86
|
-
),
|
|
87
|
-
visible.map((n, i) => /* @__PURE__ */ jsxs("span", { className: s.number, children: [
|
|
88
|
-
i > 0 && n - visible[i - 1] > 1 && /* @__PURE__ */ jsx("span", { className: s.ellipsis, children: "\u2026" }),
|
|
89
|
-
/* @__PURE__ */ jsx(
|
|
90
|
-
Button,
|
|
47
|
+
return /* @__PURE__ */ jsxs(
|
|
48
|
+
"nav",
|
|
49
|
+
{
|
|
50
|
+
className: `${s.pagination} ${compact ? s.compact : ""} ${controlSize === "small" ? s.small : ""} ${className}`,
|
|
51
|
+
"aria-label": "\u5206\u9875",
|
|
52
|
+
children: [
|
|
53
|
+
/* @__PURE__ */ jsxs("span", { className: s.summary, children: [
|
|
54
|
+
total ? (current - 1) * size + 1 + "\u2013" + Math.min(current * size, total) : 0,
|
|
55
|
+
" ",
|
|
56
|
+
"/ ",
|
|
57
|
+
total,
|
|
58
|
+
" \u9879",
|
|
59
|
+
summary
|
|
60
|
+
] }),
|
|
61
|
+
/* @__PURE__ */ jsxs("div", { className: s.controls, children: [
|
|
62
|
+
onPageSizeChange && /* @__PURE__ */ jsx(
|
|
63
|
+
Select,
|
|
91
64
|
{
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
65
|
+
label: "\u6BCF\u9875\u6761\u6570",
|
|
66
|
+
value: String(size),
|
|
67
|
+
onChange: (v) => {
|
|
68
|
+
onPageSizeChange(Number(v));
|
|
69
|
+
if (resetPageOnSizeChange) onPageChange(1);
|
|
70
|
+
},
|
|
71
|
+
options: [.../* @__PURE__ */ new Set([...pageSizes, size])].sort((a, b) => a - b).map((n) => ({ value: String(n), label: n + " / \u9875" }))
|
|
98
72
|
}
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
/* @__PURE__ */ jsx(
|
|
102
|
-
Button,
|
|
103
|
-
{
|
|
104
|
-
className: s.arrow,
|
|
105
|
-
"aria-label": "\u4E0B\u4E00\u9875",
|
|
106
|
-
disabled: current === pages,
|
|
107
|
-
onClick: () => onPageChange(current + 1),
|
|
108
|
-
children: /* @__PURE__ */ jsx(ChevronRight, {})
|
|
109
|
-
}
|
|
110
|
-
),
|
|
111
|
-
/* @__PURE__ */ jsx(
|
|
112
|
-
Button,
|
|
113
|
-
{
|
|
114
|
-
className: s.arrow,
|
|
115
|
-
"aria-label": "\u6700\u540E\u4E00\u9875",
|
|
116
|
-
disabled: current === pages,
|
|
117
|
-
onClick: () => onPageChange(pages),
|
|
118
|
-
children: /* @__PURE__ */ jsx(ChevronsRight, {})
|
|
119
|
-
}
|
|
120
|
-
)
|
|
121
|
-
] }),
|
|
122
|
-
/* @__PURE__ */ jsxs(
|
|
123
|
-
"form",
|
|
124
|
-
{
|
|
125
|
-
className: s.jump,
|
|
126
|
-
onSubmit: (e) => {
|
|
127
|
-
e.preventDefault();
|
|
128
|
-
jump();
|
|
129
|
-
},
|
|
130
|
-
children: [
|
|
131
|
-
/* @__PURE__ */ jsx("label", { htmlFor: id, children: "\u8DF3\u81F3" }),
|
|
73
|
+
),
|
|
74
|
+
/* @__PURE__ */ jsxs("div", { className: s.pages, children: [
|
|
132
75
|
/* @__PURE__ */ jsx(
|
|
133
|
-
|
|
76
|
+
Button,
|
|
134
77
|
{
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
78
|
+
className: s.arrow,
|
|
79
|
+
"aria-label": "\u7B2C\u4E00\u9875",
|
|
80
|
+
disabled: current === 1,
|
|
81
|
+
onClick: () => onPageChange(1),
|
|
82
|
+
children: /* @__PURE__ */ jsx(ChevronsLeft, {})
|
|
83
|
+
}
|
|
84
|
+
),
|
|
85
|
+
/* @__PURE__ */ jsx(
|
|
86
|
+
Button,
|
|
87
|
+
{
|
|
88
|
+
className: s.arrow,
|
|
89
|
+
"aria-label": "\u4E0A\u4E00\u9875",
|
|
90
|
+
disabled: current === 1,
|
|
91
|
+
onClick: () => onPageChange(current - 1),
|
|
92
|
+
children: /* @__PURE__ */ jsx(ChevronLeft, {})
|
|
93
|
+
}
|
|
94
|
+
),
|
|
95
|
+
visible.map((n, i) => /* @__PURE__ */ jsxs("span", { className: s.number, children: [
|
|
96
|
+
i > 0 && n - visible[i - 1] > 1 && /* @__PURE__ */ jsx("span", { className: s.ellipsis, children: "\u2026" }),
|
|
97
|
+
/* @__PURE__ */ jsx(
|
|
98
|
+
Button,
|
|
99
|
+
{
|
|
100
|
+
className: s.page,
|
|
101
|
+
"aria-label": "\u7B2C " + n + " \u9875",
|
|
102
|
+
"aria-current": n === current ? "page" : void 0,
|
|
103
|
+
variant: n === current ? "primary" : "ghost",
|
|
104
|
+
onClick: () => onPageChange(n),
|
|
105
|
+
children: n
|
|
148
106
|
}
|
|
107
|
+
)
|
|
108
|
+
] }, n)),
|
|
109
|
+
/* @__PURE__ */ jsx(
|
|
110
|
+
Button,
|
|
111
|
+
{
|
|
112
|
+
className: s.arrow,
|
|
113
|
+
"aria-label": "\u4E0B\u4E00\u9875",
|
|
114
|
+
disabled: current === pages,
|
|
115
|
+
onClick: () => onPageChange(current + 1),
|
|
116
|
+
children: /* @__PURE__ */ jsx(ChevronRight, {})
|
|
149
117
|
}
|
|
150
118
|
),
|
|
151
|
-
/* @__PURE__ */ jsx(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
119
|
+
/* @__PURE__ */ jsx(
|
|
120
|
+
Button,
|
|
121
|
+
{
|
|
122
|
+
className: s.arrow,
|
|
123
|
+
"aria-label": "\u6700\u540E\u4E00\u9875",
|
|
124
|
+
disabled: current === pages,
|
|
125
|
+
onClick: () => onPageChange(pages),
|
|
126
|
+
children: /* @__PURE__ */ jsx(ChevronsRight, {})
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
] }),
|
|
130
|
+
/* @__PURE__ */ jsxs(
|
|
131
|
+
"form",
|
|
132
|
+
{
|
|
133
|
+
className: s.jump,
|
|
134
|
+
onSubmit: (e) => {
|
|
135
|
+
e.preventDefault();
|
|
136
|
+
jump();
|
|
137
|
+
},
|
|
138
|
+
children: [
|
|
139
|
+
/* @__PURE__ */ jsx("label", { htmlFor: id, children: "\u8DF3\u81F3" }),
|
|
140
|
+
/* @__PURE__ */ jsx(
|
|
141
|
+
"input",
|
|
142
|
+
{
|
|
143
|
+
id,
|
|
144
|
+
className: control.surface,
|
|
145
|
+
"aria-label": "\u8DF3\u8F6C\u9875\u7801",
|
|
146
|
+
"aria-description": "\u8F93\u5165\u9875\u7801\u540E\u6309\u56DE\u8F66\u786E\u8BA4",
|
|
147
|
+
inputMode: "numeric",
|
|
148
|
+
value: draft,
|
|
149
|
+
onChange: (e) => setDraft(e.target.value),
|
|
150
|
+
onBlur: jump,
|
|
151
|
+
onKeyDown: (e) => {
|
|
152
|
+
if (e.key === "Escape") {
|
|
153
|
+
e.preventDefault();
|
|
154
|
+
setDraft(String(current));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
),
|
|
159
|
+
/* @__PURE__ */ jsx("span", { children: "\u9875" })
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
] })
|
|
164
|
+
]
|
|
165
|
+
}
|
|
166
|
+
);
|
|
157
167
|
}
|
|
158
168
|
export {
|
|
159
169
|
Pagination
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
.pagination {
|
|
2
|
+
min-width: 0;
|
|
3
|
+
max-width: 100%;
|
|
2
4
|
display: flex;
|
|
3
5
|
align-items: center;
|
|
4
6
|
justify-content: space-between;
|
|
@@ -12,6 +14,8 @@
|
|
|
12
14
|
font-size: 12px;
|
|
13
15
|
}
|
|
14
16
|
.controls {
|
|
17
|
+
min-width: 0;
|
|
18
|
+
max-width: 100%;
|
|
15
19
|
display: flex;
|
|
16
20
|
align-items: center;
|
|
17
21
|
gap: 16px;
|
|
@@ -27,6 +31,16 @@
|
|
|
27
31
|
gap: 4px;
|
|
28
32
|
align-items: center;
|
|
29
33
|
}
|
|
34
|
+
.pages {
|
|
35
|
+
flex-wrap: wrap;
|
|
36
|
+
}
|
|
37
|
+
.compact {
|
|
38
|
+
width: 100%;
|
|
39
|
+
padding: 0;
|
|
40
|
+
}
|
|
41
|
+
.small {
|
|
42
|
+
--control-height: var(--control-small);
|
|
43
|
+
}
|
|
30
44
|
.pages .arrow,
|
|
31
45
|
.pages .page {
|
|
32
46
|
height: var(--control-height);
|
|
@@ -67,4 +81,29 @@
|
|
|
67
81
|
.pages {
|
|
68
82
|
gap: 2px;
|
|
69
83
|
}
|
|
84
|
+
.compact {
|
|
85
|
+
display: grid;
|
|
86
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
87
|
+
gap: 8px;
|
|
88
|
+
}
|
|
89
|
+
.compact .controls {
|
|
90
|
+
display: contents;
|
|
91
|
+
}
|
|
92
|
+
.compact .pages {
|
|
93
|
+
grid-column: 1 / -1;
|
|
94
|
+
grid-row: 1;
|
|
95
|
+
justify-content: center;
|
|
96
|
+
}
|
|
97
|
+
.compact .summary {
|
|
98
|
+
grid-column: 1;
|
|
99
|
+
grid-row: 2;
|
|
100
|
+
}
|
|
101
|
+
.compact .jump {
|
|
102
|
+
grid-column: 2;
|
|
103
|
+
grid-row: 2;
|
|
104
|
+
}
|
|
105
|
+
.compact .controls > [role="combobox"] {
|
|
106
|
+
grid-column: 1 / -1;
|
|
107
|
+
grid-row: 3;
|
|
108
|
+
}
|
|
70
109
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
/** Shared lifecycle for animated closure and conditionally mounted surfaces. */
|
|
3
|
+
export declare function useModalFocus(ref: RefObject<HTMLDialogElement | null>, returnFocus?: RefObject<HTMLElement | null>): {
|
|
4
|
+
rememberFocus: () => void;
|
|
5
|
+
restoreFocus: () => void;
|
|
6
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
+
function useModalFocus(ref, returnFocus) {
|
|
3
|
+
const previous = useRef(null);
|
|
4
|
+
const requested = useRef(returnFocus);
|
|
5
|
+
const mounted = useRef(false);
|
|
6
|
+
requested.current = returnFocus;
|
|
7
|
+
const rememberFocus = useCallback(() => {
|
|
8
|
+
const active = document.activeElement;
|
|
9
|
+
if (active instanceof HTMLElement && active !== document.body && !ref.current?.contains(active))
|
|
10
|
+
previous.current = active;
|
|
11
|
+
}, [ref]);
|
|
12
|
+
const restoreFocus = useCallback(() => {
|
|
13
|
+
const target = requested.current?.current || previous.current;
|
|
14
|
+
const modal = [...document.querySelectorAll("dialog:modal")].at(-1);
|
|
15
|
+
if (target?.isConnected && !target.matches(":disabled") && !target.closest("[inert]") && (!modal || modal.contains(target)))
|
|
16
|
+
target.focus({ preventScroll: true });
|
|
17
|
+
}, []);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
mounted.current = true;
|
|
20
|
+
const node = ref.current;
|
|
21
|
+
return () => {
|
|
22
|
+
mounted.current = false;
|
|
23
|
+
if (!node?.open) return;
|
|
24
|
+
requestAnimationFrame(() => {
|
|
25
|
+
if (mounted.current) return;
|
|
26
|
+
if (node.open) node.close();
|
|
27
|
+
restoreFocus();
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
}, [ref, restoreFocus]);
|
|
31
|
+
return { rememberFocus, restoreFocus };
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
useModalFocus
|
|
35
|
+
};
|