@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,255 @@
1
+ import React, { forwardRef, useState, useRef, useCallback, useEffect } from 'react';
2
+ import { classNames, prefixCls } from '@aura-react-comp/shared';
3
+ import "./index.less";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ import { jsxs as _jsxs } from "react/jsx-runtime";
6
+ /** 将值限制在 [min, max] 范围内 */
7
+ function clamp(val, min, max) {
8
+ return Math.min(Math.max(val, min), max);
9
+ }
10
+
11
+ /** 将值对齐到步长 */
12
+ function alignToStep(val, min, step) {
13
+ const steps = Math.round((val - min) / step);
14
+ return min + steps * step;
15
+ }
16
+ export const Slider = /*#__PURE__*/forwardRef(({
17
+ min = 0,
18
+ max = 100,
19
+ step = 1,
20
+ value: controlledValue,
21
+ defaultValue,
22
+ disabled = false,
23
+ marks,
24
+ range = false,
25
+ onChange,
26
+ onChangeComplete,
27
+ className,
28
+ style,
29
+ // role="slider" 落在滑块本体上,名称需由调用方通过 aria-* 提供
30
+ 'aria-label': ariaLabel,
31
+ 'aria-labelledby': ariaLabelledBy
32
+ }, ref) => {
33
+ // 内部维护的值(非受控模式)
34
+ const [internalValue, setInternalValue] = useState(() => {
35
+ if (defaultValue !== undefined) return defaultValue;
36
+ return range ? [min, max] : min;
37
+ });
38
+
39
+ // 当前生效的值
40
+ const currentValue = controlledValue !== undefined ? controlledValue : internalValue;
41
+
42
+ // 拖拽状态
43
+ const [dragging, setDragging] = useState(null);
44
+ const trackRef = useRef(null);
45
+
46
+ // 获取单个值对应的百分比
47
+ const getPercent = useCallback(val => {
48
+ const total = max - min;
49
+ if (total === 0) return 0;
50
+ return (val - min) / total * 100;
51
+ }, [min, max]);
52
+
53
+ // 根据鼠标位置计算值
54
+ const getValueFromPosition = useCallback(clientX => {
55
+ if (!trackRef.current) return min;
56
+ const rect = trackRef.current.getBoundingClientRect();
57
+ const percent = clamp((clientX - rect.left) / rect.width, 0, 1);
58
+ const rawValue = min + percent * (max - min);
59
+ return alignToStep(clamp(rawValue, min, max), min, step);
60
+ }, [min, max, step]);
61
+
62
+ // 更新值
63
+ const updateValue = useCallback(newValue => {
64
+ if (controlledValue === undefined) {
65
+ setInternalValue(newValue);
66
+ }
67
+ onChange?.(newValue);
68
+ }, [controlledValue, onChange]);
69
+
70
+ // 处理按下(Pointer Events:鼠标 / 触摸 / 触控笔统一处理)
71
+ const handlePointerDown = useCallback((e, handle) => {
72
+ if (disabled) return;
73
+ e.preventDefault();
74
+ setDragging(handle);
75
+ }, [disabled]);
76
+
77
+ // 键盘调节(方向键 ±step、PageUp/Down ±10step、Home/End 到两端)
78
+ const stepValue = useCallback((handle, delta) => {
79
+ let next;
80
+ if (range) {
81
+ const [start, end] = currentValue;
82
+ if (handle === 'start') {
83
+ const target = delta === 'min' ? min : delta === 'max' ? end : start + delta;
84
+ const newStart = clamp(alignToStep(clamp(target, min, end), min, step), min, end);
85
+ next = [newStart, end];
86
+ } else {
87
+ const target = delta === 'min' ? start : delta === 'max' ? max : end + delta;
88
+ const newEnd = clamp(alignToStep(clamp(target, start, max), min, step), start, max);
89
+ next = [start, newEnd];
90
+ }
91
+ } else {
92
+ const base = currentValue;
93
+ const target = delta === 'min' ? min : delta === 'max' ? max : base + delta;
94
+ next = alignToStep(clamp(target, min, max), min, step);
95
+ }
96
+ updateValue(next);
97
+ onChangeComplete?.(next);
98
+ }, [currentValue, range, min, max, step, updateValue, onChangeComplete]);
99
+ const makeHandleKeyDown = handle => e => {
100
+ if (disabled) return;
101
+ const deltas = {
102
+ ArrowLeft: -step,
103
+ ArrowDown: -step,
104
+ ArrowRight: step,
105
+ ArrowUp: step,
106
+ PageDown: -step * 10,
107
+ PageUp: step * 10,
108
+ Home: 'min',
109
+ End: 'max'
110
+ };
111
+ const delta = deltas[e.key];
112
+ if (delta === undefined) return;
113
+ e.preventDefault();
114
+ stepValue(handle, delta);
115
+ };
116
+
117
+ // 处理轨道点击(非拖拽)
118
+ const handleTrackClick = useCallback(e => {
119
+ if (disabled || dragging) return;
120
+ // 忽略来自滑块手柄的事件
121
+ const target = e.target;
122
+ if (target.closest(`.${prefixCls('slider-handle')}`)) return;
123
+ const newValue = getValueFromPosition(e.clientX);
124
+ if (range) {
125
+ const [start, end] = currentValue;
126
+ // 靠近哪个滑块就移动哪个
127
+ const distStart = Math.abs(newValue - start);
128
+ const distEnd = Math.abs(newValue - end);
129
+ if (distStart <= distEnd) {
130
+ updateValue([newValue, end]);
131
+ } else {
132
+ updateValue([start, newValue]);
133
+ }
134
+ } else {
135
+ updateValue(newValue);
136
+ }
137
+ onChangeComplete?.(newValue);
138
+ }, [disabled, dragging, getValueFromPosition, currentValue, range, updateValue, onChangeComplete]);
139
+
140
+ // 拖拽移动和松开事件(Pointer Events 覆盖鼠标与触摸)
141
+ useEffect(() => {
142
+ if (!dragging) return;
143
+ const handlePointerMove = e => {
144
+ const newValue = getValueFromPosition(e.clientX);
145
+ if (range) {
146
+ const [start, end] = currentValue;
147
+ if (dragging === 'start') {
148
+ const newStart = Math.min(newValue, end);
149
+ updateValue([newStart, end]);
150
+ } else {
151
+ const newEnd = Math.max(newValue, start);
152
+ updateValue([start, newEnd]);
153
+ }
154
+ } else {
155
+ updateValue(newValue);
156
+ }
157
+ };
158
+ const handlePointerUp = () => {
159
+ setDragging(null);
160
+ // 松开时提交最后一次更新(回调闭包随 currentValue 更新,此处值是新鲜的)
161
+ onChangeComplete?.(currentValue);
162
+ };
163
+ document.addEventListener('pointermove', handlePointerMove);
164
+ document.addEventListener('pointerup', handlePointerUp);
165
+ document.addEventListener('pointercancel', handlePointerUp);
166
+ return () => {
167
+ document.removeEventListener('pointermove', handlePointerMove);
168
+ document.removeEventListener('pointerup', handlePointerUp);
169
+ document.removeEventListener('pointercancel', handlePointerUp);
170
+ };
171
+ }, [dragging, getValueFromPosition, currentValue, range, updateValue, onChangeComplete]);
172
+
173
+ // 获取当前展示值
174
+ const startValue = range ? currentValue[0] : currentValue;
175
+ const endValue = range ? currentValue[1] : currentValue;
176
+ const startPercent = getPercent(startValue);
177
+ const endPercent = getPercent(endValue);
178
+ const cls = classNames(prefixCls('slider'), disabled && prefixCls('slider-disabled'), dragging && prefixCls('slider-dragging'), className);
179
+
180
+ // 渲染标记
181
+ const renderMarks = () => {
182
+ if (!marks) return null;
183
+ const markKeys = Object.keys(marks).map(Number).sort((a, b) => a - b);
184
+ return /*#__PURE__*/_jsx("div", {
185
+ className: prefixCls('slider-marks'),
186
+ children: markKeys.map(markValue => /*#__PURE__*/_jsx("span", {
187
+ className: classNames(prefixCls('slider-mark'), markValue >= startValue && markValue <= endValue && prefixCls('slider-mark-active')),
188
+ style: {
189
+ left: `${getPercent(markValue)}%`
190
+ },
191
+ children: marks[markValue]
192
+ }, markValue))
193
+ });
194
+ };
195
+
196
+ /** 滑块的可访问名称:range 模式下两个滑块需要彼此可区分 */
197
+ const handleAriaLabel = which => {
198
+ if (!range) return ariaLabel;
199
+ const suffix = which === 'start' ? '最小值' : '最大值';
200
+ return ariaLabel ? `${ariaLabel}·${suffix}` : suffix;
201
+ };
202
+ return (
203
+ /*#__PURE__*/
204
+ // 容器不是可聚焦控件,不应承担 role="slider":否则容器与滑块体会重复表达
205
+ // 同一语义,且容器无名称可用(axe 报 aria-input-field-name)。语义交给滑块本体。
206
+ _jsxs("div", {
207
+ ref: ref,
208
+ className: cls,
209
+ style: style,
210
+ children: [/*#__PURE__*/_jsxs("div", {
211
+ ref: trackRef,
212
+ className: prefixCls('slider-track'),
213
+ onClick: handleTrackClick,
214
+ children: [/*#__PURE__*/_jsx("div", {
215
+ className: prefixCls('slider-track-selected'),
216
+ style: {
217
+ left: `${startPercent}%`,
218
+ width: `${endPercent - startPercent}%`
219
+ }
220
+ }), range && /*#__PURE__*/_jsx("div", {
221
+ className: classNames(prefixCls('slider-handle'), prefixCls('slider-handle-start'), dragging === 'start' && prefixCls('slider-handle-active')),
222
+ style: {
223
+ left: `${startPercent}%`
224
+ },
225
+ onPointerDown: e => handlePointerDown(e, 'start'),
226
+ onKeyDown: makeHandleKeyDown('start'),
227
+ role: "slider",
228
+ "aria-valuemin": min,
229
+ "aria-valuemax": max,
230
+ "aria-valuenow": startValue,
231
+ "aria-label": handleAriaLabel('start'),
232
+ "aria-labelledby": ariaLabelledBy,
233
+ "aria-disabled": disabled,
234
+ tabIndex: disabled ? -1 : 0
235
+ }), /*#__PURE__*/_jsx("div", {
236
+ className: classNames(prefixCls('slider-handle'), prefixCls('slider-handle-end'), dragging === 'end' && prefixCls('slider-handle-active')),
237
+ style: {
238
+ left: `${endPercent}%`
239
+ },
240
+ onPointerDown: e => handlePointerDown(e, 'end'),
241
+ onKeyDown: makeHandleKeyDown('end'),
242
+ role: "slider",
243
+ "aria-valuemin": min,
244
+ "aria-valuemax": max,
245
+ "aria-valuenow": endValue,
246
+ "aria-label": handleAriaLabel('end'),
247
+ "aria-labelledby": ariaLabelledBy,
248
+ "aria-disabled": disabled,
249
+ tabIndex: disabled ? -1 : 0
250
+ })]
251
+ }), renderMarks()]
252
+ })
253
+ );
254
+ });
255
+ Slider.displayName = 'Slider';
@@ -0,0 +1,154 @@
1
+ /* ===== Slider 组件样式 ===== */
2
+
3
+ .aura-slider {
4
+ position: relative;
5
+ width: 100%;
6
+ padding: var(--aura-spacing-3) 0;
7
+ user-select: none;
8
+ touch-action: none;
9
+
10
+ // 禁用状态
11
+ &&-disabled {
12
+ opacity: 0.5;
13
+ cursor: not-allowed;
14
+ pointer-events: none;
15
+ }
16
+ }
17
+
18
+ // ===== 轨道 =====
19
+ .aura-slider-track {
20
+ position: relative;
21
+ width: 100%;
22
+ height: 6px;
23
+ border-radius: var(--aura-radius-full);
24
+ background: var(--aura-gray-200);
25
+ cursor: pointer;
26
+ transition: height var(--aura-duration-fast) var(--aura-easing);
27
+
28
+ &:hover {
29
+ height: 8px;
30
+ }
31
+ }
32
+
33
+ // ===== 已选区域 =====
34
+ .aura-slider-track-selected {
35
+ position: absolute;
36
+ top: 0;
37
+ height: 100%;
38
+ border-radius: var(--aura-radius-full);
39
+ background: var(--aura-primary-700);
40
+ transition:
41
+ left var(--aura-duration-fast) var(--aura-easing),
42
+ width var(--aura-duration-fast) var(--aura-easing);
43
+
44
+ .aura-slider-disabled & {
45
+ background: var(--aura-gray-400);
46
+ }
47
+ }
48
+
49
+ // ===== 滑块手柄 =====
50
+ .aura-slider-handle {
51
+ position: absolute;
52
+ top: 50%;
53
+ width: 16px;
54
+ height: 16px;
55
+ border-radius: 50%;
56
+ background: var(--aura-bg);
57
+ border: 2px solid var(--aura-primary-700);
58
+ transform: translate(-50%, -50%);
59
+ cursor: grab;
60
+ z-index: 1;
61
+ // 触屏拖拽时阻止浏览器把手势识别为页面滚动
62
+ touch-action: none;
63
+ transition:
64
+ box-shadow var(--aura-duration-normal) var(--aura-easing),
65
+ transform var(--aura-duration-normal) cubic-bezier(0.34, 1.56, 0.64, 1),
66
+ border-color var(--aura-duration-normal) var(--aura-easing);
67
+
68
+ &:hover {
69
+ box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.15);
70
+ }
71
+
72
+ &:focus-visible {
73
+ outline: none;
74
+ box-shadow:
75
+ 0 0 0 2px var(--aura-primary-200),
76
+ 0 0 0 4px rgba(124, 58, 237, 0.15);
77
+ }
78
+
79
+ // 拖拽激活状态
80
+ &&-active {
81
+ width: 20px;
82
+ height: 20px;
83
+ cursor: grabbing;
84
+ box-shadow:
85
+ var(--aura-shadow-md),
86
+ 0 0 0 4px rgba(124, 58, 237, 0.2);
87
+ transform: translate(-50%, -50%) scale(1.1);
88
+ }
89
+
90
+ .aura-slider-disabled & {
91
+ border-color: var(--aura-gray-400);
92
+ cursor: not-allowed;
93
+
94
+ &:hover {
95
+ box-shadow: none;
96
+ }
97
+ }
98
+ }
99
+
100
+ // ===== 标记 =====
101
+ .aura-slider-marks {
102
+ position: relative;
103
+ width: 100%;
104
+ margin-top: var(--aura-spacing-2);
105
+ height: 20px;
106
+ }
107
+
108
+ .aura-slider-mark {
109
+ position: absolute;
110
+ transform: translateX(-50%);
111
+ font-size: var(--aura-font-size-xs);
112
+ color: var(--aura-text-tertiary);
113
+ white-space: nowrap;
114
+ transition: color var(--aura-duration-fast) var(--aura-easing);
115
+
116
+ // 激活状态的标记
117
+ &&-active {
118
+ color: var(--aura-primary-700);
119
+ }
120
+ }
121
+
122
+ // ===== 暗色模式 =====
123
+ [data-theme='dark'] {
124
+ .aura-slider-track {
125
+ background: var(--aura-gray-700);
126
+ }
127
+
128
+ .aura-slider-track-selected {
129
+ background: var(--aura-primary-600);
130
+ }
131
+
132
+ .aura-slider-handle {
133
+ background: var(--aura-gray-800);
134
+ border-color: var(--aura-primary-600);
135
+
136
+ &:hover {
137
+ box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.25);
138
+ }
139
+
140
+ &&-active {
141
+ box-shadow:
142
+ var(--aura-shadow-lg),
143
+ 0 0 0 4px rgba(124, 58, 237, 0.3);
144
+ }
145
+ }
146
+
147
+ .aura-slider-mark {
148
+ color: var(--aura-gray-400);
149
+
150
+ &&-active {
151
+ color: var(--aura-primary-400);
152
+ }
153
+ }
154
+ }
@@ -0,0 +1,16 @@
1
+ import React, { HTMLAttributes } from 'react';
2
+ export interface SpaceProps extends HTMLAttributes<HTMLDivElement> {
3
+ /** 排列方向
4
+ * @default 'horizontal'
5
+ */
6
+ direction?: 'horizontal' | 'vertical';
7
+ /** 间距大小,支持预设尺寸或自定义像素值
8
+ * @default 'md'
9
+ */
10
+ size?: 'sm' | 'md' | 'lg' | number;
11
+ /** 是否自动换行(仅水平方向有效) */
12
+ wrap?: boolean;
13
+ /** 对齐方式 */
14
+ align?: 'start' | 'center' | 'end' | 'baseline';
15
+ }
16
+ export declare const Space: React.ForwardRefExoticComponent<SpaceProps & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,34 @@
1
+ import React, { forwardRef } from 'react';
2
+ import { classNames, prefixCls } from '@aura-react-comp/shared';
3
+ import "./index.less";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ const sizeMap = {
6
+ sm: 8,
7
+ md: 16,
8
+ lg: 24
9
+ };
10
+ export const Space = /*#__PURE__*/forwardRef(({
11
+ direction = 'horizontal',
12
+ size = 'md',
13
+ wrap = false,
14
+ align,
15
+ className,
16
+ style,
17
+ children,
18
+ ...rest
19
+ }, ref) => {
20
+ const gap = typeof size === 'number' ? size : sizeMap[size];
21
+ const cls = classNames(prefixCls('space'), direction === 'vertical' && prefixCls('space-vertical'), wrap && prefixCls('space-wrap'), align && prefixCls(`space-align-${align}`), className);
22
+ const mergedStyle = {
23
+ ...style,
24
+ gap: `${gap}px`
25
+ };
26
+ return /*#__PURE__*/_jsx("div", {
27
+ ref: ref,
28
+ className: cls,
29
+ style: mergedStyle,
30
+ ...rest,
31
+ children: children
32
+ });
33
+ });
34
+ Space.displayName = 'Space';
@@ -0,0 +1,34 @@
1
+ /* ===== Space 布局 ===== */
2
+ .aura-space {
3
+ display: inline-flex;
4
+ flex-direction: row;
5
+ align-items: center;
6
+ flex-wrap: nowrap;
7
+
8
+ /* 垂直方向 */
9
+ &&-vertical {
10
+ flex-direction: column;
11
+ }
12
+
13
+ /* 自动换行 */
14
+ &&-wrap {
15
+ flex-wrap: wrap;
16
+ }
17
+
18
+ /* 对齐方式 */
19
+ &&-align-start {
20
+ align-items: flex-start;
21
+ }
22
+
23
+ &&-align-center {
24
+ align-items: center;
25
+ }
26
+
27
+ &&-align-end {
28
+ align-items: flex-end;
29
+ }
30
+
31
+ &&-align-baseline {
32
+ align-items: baseline;
33
+ }
34
+ }
@@ -0,0 +1,44 @@
1
+ import React from 'react';
2
+ export interface SpinProps {
3
+ /**
4
+ * 加载指示器尺寸
5
+ * @default 'md'
6
+ */
7
+ size?: 'sm' | 'md' | 'lg';
8
+ /**
9
+ * 是否加载中
10
+ * @default true
11
+ */
12
+ spinning?: boolean;
13
+ /**
14
+ * 延迟显示加载指示器(ms),避免快速加载时闪烁
15
+ * @default 0
16
+ */
17
+ delay?: number;
18
+ /**
19
+ * 加载动画样式
20
+ * @default 'default'
21
+ */
22
+ variant?: 'default' | 'dot';
23
+ /**
24
+ * 加载提示文字
25
+ */
26
+ tip?: React.ReactNode;
27
+ /**
28
+ * 自定义加载图标
29
+ */
30
+ indicator?: React.ReactNode;
31
+ /**
32
+ * 包裹的内容(加载时半透明)
33
+ */
34
+ children?: React.ReactNode;
35
+ /**
36
+ * 自定义类名
37
+ */
38
+ className?: string;
39
+ /**
40
+ * 自定义样式
41
+ */
42
+ style?: React.CSSProperties;
43
+ }
44
+ export declare const Spin: React.ForwardRefExoticComponent<SpinProps & React.RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,152 @@
1
+ import React, { forwardRef, useEffect, useState, useMemo } from 'react';
2
+ import { classNames, prefixCls } from '@aura-react-comp/shared';
3
+ import "./index.less";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ import { jsxs as _jsxs } from "react/jsx-runtime";
6
+ /** 尺寸 → 像素映射 */
7
+ const SIZE_MAP = {
8
+ sm: 16,
9
+ md: 24,
10
+ lg: 36
11
+ };
12
+
13
+ /**
14
+ * 内联 Spinner SVG:底层半透明轨道圆 + 顶层追逐弧线
15
+ * 使用纯 CSS 旋转动画,避免 JS 动画开销
16
+ */
17
+ const SpinnerSvg = ({
18
+ pixelSize,
19
+ className
20
+ }) => {
21
+ // 根据尺寸动态计算 stroke 宽度,小尺寸相对更粗以保持可见性
22
+ const strokeWidth = pixelSize <= 16 ? 2.5 : pixelSize <= 24 ? 2.5 : 3;
23
+ const center = pixelSize / 2;
24
+ const radius = center - strokeWidth / 2;
25
+ const circumference = 2 * Math.PI * radius;
26
+ // 弧线占圆周的 75%,剩余 25% 为缺口
27
+ const arcLength = circumference * 0.75;
28
+ return /*#__PURE__*/_jsxs("svg", {
29
+ className: className,
30
+ viewBox: `0 0 ${pixelSize} ${pixelSize}`,
31
+ width: pixelSize,
32
+ height: pixelSize,
33
+ "aria-hidden": "true",
34
+ fill: "none",
35
+ children: [/*#__PURE__*/_jsx("circle", {
36
+ cx: center,
37
+ cy: center,
38
+ r: radius,
39
+ stroke: "currentColor",
40
+ strokeWidth: strokeWidth,
41
+ opacity: 0.18
42
+ }), /*#__PURE__*/_jsx("circle", {
43
+ cx: center,
44
+ cy: center,
45
+ r: radius,
46
+ stroke: "currentColor",
47
+ strokeWidth: strokeWidth,
48
+ strokeLinecap: "round",
49
+ strokeDasharray: `${arcLength} ${circumference}`
50
+ })]
51
+ });
52
+ };
53
+
54
+ /**
55
+ * 点状加载动画 — 三个弹跳圆点
56
+ */
57
+ const DotIndicator = ({
58
+ className
59
+ }) => /*#__PURE__*/_jsxs("span", {
60
+ className: className,
61
+ "aria-hidden": "true",
62
+ children: [/*#__PURE__*/_jsx("span", {
63
+ className: prefixCls('spin-dot-item')
64
+ }), /*#__PURE__*/_jsx("span", {
65
+ className: prefixCls('spin-dot-item')
66
+ }), /*#__PURE__*/_jsx("span", {
67
+ className: prefixCls('spin-dot-item')
68
+ })]
69
+ });
70
+ export const Spin = /*#__PURE__*/forwardRef(({
71
+ size = 'md',
72
+ spinning: spinningProp = true,
73
+ delay = 0,
74
+ variant = 'default',
75
+ tip,
76
+ indicator,
77
+ children,
78
+ className,
79
+ style
80
+ }, ref) => {
81
+ const pixelSize = SIZE_MAP[size] ?? 24;
82
+
83
+ // delay 逻辑:避免快速加载闪烁
84
+ const [showSpinner, setShowSpinner] = useState(delay === 0);
85
+ useEffect(() => {
86
+ if (delay <= 0) {
87
+ setShowSpinner(true);
88
+ return;
89
+ }
90
+ setShowSpinner(false);
91
+ const timer = setTimeout(() => setShowSpinner(true), delay);
92
+ return () => clearTimeout(timer);
93
+ }, [delay]);
94
+
95
+ // 合并 spinning 状态:外部 spinning + 内部 delay
96
+ const effectiveSpinning = spinningProp && (delay === 0 || showSpinner);
97
+
98
+ // 构建默认指示器
99
+ const defaultIndicator = useMemo(() => {
100
+ if (indicator) return indicator;
101
+ if (variant === 'dot') {
102
+ return /*#__PURE__*/_jsx(DotIndicator, {
103
+ className: prefixCls('spin-dot')
104
+ });
105
+ }
106
+ return /*#__PURE__*/_jsx(SpinnerSvg, {
107
+ pixelSize: pixelSize,
108
+ className: prefixCls('spin-svg')
109
+ });
110
+ }, [indicator, variant, pixelSize]);
111
+
112
+ // 核心 spin 元素
113
+ const spinElement = /*#__PURE__*/_jsxs("div", {
114
+ className: prefixCls('spin-indicator'),
115
+ children: [defaultIndicator, tip && /*#__PURE__*/_jsx("span", {
116
+ className: prefixCls('spin-tip'),
117
+ children: tip
118
+ })]
119
+ });
120
+
121
+ // 无 children:独立显示
122
+ if (!children) {
123
+ const cls = classNames(prefixCls('spin'), prefixCls(`spin-${size}`), !effectiveSpinning && prefixCls('spin-hidden'), className);
124
+ return /*#__PURE__*/_jsx("div", {
125
+ ref: ref,
126
+ className: cls,
127
+ style: style,
128
+ role: "status",
129
+ "aria-label": typeof tip === 'string' ? tip : '加载中',
130
+ children: effectiveSpinning && spinElement
131
+ });
132
+ }
133
+
134
+ // 有 children:包裹模式
135
+ const containerCls = classNames(prefixCls('spin-container'), effectiveSpinning && prefixCls('spin-spinning'), className);
136
+ return /*#__PURE__*/_jsxs("div", {
137
+ ref: ref,
138
+ className: containerCls,
139
+ style: style,
140
+ children: [effectiveSpinning && /*#__PURE__*/_jsx("div", {
141
+ className: prefixCls('spin-overlay'),
142
+ role: "status",
143
+ "aria-label": typeof tip === 'string' ? tip : '加载中',
144
+ children: spinElement
145
+ }), /*#__PURE__*/_jsx("div", {
146
+ className: classNames(prefixCls('spin-content'), effectiveSpinning && prefixCls('spin-content-blur')),
147
+ "aria-busy": effectiveSpinning,
148
+ children: children
149
+ })]
150
+ });
151
+ });
152
+ Spin.displayName = 'Spin';