@aura-react-comp/ui 0.0.0-stage → 0.1.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.
Files changed (123) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +67 -2
  3. package/esm/alert/index.d.ts +28 -0
  4. package/esm/alert/index.js +76 -0
  5. package/esm/alert/index.less +172 -0
  6. package/esm/avatar/index.d.ts +41 -0
  7. package/esm/avatar/index.js +117 -0
  8. package/esm/avatar/index.less +162 -0
  9. package/esm/badge/index.d.ts +29 -0
  10. package/esm/badge/index.js +84 -0
  11. package/esm/badge/index.less +215 -0
  12. package/esm/breadcrumb/index.d.ts +31 -0
  13. package/esm/breadcrumb/index.js +91 -0
  14. package/esm/breadcrumb/index.less +108 -0
  15. package/esm/button/index.d.ts +28 -0
  16. package/esm/button/index.js +59 -0
  17. package/esm/button/index.less +191 -0
  18. package/esm/card/index.d.ts +67 -0
  19. package/esm/card/index.js +156 -0
  20. package/esm/card/index.less +231 -0
  21. package/esm/checkbox/index.d.ts +35 -0
  22. package/esm/checkbox/index.js +118 -0
  23. package/esm/checkbox/index.less +141 -0
  24. package/esm/collapse/index.d.ts +45 -0
  25. package/esm/collapse/index.js +157 -0
  26. package/esm/collapse/index.less +144 -0
  27. package/esm/divider/index.d.ts +16 -0
  28. package/esm/divider/index.js +37 -0
  29. package/esm/divider/index.less +115 -0
  30. package/esm/dropdown/index.d.ts +38 -0
  31. package/esm/dropdown/index.js +108 -0
  32. package/esm/dropdown/index.less +245 -0
  33. package/esm/empty/index.d.ts +35 -0
  34. package/esm/empty/index.js +87 -0
  35. package/esm/empty/index.less +67 -0
  36. package/esm/flex/index.d.ts +24 -0
  37. package/esm/flex/index.js +64 -0
  38. package/esm/flex/index.less +9 -0
  39. package/esm/form/index.d.ts +121 -0
  40. package/esm/form/index.js +443 -0
  41. package/esm/form/index.less +257 -0
  42. package/esm/global.d.ts +6 -0
  43. package/esm/index.d.ts +78 -0
  44. package/esm/index.js +41 -0
  45. package/esm/input/index.d.ts +51 -0
  46. package/esm/input/index.js +217 -0
  47. package/esm/input/index.less +369 -0
  48. package/esm/layout/index.d.ts +46 -0
  49. package/esm/layout/index.js +135 -0
  50. package/esm/layout/index.less +132 -0
  51. package/esm/menu/index.d.ts +91 -0
  52. package/esm/menu/index.js +294 -0
  53. package/esm/menu/index.less +340 -0
  54. package/esm/message/index.d.ts +33 -0
  55. package/esm/message/index.js +199 -0
  56. package/esm/message/index.less +113 -0
  57. package/esm/notification/index.d.ts +33 -0
  58. package/esm/notification/index.js +229 -0
  59. package/esm/notification/index.less +175 -0
  60. package/esm/pagination/index.d.ts +38 -0
  61. package/esm/pagination/index.js +180 -0
  62. package/esm/pagination/index.less +238 -0
  63. package/esm/popconfirm/index.d.ts +37 -0
  64. package/esm/popconfirm/index.js +115 -0
  65. package/esm/popconfirm/index.less +229 -0
  66. package/esm/radio/index.d.ts +33 -0
  67. package/esm/radio/index.js +122 -0
  68. package/esm/radio/index.less +119 -0
  69. package/esm/rate/index.d.ts +30 -0
  70. package/esm/rate/index.js +143 -0
  71. package/esm/rate/index.less +87 -0
  72. package/esm/result/index.d.ts +19 -0
  73. package/esm/result/index.js +69 -0
  74. package/esm/result/index.less +103 -0
  75. package/esm/scrollbar/index.d.ts +18 -0
  76. package/esm/scrollbar/index.js +35 -0
  77. package/esm/scrollbar/index.less +67 -0
  78. package/esm/select/index.d.ts +63 -0
  79. package/esm/select/index.js +358 -0
  80. package/esm/select/index.less +427 -0
  81. package/esm/slider/index.d.ts +36 -0
  82. package/esm/slider/index.js +255 -0
  83. package/esm/slider/index.less +154 -0
  84. package/esm/space/index.d.ts +16 -0
  85. package/esm/space/index.js +34 -0
  86. package/esm/space/index.less +34 -0
  87. package/esm/spin/index.d.ts +44 -0
  88. package/esm/spin/index.js +152 -0
  89. package/esm/spin/index.less +170 -0
  90. package/esm/steps/index.d.ts +55 -0
  91. package/esm/steps/index.js +165 -0
  92. package/esm/steps/index.less +394 -0
  93. package/esm/switch/index.d.ts +30 -0
  94. package/esm/switch/index.js +56 -0
  95. package/esm/switch/index.less +135 -0
  96. package/esm/tabs/index.d.ts +45 -0
  97. package/esm/tabs/index.js +170 -0
  98. package/esm/tabs/index.less +226 -0
  99. package/esm/tag/index.d.ts +52 -0
  100. package/esm/tag/index.js +120 -0
  101. package/esm/tag/index.less +227 -0
  102. package/esm/textarea/index.d.ts +27 -0
  103. package/esm/textarea/index.js +84 -0
  104. package/esm/textarea/index.less +224 -0
  105. package/esm/theme/ThemeProvider.d.ts +15 -0
  106. package/esm/theme/ThemeProvider.js +32 -0
  107. package/esm/theme/index.d.ts +2 -0
  108. package/esm/theme/index.js +1 -0
  109. package/esm/theme/tokens.css +183 -0
  110. package/esm/theme/useTheme.d.ts +1 -0
  111. package/esm/theme/useTheme.js +1 -0
  112. package/esm/tooltip/index.d.ts +38 -0
  113. package/esm/tooltip/index.js +149 -0
  114. package/esm/tooltip/index.less +244 -0
  115. package/esm/typography/index.d.ts +26 -0
  116. package/esm/typography/index.js +92 -0
  117. package/esm/typography/index.less +106 -0
  118. package/esm/upload/index.d.ts +68 -0
  119. package/esm/upload/index.js +447 -0
  120. package/esm/upload/index.less +371 -0
  121. package/esm/upload/request.d.ts +26 -0
  122. package/esm/upload/request.js +38 -0
  123. package/package.json +56 -3
@@ -0,0 +1,229 @@
1
+ import React, { useEffect, useState, useRef } from 'react';
2
+ import { createRoot } from 'react-dom/client';
3
+ import { flushSync } from 'react-dom';
4
+ import { classNames, prefixCls } from '@aura-react-comp/shared';
5
+ import { CheckCircleFilled, CloseCircleFilled, WarningTriangleFilled, InfoCircleFilled, Close } from '@aura-react-comp/icons';
6
+ import "./index.less";
7
+
8
+ /* ===== 类型定义 ===== */
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ import { Fragment as _Fragment } from "react/jsx-runtime";
11
+ import { jsxs as _jsxs } from "react/jsx-runtime";
12
+ /* ===== 图标 ===== */
13
+ const variantIcons = {
14
+ default: null,
15
+ success: /*#__PURE__*/_jsx(CheckCircleFilled, {
16
+ size: 18
17
+ }),
18
+ error: /*#__PURE__*/_jsx(CloseCircleFilled, {
19
+ size: 18
20
+ }),
21
+ warning: /*#__PURE__*/_jsx(WarningTriangleFilled, {
22
+ size: 18
23
+ }),
24
+ info: /*#__PURE__*/_jsx(InfoCircleFilled, {
25
+ size: 18
26
+ })
27
+ };
28
+
29
+ /* ===== 容器管理 ===== */
30
+ const containers = new Map();
31
+ let notificationList = [];
32
+ let notificationKeyCounter = 0;
33
+ function getContainer(placement) {
34
+ const existing = containers.get(placement);
35
+ if (existing) return existing;
36
+ const el = document.createElement('div');
37
+ el.className = classNames(prefixCls('notification-container'), prefixCls(`notification-container-${placement}`));
38
+ document.body.appendChild(el);
39
+ const root = createRoot(el);
40
+ containers.set(placement, {
41
+ el,
42
+ root
43
+ });
44
+ return {
45
+ el,
46
+ root
47
+ };
48
+ }
49
+ function renderNotifications() {
50
+ // 按 placement 分组渲染
51
+ const groups = new Map();
52
+ notificationList.forEach(item => {
53
+ const placement = item._placement;
54
+ if (!groups.has(placement)) groups.set(placement, []);
55
+ groups.get(placement).push(item);
56
+ });
57
+
58
+ // 渲染有内容的容器
59
+ groups.forEach((items, placement) => {
60
+ const {
61
+ root
62
+ } = getContainer(placement);
63
+ flushSync(() => {
64
+ root.render( /*#__PURE__*/_jsx(NotificationList, {
65
+ items: items
66
+ }));
67
+ });
68
+ });
69
+
70
+ // 清理空容器
71
+ containers.forEach((container, placement) => {
72
+ const p = placement;
73
+ if (!groups.has(p)) {
74
+ setTimeout(() => {
75
+ if (!notificationList.some(n => n._placement === p)) {
76
+ container.root.unmount();
77
+ if (container.el.parentNode) {
78
+ document.body.removeChild(container.el);
79
+ }
80
+ containers.delete(p);
81
+ }
82
+ }, 400);
83
+ }
84
+ });
85
+ }
86
+ function addNotification(options) {
87
+ const variant = options._variantOverride ?? options.variant ?? 'default';
88
+ const placement = options.placement ?? 'topRight';
89
+ // 显式传 0 / 负数视为不自动关闭
90
+ const duration = options.duration !== undefined && options.duration > 0 ? options.duration : options.duration !== undefined ? null : 4500;
91
+ const existingIndex = options.key ? notificationList.findIndex(n => n.key === options.key) : -1;
92
+ const item = {
93
+ ...options,
94
+ key: options.key ?? `aura-notify-${++notificationKeyCounter}`,
95
+ variant,
96
+ _placement: placement,
97
+ duration,
98
+ version: existingIndex >= 0 ? notificationList[existingIndex].version + 1 : 0
99
+ };
100
+ if (existingIndex >= 0) {
101
+ // 同 key 原位更新:保持通知在列表中的位置,不重新播放入场动画
102
+ notificationList = notificationList.map((existing, i) => i === existingIndex ? item : existing);
103
+ } else {
104
+ notificationList = [...notificationList, item];
105
+ }
106
+ renderNotifications();
107
+ }
108
+ function removeNotification(key) {
109
+ const item = notificationList.find(n => n.key === key);
110
+ notificationList = notificationList.filter(n => n.key !== key);
111
+ renderNotifications();
112
+ if (item?.onClose) item.onClose();
113
+ }
114
+ function destroyNotifications(key) {
115
+ if (key === undefined) {
116
+ const keys = notificationList.map(n => n.key);
117
+ keys.forEach(removeNotification);
118
+ return;
119
+ }
120
+ removeNotification(key);
121
+ }
122
+
123
+ /* ===== NotificationList 组件 ===== */
124
+ const NotificationList = ({
125
+ items
126
+ }) => {
127
+ return /*#__PURE__*/_jsx(_Fragment, {
128
+ children: items.map(item => /*#__PURE__*/_jsx(NotificationItemComponent, {
129
+ item: item,
130
+ onClose: () => removeNotification(item.key)
131
+ }, item.key))
132
+ });
133
+ };
134
+
135
+ /* ===== 单条通知组件 ===== */
136
+ const NotificationItemComponent = ({
137
+ item,
138
+ onClose
139
+ }) => {
140
+ const [visible, setVisible] = useState(false);
141
+ const [leaving, setLeaving] = useState(false);
142
+ const timerRef = useRef(null);
143
+ useEffect(() => {
144
+ const raf = requestAnimationFrame(() => setVisible(true));
145
+ return () => cancelAnimationFrame(raf);
146
+ }, []);
147
+ useEffect(() => {
148
+ if (item.duration != null && item.duration > 0) {
149
+ timerRef.current = setTimeout(() => {
150
+ handleClose();
151
+ }, item.duration);
152
+ }
153
+ return () => {
154
+ if (timerRef.current) clearTimeout(timerRef.current);
155
+ };
156
+ // eslint-disable-next-line react-hooks/exhaustive-deps
157
+ }, [item.duration, item.version]);
158
+ const handleClose = () => {
159
+ setLeaving(true);
160
+ setTimeout(() => {
161
+ setVisible(false);
162
+ onClose();
163
+ }, 300);
164
+ };
165
+ const cls = classNames(prefixCls('notification'), prefixCls(`notification-${item.variant ?? 'default'}`), visible && !leaving && prefixCls('notification-visible'), leaving && prefixCls('notification-leaving'));
166
+ return /*#__PURE__*/_jsxs("div", {
167
+ className: cls,
168
+ children: [item.variant && item.variant !== 'default' && /*#__PURE__*/_jsx("span", {
169
+ className: prefixCls('notification-icon'),
170
+ children: variantIcons[item.variant]
171
+ }), /*#__PURE__*/_jsxs("div", {
172
+ className: prefixCls('notification-body'),
173
+ children: [item.title && /*#__PURE__*/_jsx("div", {
174
+ className: prefixCls('notification-title'),
175
+ children: item.title
176
+ }), /*#__PURE__*/_jsx("div", {
177
+ className: prefixCls('notification-content'),
178
+ children: item.content
179
+ }), item.actions && /*#__PURE__*/_jsx("div", {
180
+ className: prefixCls('notification-actions'),
181
+ children: item.actions
182
+ })]
183
+ }), /*#__PURE__*/_jsx("button", {
184
+ type: "button",
185
+ className: prefixCls('notification-close'),
186
+ onClick: handleClose,
187
+ "aria-label": "\u5173\u95ED",
188
+ children: /*#__PURE__*/_jsx(Close, {
189
+ size: 14
190
+ })
191
+ })]
192
+ });
193
+ };
194
+
195
+ /* ===== 重置内部状态(供测试使用) ===== */
196
+ export function _resetNotificationState() {
197
+ notificationList = [];
198
+ containers.forEach(container => {
199
+ container.root.unmount();
200
+ if (container.el.parentNode) {
201
+ container.el.parentNode.removeChild(container.el);
202
+ }
203
+ });
204
+ containers.clear();
205
+ }
206
+
207
+ /* ===== 对外导出 ===== */
208
+
209
+ export const notification = {
210
+ open: options => addNotification(options),
211
+ success: options => addNotification({
212
+ ...options,
213
+ _variantOverride: 'success'
214
+ }),
215
+ error: options => addNotification({
216
+ ...options,
217
+ _variantOverride: 'error'
218
+ }),
219
+ warning: options => addNotification({
220
+ ...options,
221
+ _variantOverride: 'warning'
222
+ }),
223
+ info: options => addNotification({
224
+ ...options,
225
+ _variantOverride: 'info'
226
+ }),
227
+ destroy: key => destroyNotifications(key)
228
+ };
229
+ export default notification;
@@ -0,0 +1,175 @@
1
+ /* ===== 容器定位 ===== */
2
+ .aura-notification-container {
3
+ position: fixed;
4
+ z-index: 9998;
5
+ display: flex;
6
+ flex-direction: column;
7
+ gap: var(--aura-spacing-3);
8
+ pointer-events: none;
9
+ max-height: 100vh;
10
+ overflow: hidden;
11
+
12
+ &-topLeft {
13
+ top: var(--aura-spacing-6);
14
+ left: var(--aura-spacing-6);
15
+ }
16
+
17
+ &-topRight {
18
+ top: var(--aura-spacing-6);
19
+ right: var(--aura-spacing-6);
20
+ }
21
+
22
+ &-bottomLeft {
23
+ bottom: var(--aura-spacing-6);
24
+ left: var(--aura-spacing-6);
25
+ flex-direction: column-reverse;
26
+ }
27
+
28
+ &-bottomRight {
29
+ bottom: var(--aura-spacing-6);
30
+ right: var(--aura-spacing-6);
31
+ flex-direction: column-reverse;
32
+ }
33
+ }
34
+
35
+ /* ===== 单条通知 ===== */
36
+ .aura-notification {
37
+ display: flex;
38
+ align-items: flex-start;
39
+ gap: var(--aura-spacing-3);
40
+ width: 360px;
41
+ padding: var(--aura-spacing-4);
42
+ background: var(--aura-bg);
43
+ border-radius: var(--aura-radius-lg);
44
+ box-shadow: var(--aura-shadow-lg);
45
+ border-left: 4px solid var(--aura-border);
46
+ pointer-events: auto;
47
+ opacity: 0;
48
+ transform: translateX(100%);
49
+ transition:
50
+ opacity var(--aura-duration-normal) var(--aura-easing),
51
+ transform var(--aura-duration-slow) var(--aura-easing);
52
+
53
+ /* ===== 图标 ===== */
54
+ &-icon {
55
+ display: flex;
56
+ align-items: center;
57
+ flex-shrink: 0;
58
+ margin-top: 1px;
59
+ }
60
+
61
+ /* ===== 主体内容 ===== */
62
+ &-body {
63
+ flex: 1;
64
+ min-width: 0;
65
+ }
66
+
67
+ /* ===== 标题 ===== */
68
+ &-title {
69
+ font-size: var(--aura-font-size-md);
70
+ font-weight: 600;
71
+ color: var(--aura-text);
72
+ line-height: 1.5;
73
+ margin-bottom: var(--aura-spacing-1);
74
+ }
75
+
76
+ /* ===== 内容 ===== */
77
+ &-content {
78
+ font-size: var(--aura-font-size-sm);
79
+ color: var(--aura-text-secondary);
80
+ line-height: 1.5;
81
+ }
82
+
83
+ /* ===== 底部操作区 ===== */
84
+ &-actions {
85
+ margin-top: var(--aura-spacing-3);
86
+ display: flex;
87
+ align-items: center;
88
+ gap: var(--aura-spacing-2);
89
+ }
90
+
91
+ /* ===== 关闭按钮 ===== */
92
+ &-close {
93
+ display: inline-flex;
94
+ align-items: center;
95
+ justify-content: center;
96
+ flex-shrink: 0;
97
+ padding: 0;
98
+ border: none;
99
+ background: transparent;
100
+ color: var(--aura-text-tertiary);
101
+ cursor: pointer;
102
+ border-radius: var(--aura-radius-sm);
103
+ transition: all var(--aura-duration-fast) var(--aura-easing);
104
+
105
+ &:hover {
106
+ color: var(--aura-text);
107
+ background: var(--aura-bg-tertiary);
108
+ transform: scale(1.1);
109
+ }
110
+
111
+ &:active {
112
+ transform: scale(0.95);
113
+ }
114
+ }
115
+
116
+ /* ===== 入场状态 ===== */
117
+ &-visible {
118
+ opacity: 1;
119
+ transform: translateX(0);
120
+ }
121
+
122
+ /* ===== 退场状态 ===== */
123
+ &-leaving {
124
+ opacity: 0;
125
+ transform: translateX(100%);
126
+ }
127
+
128
+ /* ===== Variant 颜色 ===== */
129
+ &-default {
130
+ border-left-color: var(--aura-border);
131
+ }
132
+
133
+ &-success {
134
+ border-left-color: var(--aura-success);
135
+
136
+ .aura-notification-icon {
137
+ color: var(--aura-success);
138
+ }
139
+ }
140
+
141
+ &-error {
142
+ border-left-color: var(--aura-error);
143
+
144
+ .aura-notification-icon {
145
+ color: var(--aura-error);
146
+ }
147
+ }
148
+
149
+ &-warning {
150
+ border-left-color: var(--aura-warning);
151
+
152
+ .aura-notification-icon {
153
+ color: var(--aura-warning);
154
+ }
155
+ }
156
+
157
+ &-info {
158
+ border-left-color: var(--aura-info);
159
+
160
+ .aura-notification-icon {
161
+ color: var(--aura-info);
162
+ }
163
+ }
164
+ }
165
+
166
+ /* ===== 暗色模式 ===== */
167
+ [data-theme='dark'] {
168
+ .aura-notification {
169
+ background: var(--aura-bg-secondary);
170
+
171
+ &-close:hover {
172
+ background: var(--aura-bg-tertiary);
173
+ }
174
+ }
175
+ }
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+ export interface PaginationProps {
3
+ /** 当前页码(受控) */
4
+ current?: number;
5
+ /** 默认页码
6
+ * @default 1
7
+ */
8
+ defaultCurrent?: number;
9
+ /** 每页条数
10
+ * @default 10
11
+ */
12
+ pageSize?: number;
13
+ /** 数据总条数 */
14
+ total: number;
15
+ /** 是否显示每页条数选择器 */
16
+ showSizeChanger?: boolean;
17
+ /** 每页条数选择器的可选项
18
+ * @default [10, 20, 50, 100]
19
+ */
20
+ pageSizeOptions?: number[];
21
+ /** 自定义总条数展示,参数为总条数与当前区间 [起始, 结束] */
22
+ showTotal?: (total: number, range: [number, number]) => React.ReactNode;
23
+ /** 每页条数变化回调(独立于 onChange,参数为变化前的页码与新的条数) */
24
+ onShowSizeChange?: (current: number, size: number) => void;
25
+ /** 是否显示快速跳转输入框 */
26
+ showQuickJumper?: boolean;
27
+ /** 尺寸
28
+ * @default 'md'
29
+ */
30
+ size?: 'sm' | 'md';
31
+ /** 页码或每页条数变化回调 */
32
+ onChange?: (page: number, pageSize: number) => void;
33
+ /** 自定义类名 */
34
+ className?: string;
35
+ /** 自定义样式 */
36
+ style?: React.CSSProperties;
37
+ }
38
+ export declare const Pagination: React.ForwardRefExoticComponent<PaginationProps & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,180 @@
1
+ import React, { forwardRef, useState, useCallback } from 'react';
2
+ import { classNames, prefixCls } from '@aura-react-comp/shared';
3
+ import { ChevronLeft, ChevronRight } from '@aura-react-comp/icons';
4
+ import "./index.less";
5
+
6
+ /* ===== 页码范围计算 ===== */
7
+
8
+ /**
9
+ * 生成应显示的页码数组
10
+ * 超过 7 页时用 -1 表示省略号
11
+ */
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ function generatePages(current, totalPages) {
15
+ if (totalPages <= 7) {
16
+ return Array.from({
17
+ length: totalPages
18
+ }, (_, i) => i + 1);
19
+ }
20
+ const pages = [1];
21
+ if (current <= 4) {
22
+ // 靠近开头
23
+ pages.push(2, 3, 4, 5, -1, totalPages);
24
+ } else if (current >= totalPages - 3) {
25
+ // 靠近末尾
26
+ pages.push(-1, totalPages - 4, totalPages - 3, totalPages - 2, totalPages - 1, totalPages);
27
+ } else {
28
+ // 中间
29
+ pages.push(-1, current - 1, current, current + 1, -1, totalPages);
30
+ }
31
+ return pages;
32
+ }
33
+
34
+ /* ===== Pagination ===== */
35
+
36
+ export const Pagination = /*#__PURE__*/forwardRef(({
37
+ current: controlledCurrent,
38
+ defaultCurrent = 1,
39
+ pageSize: controlledPageSize,
40
+ total,
41
+ showSizeChanger = false,
42
+ pageSizeOptions = [10, 20, 50, 100],
43
+ showTotal,
44
+ onShowSizeChange,
45
+ showQuickJumper = false,
46
+ size = 'md',
47
+ onChange,
48
+ className,
49
+ style
50
+ }, ref) => {
51
+ /* --- 受控/非受控 --- */
52
+ const [internalCurrent, setInternalCurrent] = useState(defaultCurrent);
53
+ const [internalPageSize, setInternalPageSize] = useState(controlledPageSize ?? 10);
54
+ const isControlled = controlledCurrent !== undefined;
55
+ const currentPage = isControlled ? controlledCurrent : internalCurrent;
56
+ const pageSize = controlledPageSize ?? internalPageSize;
57
+ const totalPages = Math.max(1, Math.ceil(total / pageSize));
58
+
59
+ /* --- 翻页逻辑 --- */
60
+ const goToPage = useCallback(page => {
61
+ const safePage = Math.max(1, Math.min(page, totalPages));
62
+ if (!isControlled) {
63
+ setInternalCurrent(safePage);
64
+ }
65
+ onChange?.(safePage, pageSize);
66
+ }, [isControlled, totalPages, onChange, pageSize]);
67
+ const handlePageSizeChange = useCallback(newPageSize => {
68
+ const prevPage = currentPage;
69
+ if (controlledPageSize === undefined) {
70
+ setInternalPageSize(newPageSize);
71
+ }
72
+ // 切换 pageSize 后回到第一页
73
+ const newTotalPages = Math.max(1, Math.ceil(total / newPageSize));
74
+ if (!isControlled) {
75
+ setInternalCurrent(1);
76
+ }
77
+ onShowSizeChange?.(prevPage, newPageSize);
78
+ onChange?.(1, newPageSize);
79
+ void newTotalPages;
80
+ }, [controlledPageSize, isControlled, onChange, onShowSizeChange, total, currentPage]);
81
+
82
+ /* --- 总条数展示 --- */
83
+ const range = total === 0 ? [0, 0] : [(currentPage - 1) * pageSize + 1, Math.min(currentPage * pageSize, total)];
84
+
85
+ /* --- 页码数组 --- */
86
+ const pages = generatePages(currentPage, totalPages);
87
+
88
+ /* --- Quick Jumper --- */
89
+ const [jumperValue, setJumperValue] = useState('');
90
+ const handleJumperSubmit = useCallback(() => {
91
+ const page = parseInt(jumperValue, 10);
92
+ if (!isNaN(page) && page >= 1 && page <= totalPages) {
93
+ goToPage(page);
94
+ }
95
+ setJumperValue('');
96
+ }, [jumperValue, totalPages, goToPage]);
97
+
98
+ /* --- className --- */
99
+ const wrapperCls = classNames(prefixCls('pagination'), prefixCls(`pagination-${size}`), className);
100
+
101
+ /* --- 上一页/下一页箭头 --- */
102
+ const prevDisabled = currentPage <= 1;
103
+ const nextDisabled = currentPage >= totalPages;
104
+ return /*#__PURE__*/_jsxs("div", {
105
+ ref: ref,
106
+ className: wrapperCls,
107
+ style: style,
108
+ role: "navigation",
109
+ "aria-label": "\u5206\u9875",
110
+ children: [showTotal && /*#__PURE__*/_jsx("span", {
111
+ className: prefixCls('pagination-total'),
112
+ children: showTotal(total, range)
113
+ }), /*#__PURE__*/_jsx("button", {
114
+ type: "button",
115
+ className: classNames(prefixCls('pagination-btn'), prefixCls('pagination-prev'), prevDisabled && prefixCls('pagination-btn-disabled')),
116
+ onClick: () => !prevDisabled && goToPage(currentPage - 1),
117
+ disabled: prevDisabled,
118
+ "aria-label": "\u4E0A\u4E00\u9875",
119
+ children: /*#__PURE__*/_jsx(ChevronLeft, {
120
+ size: 14
121
+ })
122
+ }), /*#__PURE__*/_jsx("div", {
123
+ className: prefixCls('pagination-pages'),
124
+ children: pages.map((page, index) => {
125
+ if (page === -1) {
126
+ return /*#__PURE__*/_jsx("span", {
127
+ className: prefixCls('pagination-ellipsis'),
128
+ "aria-hidden": "true",
129
+ children: "..."
130
+ }, `ellipsis-${index}`);
131
+ }
132
+ const isActive = page === currentPage;
133
+ return /*#__PURE__*/_jsx("button", {
134
+ type: "button",
135
+ className: classNames(prefixCls('pagination-btn'), isActive && prefixCls('pagination-btn-active')),
136
+ onClick: () => !isActive && goToPage(page),
137
+ "aria-current": isActive ? 'page' : undefined,
138
+ "aria-label": `第 ${page} 页`,
139
+ children: page
140
+ }, page);
141
+ })
142
+ }), /*#__PURE__*/_jsx("button", {
143
+ type: "button",
144
+ className: classNames(prefixCls('pagination-btn'), prefixCls('pagination-next'), nextDisabled && prefixCls('pagination-btn-disabled')),
145
+ onClick: () => !nextDisabled && goToPage(currentPage + 1),
146
+ disabled: nextDisabled,
147
+ "aria-label": "\u4E0B\u4E00\u9875",
148
+ children: /*#__PURE__*/_jsx(ChevronRight, {
149
+ size: 14
150
+ })
151
+ }), showSizeChanger && /*#__PURE__*/_jsx("select", {
152
+ className: prefixCls('pagination-size-changer'),
153
+ value: pageSize,
154
+ onChange: e => handlePageSizeChange(Number(e.target.value)),
155
+ "aria-label": "\u6BCF\u9875\u6761\u6570",
156
+ children: pageSizeOptions.map(size => /*#__PURE__*/_jsxs("option", {
157
+ value: size,
158
+ children: [size, " \u6761/\u9875"]
159
+ }, size))
160
+ }), showQuickJumper && /*#__PURE__*/_jsxs("div", {
161
+ className: prefixCls('pagination-jumper'),
162
+ children: [/*#__PURE__*/_jsx("span", {
163
+ className: prefixCls('pagination-jumper-text'),
164
+ children: "\u8DF3\u81F3"
165
+ }), /*#__PURE__*/_jsx("input", {
166
+ className: prefixCls('pagination-jumper-input'),
167
+ value: jumperValue,
168
+ onChange: e => setJumperValue(e.target.value),
169
+ onKeyDown: e => {
170
+ if (e.key === 'Enter') handleJumperSubmit();
171
+ },
172
+ "aria-label": "\u8DF3\u8F6C\u9875\u7801"
173
+ }), /*#__PURE__*/_jsx("span", {
174
+ className: prefixCls('pagination-jumper-text'),
175
+ children: "\u9875"
176
+ })]
177
+ })]
178
+ });
179
+ });
180
+ Pagination.displayName = 'Pagination';