@aura-react-comp/ui 0.0.0-stage → 0.1.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.
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 +163 -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 +107 -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 +175 -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 +247 -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 +258 -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 +118 -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 +182 -0
  62. package/esm/pagination/index.less +230 -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 +155 -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 +104 -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 +471 -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 +179 -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 +160 -0
  96. package/esm/tabs/index.d.ts +45 -0
  97. package/esm/tabs/index.js +170 -0
  98. package/esm/tabs/index.less +228 -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 +226 -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 +107 -0
  118. package/esm/upload/index.d.ts +68 -0
  119. package/esm/upload/index.js +447 -0
  120. package/esm/upload/index.less +376 -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,33 @@
1
+ import React from 'react';
2
+ type NotificationVariant = 'default' | 'success' | 'warning' | 'error' | 'info';
3
+ type NotificationPlacement = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';
4
+ export interface NotificationOptions {
5
+ /** 通知标题,支持任意 ReactNode */
6
+ title?: React.ReactNode;
7
+ /** 通知内容(必填),支持任意 ReactNode */
8
+ content: React.ReactNode;
9
+ /** 唯一标识;重复调用同 key 会原位更新(不重新弹出新通知),并重置自动关闭计时 */
10
+ key?: string;
11
+ /** 自动关闭延时(毫秒);0 表示不自动关闭 */
12
+ duration?: number;
13
+ /** 通知类型 */
14
+ variant?: NotificationVariant;
15
+ /** 弹出位置 */
16
+ placement?: NotificationPlacement;
17
+ /** 底部操作区(按钮组等) */
18
+ actions?: React.ReactNode;
19
+ /** 关闭回调(自动关闭 / 手动关闭 / destroy 均触发) */
20
+ onClose?: () => void;
21
+ }
22
+ export declare function _resetNotificationState(): void;
23
+ export interface NotificationApi {
24
+ open(options: NotificationOptions): void;
25
+ success(options: Omit<NotificationOptions, 'variant'>): void;
26
+ error(options: Omit<NotificationOptions, 'variant'>): void;
27
+ warning(options: Omit<NotificationOptions, 'variant'>): void;
28
+ info(options: Omit<NotificationOptions, 'variant'>): void;
29
+ /** 关闭指定通知;不传 key 关闭全部 */
30
+ destroy(key?: string): void;
31
+ }
32
+ export declare const notification: NotificationApi;
33
+ export default notification;
@@ -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,182 @@
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 { Select } from "../select";
5
+ import "./index.less";
6
+
7
+ /* ===== 页码范围计算 ===== */
8
+
9
+ /**
10
+ * 生成应显示的页码数组
11
+ * 超过 7 页时用 -1 表示省略号
12
+ */
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { jsxs as _jsxs } from "react/jsx-runtime";
15
+ function generatePages(current, totalPages) {
16
+ if (totalPages <= 7) {
17
+ return Array.from({
18
+ length: totalPages
19
+ }, (_, i) => i + 1);
20
+ }
21
+ const pages = [1];
22
+ if (current <= 4) {
23
+ // 靠近开头
24
+ pages.push(2, 3, 4, 5, -1, totalPages);
25
+ } else if (current >= totalPages - 3) {
26
+ // 靠近末尾
27
+ pages.push(-1, totalPages - 4, totalPages - 3, totalPages - 2, totalPages - 1, totalPages);
28
+ } else {
29
+ // 中间
30
+ pages.push(-1, current - 1, current, current + 1, -1, totalPages);
31
+ }
32
+ return pages;
33
+ }
34
+
35
+ /* ===== Pagination ===== */
36
+
37
+ export const Pagination = /*#__PURE__*/forwardRef(({
38
+ current: controlledCurrent,
39
+ defaultCurrent = 1,
40
+ pageSize: controlledPageSize,
41
+ total,
42
+ showSizeChanger = false,
43
+ pageSizeOptions = [10, 20, 50, 100],
44
+ showTotal,
45
+ onShowSizeChange,
46
+ showQuickJumper = false,
47
+ size = 'md',
48
+ onChange,
49
+ className,
50
+ style
51
+ }, ref) => {
52
+ /* --- 受控/非受控 --- */
53
+ const [internalCurrent, setInternalCurrent] = useState(defaultCurrent);
54
+ const [internalPageSize, setInternalPageSize] = useState(controlledPageSize ?? 10);
55
+ const isControlled = controlledCurrent !== undefined;
56
+ const currentPage = isControlled ? controlledCurrent : internalCurrent;
57
+ const pageSize = controlledPageSize ?? internalPageSize;
58
+ const totalPages = Math.max(1, Math.ceil(total / pageSize));
59
+
60
+ /* --- 翻页逻辑 --- */
61
+ const goToPage = useCallback(page => {
62
+ const safePage = Math.max(1, Math.min(page, totalPages));
63
+ if (!isControlled) {
64
+ setInternalCurrent(safePage);
65
+ }
66
+ onChange?.(safePage, pageSize);
67
+ }, [isControlled, totalPages, onChange, pageSize]);
68
+ const handlePageSizeChange = useCallback(newPageSize => {
69
+ const prevPage = currentPage;
70
+ if (controlledPageSize === undefined) {
71
+ setInternalPageSize(newPageSize);
72
+ }
73
+ // 切换 pageSize 后回到第一页
74
+ const newTotalPages = Math.max(1, Math.ceil(total / newPageSize));
75
+ if (!isControlled) {
76
+ setInternalCurrent(1);
77
+ }
78
+ onShowSizeChange?.(prevPage, newPageSize);
79
+ onChange?.(1, newPageSize);
80
+ void newTotalPages;
81
+ }, [controlledPageSize, isControlled, onChange, onShowSizeChange, total, currentPage]);
82
+
83
+ /* --- 总条数展示 --- */
84
+ const range = total === 0 ? [0, 0] : [(currentPage - 1) * pageSize + 1, Math.min(currentPage * pageSize, total)];
85
+
86
+ /* --- 页码数组 --- */
87
+ const pages = generatePages(currentPage, totalPages);
88
+
89
+ /* --- Quick Jumper --- */
90
+ const [jumperValue, setJumperValue] = useState('');
91
+ const handleJumperSubmit = useCallback(() => {
92
+ const page = parseInt(jumperValue, 10);
93
+ if (!isNaN(page) && page >= 1 && page <= totalPages) {
94
+ goToPage(page);
95
+ }
96
+ setJumperValue('');
97
+ }, [jumperValue, totalPages, goToPage]);
98
+
99
+ /* --- className --- */
100
+ const wrapperCls = classNames(prefixCls('pagination'), prefixCls(`pagination-${size}`), className);
101
+
102
+ /* --- 上一页/下一页箭头 --- */
103
+ const prevDisabled = currentPage <= 1;
104
+ const nextDisabled = currentPage >= totalPages;
105
+ return /*#__PURE__*/_jsxs("div", {
106
+ ref: ref,
107
+ className: wrapperCls,
108
+ style: style,
109
+ role: "navigation",
110
+ "aria-label": "\u5206\u9875",
111
+ children: [showTotal && /*#__PURE__*/_jsx("span", {
112
+ className: prefixCls('pagination-total'),
113
+ children: showTotal(total, range)
114
+ }), /*#__PURE__*/_jsx("button", {
115
+ type: "button",
116
+ className: classNames(prefixCls('pagination-btn'), prefixCls('pagination-prev'), prevDisabled && prefixCls('pagination-btn-disabled')),
117
+ onClick: () => !prevDisabled && goToPage(currentPage - 1),
118
+ disabled: prevDisabled,
119
+ "aria-label": "\u4E0A\u4E00\u9875",
120
+ children: /*#__PURE__*/_jsx(ChevronLeft, {
121
+ size: 14
122
+ })
123
+ }), /*#__PURE__*/_jsx("div", {
124
+ className: prefixCls('pagination-pages'),
125
+ children: pages.map((page, index) => {
126
+ if (page === -1) {
127
+ return /*#__PURE__*/_jsx("span", {
128
+ className: prefixCls('pagination-ellipsis'),
129
+ "aria-hidden": "true",
130
+ children: "..."
131
+ }, `ellipsis-${index}`);
132
+ }
133
+ const isActive = page === currentPage;
134
+ return /*#__PURE__*/_jsx("button", {
135
+ type: "button",
136
+ className: classNames(prefixCls('pagination-btn'), isActive && prefixCls('pagination-btn-active')),
137
+ onClick: () => !isActive && goToPage(page),
138
+ "aria-current": isActive ? 'page' : undefined,
139
+ "aria-label": `第 ${page} 页`,
140
+ children: page
141
+ }, page);
142
+ })
143
+ }), /*#__PURE__*/_jsx("button", {
144
+ type: "button",
145
+ className: classNames(prefixCls('pagination-btn'), prefixCls('pagination-next'), nextDisabled && prefixCls('pagination-btn-disabled')),
146
+ onClick: () => !nextDisabled && goToPage(currentPage + 1),
147
+ disabled: nextDisabled,
148
+ "aria-label": "\u4E0B\u4E00\u9875",
149
+ children: /*#__PURE__*/_jsx(ChevronRight, {
150
+ size: 14
151
+ })
152
+ }), showSizeChanger && /*#__PURE__*/_jsx(Select, {
153
+ className: prefixCls('pagination-size-changer'),
154
+ size: size,
155
+ value: pageSize,
156
+ options: pageSizeOptions.map(option => ({
157
+ label: `${option} 条/页`,
158
+ value: option
159
+ })),
160
+ onChange: value => handlePageSizeChange(Number(value)),
161
+ "aria-label": "\u6BCF\u9875\u6761\u6570"
162
+ }), showQuickJumper && /*#__PURE__*/_jsxs("div", {
163
+ className: prefixCls('pagination-jumper'),
164
+ children: [/*#__PURE__*/_jsx("span", {
165
+ className: prefixCls('pagination-jumper-text'),
166
+ children: "\u8DF3\u81F3"
167
+ }), /*#__PURE__*/_jsx("input", {
168
+ className: prefixCls('pagination-jumper-input'),
169
+ value: jumperValue,
170
+ onChange: e => setJumperValue(e.target.value),
171
+ onKeyDown: e => {
172
+ if (e.key === 'Enter') handleJumperSubmit();
173
+ },
174
+ "aria-label": "\u8DF3\u8F6C\u9875\u7801"
175
+ }), /*#__PURE__*/_jsx("span", {
176
+ className: prefixCls('pagination-jumper-text'),
177
+ children: "\u9875"
178
+ })]
179
+ })]
180
+ });
181
+ });
182
+ Pagination.displayName = 'Pagination';