@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.
- package/LICENSE +21 -0
- package/README.md +67 -2
- package/esm/alert/index.d.ts +28 -0
- package/esm/alert/index.js +76 -0
- package/esm/alert/index.less +172 -0
- package/esm/avatar/index.d.ts +41 -0
- package/esm/avatar/index.js +117 -0
- package/esm/avatar/index.less +162 -0
- package/esm/badge/index.d.ts +29 -0
- package/esm/badge/index.js +84 -0
- package/esm/badge/index.less +215 -0
- package/esm/breadcrumb/index.d.ts +31 -0
- package/esm/breadcrumb/index.js +91 -0
- package/esm/breadcrumb/index.less +108 -0
- package/esm/button/index.d.ts +28 -0
- package/esm/button/index.js +59 -0
- package/esm/button/index.less +191 -0
- package/esm/card/index.d.ts +67 -0
- package/esm/card/index.js +156 -0
- package/esm/card/index.less +231 -0
- package/esm/checkbox/index.d.ts +35 -0
- package/esm/checkbox/index.js +118 -0
- package/esm/checkbox/index.less +141 -0
- package/esm/collapse/index.d.ts +45 -0
- package/esm/collapse/index.js +157 -0
- package/esm/collapse/index.less +144 -0
- package/esm/divider/index.d.ts +16 -0
- package/esm/divider/index.js +37 -0
- package/esm/divider/index.less +115 -0
- package/esm/dropdown/index.d.ts +38 -0
- package/esm/dropdown/index.js +108 -0
- package/esm/dropdown/index.less +245 -0
- package/esm/empty/index.d.ts +35 -0
- package/esm/empty/index.js +87 -0
- package/esm/empty/index.less +67 -0
- package/esm/flex/index.d.ts +24 -0
- package/esm/flex/index.js +64 -0
- package/esm/flex/index.less +9 -0
- package/esm/form/index.d.ts +121 -0
- package/esm/form/index.js +443 -0
- package/esm/form/index.less +257 -0
- package/esm/global.d.ts +6 -0
- package/esm/index.d.ts +78 -0
- package/esm/index.js +41 -0
- package/esm/input/index.d.ts +51 -0
- package/esm/input/index.js +217 -0
- package/esm/input/index.less +369 -0
- package/esm/layout/index.d.ts +46 -0
- package/esm/layout/index.js +135 -0
- package/esm/layout/index.less +132 -0
- package/esm/menu/index.d.ts +91 -0
- package/esm/menu/index.js +294 -0
- package/esm/menu/index.less +340 -0
- package/esm/message/index.d.ts +33 -0
- package/esm/message/index.js +199 -0
- package/esm/message/index.less +113 -0
- package/esm/notification/index.d.ts +33 -0
- package/esm/notification/index.js +229 -0
- package/esm/notification/index.less +175 -0
- package/esm/pagination/index.d.ts +38 -0
- package/esm/pagination/index.js +180 -0
- package/esm/pagination/index.less +238 -0
- package/esm/popconfirm/index.d.ts +37 -0
- package/esm/popconfirm/index.js +115 -0
- package/esm/popconfirm/index.less +229 -0
- package/esm/radio/index.d.ts +33 -0
- package/esm/radio/index.js +122 -0
- package/esm/radio/index.less +119 -0
- package/esm/rate/index.d.ts +30 -0
- package/esm/rate/index.js +143 -0
- package/esm/rate/index.less +87 -0
- package/esm/result/index.d.ts +19 -0
- package/esm/result/index.js +69 -0
- package/esm/result/index.less +103 -0
- package/esm/scrollbar/index.d.ts +18 -0
- package/esm/scrollbar/index.js +35 -0
- package/esm/scrollbar/index.less +67 -0
- package/esm/select/index.d.ts +63 -0
- package/esm/select/index.js +358 -0
- package/esm/select/index.less +427 -0
- package/esm/slider/index.d.ts +36 -0
- package/esm/slider/index.js +255 -0
- package/esm/slider/index.less +154 -0
- package/esm/space/index.d.ts +16 -0
- package/esm/space/index.js +34 -0
- package/esm/space/index.less +34 -0
- package/esm/spin/index.d.ts +44 -0
- package/esm/spin/index.js +152 -0
- package/esm/spin/index.less +170 -0
- package/esm/steps/index.d.ts +55 -0
- package/esm/steps/index.js +165 -0
- package/esm/steps/index.less +394 -0
- package/esm/switch/index.d.ts +30 -0
- package/esm/switch/index.js +56 -0
- package/esm/switch/index.less +135 -0
- package/esm/tabs/index.d.ts +45 -0
- package/esm/tabs/index.js +170 -0
- package/esm/tabs/index.less +226 -0
- package/esm/tag/index.d.ts +52 -0
- package/esm/tag/index.js +120 -0
- package/esm/tag/index.less +227 -0
- package/esm/textarea/index.d.ts +27 -0
- package/esm/textarea/index.js +84 -0
- package/esm/textarea/index.less +224 -0
- package/esm/theme/ThemeProvider.d.ts +15 -0
- package/esm/theme/ThemeProvider.js +32 -0
- package/esm/theme/index.d.ts +2 -0
- package/esm/theme/index.js +1 -0
- package/esm/theme/tokens.css +183 -0
- package/esm/theme/useTheme.d.ts +1 -0
- package/esm/theme/useTheme.js +1 -0
- package/esm/tooltip/index.d.ts +38 -0
- package/esm/tooltip/index.js +149 -0
- package/esm/tooltip/index.less +244 -0
- package/esm/typography/index.d.ts +26 -0
- package/esm/typography/index.js +92 -0
- package/esm/typography/index.less +106 -0
- package/esm/upload/index.d.ts +68 -0
- package/esm/upload/index.js +447 -0
- package/esm/upload/index.less +371 -0
- package/esm/upload/request.d.ts +26 -0
- package/esm/upload/request.js +38 -0
- package/package.json +56 -3
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
.aura-select {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: inline-block;
|
|
4
|
+
width: 100%;
|
|
5
|
+
max-width: 100%;
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
min-width: 160px;
|
|
8
|
+
|
|
9
|
+
&-selector {
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
width: 100%;
|
|
13
|
+
padding: 8px 32px 8px 12px;
|
|
14
|
+
font-size: var(--aura-font-size-md);
|
|
15
|
+
font-family: inherit;
|
|
16
|
+
line-height: 1.5;
|
|
17
|
+
border: 1px solid var(--aura-border);
|
|
18
|
+
border-radius: var(--aura-radius-md);
|
|
19
|
+
background: var(--aura-bg);
|
|
20
|
+
color: var(--aura-text);
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
transition: all var(--aura-duration-normal) var(--aura-easing);
|
|
23
|
+
position: relative;
|
|
24
|
+
min-height: 38px;
|
|
25
|
+
box-sizing: border-box;
|
|
26
|
+
|
|
27
|
+
&:hover {
|
|
28
|
+
border-color: var(--aura-primary-700);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
&:focus-visible {
|
|
32
|
+
outline: none;
|
|
33
|
+
box-shadow: 0 0 0 2px var(--aura-primary-200);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 箭头区域
|
|
38
|
+
&-arrow {
|
|
39
|
+
position: absolute;
|
|
40
|
+
right: 10px;
|
|
41
|
+
top: 50%;
|
|
42
|
+
transform: translateY(-50%);
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
color: var(--aura-text-tertiary);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
&-arrow-icon {
|
|
49
|
+
display: inline-block;
|
|
50
|
+
width: 0;
|
|
51
|
+
height: 0;
|
|
52
|
+
border-left: 4px solid transparent;
|
|
53
|
+
border-right: 4px solid transparent;
|
|
54
|
+
border-top: 5px solid currentColor;
|
|
55
|
+
transition: transform var(--aura-duration-normal) var(--aura-easing);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 展开状态
|
|
59
|
+
&&-open {
|
|
60
|
+
.aura-select-selector {
|
|
61
|
+
border-color: var(--aura-primary-700);
|
|
62
|
+
box-shadow: 0 0 0 2px var(--aura-primary-200);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.aura-select-arrow-icon {
|
|
66
|
+
transform: rotate(180deg);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 禁用状态
|
|
71
|
+
&&-disabled {
|
|
72
|
+
.aura-select-selector {
|
|
73
|
+
opacity: 0.5;
|
|
74
|
+
cursor: not-allowed;
|
|
75
|
+
background: var(--aura-bg-secondary);
|
|
76
|
+
|
|
77
|
+
&:hover {
|
|
78
|
+
border-color: var(--aura-border);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 占位文本
|
|
84
|
+
&-placeholder {
|
|
85
|
+
color: var(--aura-text-tertiary);
|
|
86
|
+
user-select: none;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 选中项显示
|
|
90
|
+
&-selection-item {
|
|
91
|
+
display: block;
|
|
92
|
+
overflow: hidden;
|
|
93
|
+
text-overflow: ellipsis;
|
|
94
|
+
white-space: nowrap;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 清除按钮
|
|
98
|
+
&-clear {
|
|
99
|
+
display: inline-flex;
|
|
100
|
+
align-items: center;
|
|
101
|
+
justify-content: center;
|
|
102
|
+
width: 16px;
|
|
103
|
+
height: 16px;
|
|
104
|
+
font-size: 14px;
|
|
105
|
+
line-height: 1;
|
|
106
|
+
cursor: pointer;
|
|
107
|
+
color: var(--aura-text-tertiary);
|
|
108
|
+
border-radius: var(--aura-radius-full);
|
|
109
|
+
|
|
110
|
+
&:hover {
|
|
111
|
+
color: var(--aura-text-secondary);
|
|
112
|
+
background: var(--aura-bg-tertiary);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 搜索输入框
|
|
117
|
+
&-search-input {
|
|
118
|
+
flex: 1;
|
|
119
|
+
border: none;
|
|
120
|
+
outline: none;
|
|
121
|
+
background: transparent;
|
|
122
|
+
font-size: inherit;
|
|
123
|
+
font-family: inherit;
|
|
124
|
+
color: var(--aura-text);
|
|
125
|
+
padding: 0;
|
|
126
|
+
line-height: inherit;
|
|
127
|
+
|
|
128
|
+
&::placeholder {
|
|
129
|
+
color: var(--aura-text-tertiary);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 多选标签
|
|
134
|
+
&-multiple &-selector {
|
|
135
|
+
flex-wrap: wrap;
|
|
136
|
+
gap: var(--aura-spacing-1);
|
|
137
|
+
padding: 4px 32px 4px 8px;
|
|
138
|
+
min-height: 38px;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
&-tags {
|
|
142
|
+
display: flex;
|
|
143
|
+
flex-wrap: wrap;
|
|
144
|
+
gap: var(--aura-spacing-1);
|
|
145
|
+
flex: 1;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
&-tag {
|
|
149
|
+
display: inline-flex;
|
|
150
|
+
align-items: center;
|
|
151
|
+
gap: 2px;
|
|
152
|
+
padding: 1px 6px;
|
|
153
|
+
font-size: var(--aura-font-size-xs);
|
|
154
|
+
line-height: 1.6;
|
|
155
|
+
background: var(--aura-primary-100);
|
|
156
|
+
color: var(--aura-primary-800);
|
|
157
|
+
border-radius: var(--aura-radius-sm);
|
|
158
|
+
user-select: none;
|
|
159
|
+
max-width: 100%;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
&-tag-close {
|
|
163
|
+
display: inline-flex;
|
|
164
|
+
align-items: center;
|
|
165
|
+
justify-content: center;
|
|
166
|
+
font-size: 12px;
|
|
167
|
+
cursor: pointer;
|
|
168
|
+
margin-left: 2px;
|
|
169
|
+
border-radius: var(--aura-radius-full);
|
|
170
|
+
|
|
171
|
+
&:hover {
|
|
172
|
+
color: var(--aura-primary-900);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// 下拉面板
|
|
177
|
+
&-dropdown {
|
|
178
|
+
position: absolute;
|
|
179
|
+
top: calc(100% + 4px);
|
|
180
|
+
left: 0;
|
|
181
|
+
width: 100%;
|
|
182
|
+
max-height: 256px;
|
|
183
|
+
overflow-y: auto;
|
|
184
|
+
background: var(--aura-bg);
|
|
185
|
+
border: 1px solid var(--aura-border);
|
|
186
|
+
border-radius: var(--aura-radius-md);
|
|
187
|
+
box-shadow: var(--aura-shadow-lg);
|
|
188
|
+
z-index: 1000;
|
|
189
|
+
padding: var(--aura-spacing-1) 0;
|
|
190
|
+
animation: aura-dropdown-in 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
|
191
|
+
transform-origin: top center;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// 选项
|
|
195
|
+
&-option {
|
|
196
|
+
display: flex;
|
|
197
|
+
align-items: center;
|
|
198
|
+
gap: var(--aura-spacing-2);
|
|
199
|
+
padding: 8px 12px;
|
|
200
|
+
font-size: var(--aura-font-size-md);
|
|
201
|
+
color: var(--aura-text);
|
|
202
|
+
cursor: pointer;
|
|
203
|
+
transition: all 0.15s var(--aura-easing);
|
|
204
|
+
|
|
205
|
+
&:hover,
|
|
206
|
+
&&-active {
|
|
207
|
+
background: var(--aura-bg-secondary);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
&&-selected {
|
|
211
|
+
color: var(--aura-primary-700);
|
|
212
|
+
font-weight: 500;
|
|
213
|
+
background: var(--aura-primary-50);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
&&-disabled {
|
|
217
|
+
opacity: 0.4;
|
|
218
|
+
cursor: not-allowed;
|
|
219
|
+
|
|
220
|
+
&:hover {
|
|
221
|
+
background: transparent;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
&-option-label {
|
|
227
|
+
flex: 1;
|
|
228
|
+
overflow: hidden;
|
|
229
|
+
text-overflow: ellipsis;
|
|
230
|
+
white-space: nowrap;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// 多选勾选框
|
|
234
|
+
&-option-checkbox {
|
|
235
|
+
display: inline-flex;
|
|
236
|
+
align-items: center;
|
|
237
|
+
justify-content: center;
|
|
238
|
+
width: 16px;
|
|
239
|
+
height: 16px;
|
|
240
|
+
border: 1px solid var(--aura-border);
|
|
241
|
+
border-radius: var(--aura-radius-sm);
|
|
242
|
+
flex-shrink: 0;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
&-option-check {
|
|
246
|
+
display: block;
|
|
247
|
+
width: 8px;
|
|
248
|
+
height: 8px;
|
|
249
|
+
background: var(--aura-primary-700);
|
|
250
|
+
border-radius: 2px;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// 单选对勾
|
|
254
|
+
&-option-tick {
|
|
255
|
+
display: inline-flex;
|
|
256
|
+
align-items: center;
|
|
257
|
+
justify-content: center;
|
|
258
|
+
width: 16px;
|
|
259
|
+
height: 16px;
|
|
260
|
+
|
|
261
|
+
&::after {
|
|
262
|
+
content: '';
|
|
263
|
+
display: block;
|
|
264
|
+
width: 6px;
|
|
265
|
+
height: 10px;
|
|
266
|
+
border: solid var(--aura-primary-700);
|
|
267
|
+
border-width: 0 2px 2px 0;
|
|
268
|
+
transform: rotate(45deg) translateY(-1px);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// 加载状态
|
|
273
|
+
&-loading {
|
|
274
|
+
display: flex;
|
|
275
|
+
align-items: center;
|
|
276
|
+
justify-content: center;
|
|
277
|
+
gap: var(--aura-spacing-2);
|
|
278
|
+
padding: var(--aura-spacing-4);
|
|
279
|
+
color: var(--aura-text-secondary);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
&-loading-icon {
|
|
283
|
+
display: inline-block;
|
|
284
|
+
width: 14px;
|
|
285
|
+
height: 14px;
|
|
286
|
+
border: 2px solid var(--aura-border);
|
|
287
|
+
border-right-color: transparent;
|
|
288
|
+
border-radius: 50%;
|
|
289
|
+
animation: aura-select-spin 0.6s linear infinite;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// 空状态
|
|
293
|
+
&-empty {
|
|
294
|
+
padding: var(--aura-spacing-4);
|
|
295
|
+
text-align: center;
|
|
296
|
+
color: var(--aura-text-tertiary);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Variants
|
|
300
|
+
&&-filled {
|
|
301
|
+
.aura-select-selector {
|
|
302
|
+
background: var(--aura-primary-50);
|
|
303
|
+
border: 2px solid transparent;
|
|
304
|
+
border-bottom-color: var(--aura-primary-200);
|
|
305
|
+
border-radius: var(--aura-radius-md);
|
|
306
|
+
box-shadow: none;
|
|
307
|
+
|
|
308
|
+
&:hover {
|
|
309
|
+
border-bottom-color: var(--aura-primary-400);
|
|
310
|
+
box-shadow: none;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
&:focus-visible {
|
|
314
|
+
box-shadow: none;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
&.aura-select-open .aura-select-selector {
|
|
319
|
+
border-bottom-color: var(--aura-primary-700);
|
|
320
|
+
box-shadow: none;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
&&-bordered {
|
|
325
|
+
.aura-select-selector {
|
|
326
|
+
border: 2px solid var(--aura-border);
|
|
327
|
+
border-radius: var(--aura-radius-lg);
|
|
328
|
+
|
|
329
|
+
&:hover {
|
|
330
|
+
border-color: var(--aura-primary-400);
|
|
331
|
+
box-shadow: 0 0 0 3px var(--aura-primary-100);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
&.aura-select-open .aura-select-selector {
|
|
336
|
+
border-color: var(--aura-primary-700);
|
|
337
|
+
box-shadow: 0 0 0 4px var(--aura-primary-100);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// Sizes
|
|
342
|
+
&&-sm {
|
|
343
|
+
.aura-select-selector {
|
|
344
|
+
padding: 4px 28px 4px 8px;
|
|
345
|
+
font-size: var(--aura-font-size-sm);
|
|
346
|
+
min-height: 30px;
|
|
347
|
+
border-radius: var(--aura-radius-sm);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
.aura-select-option {
|
|
351
|
+
padding: 6px 8px;
|
|
352
|
+
font-size: var(--aura-font-size-sm);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
&&-lg {
|
|
357
|
+
.aura-select-selector {
|
|
358
|
+
padding: 10px 36px 10px 14px;
|
|
359
|
+
font-size: var(--aura-font-size-lg);
|
|
360
|
+
min-height: 46px;
|
|
361
|
+
border-radius: var(--aura-radius-lg);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
.aura-select-option {
|
|
365
|
+
padding: 10px 14px;
|
|
366
|
+
font-size: var(--aura-font-size-lg);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
@keyframes aura-select-spin {
|
|
372
|
+
from { transform: rotate(0deg); }
|
|
373
|
+
to { transform: rotate(360deg); }
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// 暗色模式
|
|
377
|
+
[data-theme="dark"] {
|
|
378
|
+
.aura-select {
|
|
379
|
+
&-selector:focus-visible {
|
|
380
|
+
box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.2);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
&-tag {
|
|
384
|
+
background: rgba(124, 58, 237, 0.2);
|
|
385
|
+
color: var(--aura-primary-600);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
&-option-selected {
|
|
389
|
+
background: rgba(124, 58, 237, 0.1);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
.aura-select-filled {
|
|
394
|
+
.aura-select-selector {
|
|
395
|
+
background: rgba(124, 58, 237, 0.08);
|
|
396
|
+
border-bottom-color: rgba(124, 58, 237, 0.2);
|
|
397
|
+
|
|
398
|
+
&:hover {
|
|
399
|
+
border-bottom-color: var(--aura-primary-500);
|
|
400
|
+
box-shadow: none;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
&:focus-visible {
|
|
404
|
+
box-shadow: none;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
&.aura-select-open .aura-select-selector {
|
|
409
|
+
border-bottom-color: var(--aura-primary-400);
|
|
410
|
+
box-shadow: none;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
.aura-select-bordered {
|
|
415
|
+
.aura-select-selector {
|
|
416
|
+
&:hover {
|
|
417
|
+
border-color: var(--aura-primary-500);
|
|
418
|
+
box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
&.aura-select-open .aura-select-selector {
|
|
423
|
+
border-color: var(--aura-primary-400);
|
|
424
|
+
box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.15);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface SliderProps extends React.AriaAttributes {
|
|
3
|
+
/** 最小值
|
|
4
|
+
* @default 0
|
|
5
|
+
*/
|
|
6
|
+
min?: number;
|
|
7
|
+
/** 最大值
|
|
8
|
+
* @default 100
|
|
9
|
+
*/
|
|
10
|
+
max?: number;
|
|
11
|
+
/** 步长
|
|
12
|
+
* @default 1
|
|
13
|
+
*/
|
|
14
|
+
step?: number;
|
|
15
|
+
/** 当前值(受控) */
|
|
16
|
+
value?: number | [number, number];
|
|
17
|
+
/** 默认值(非受控)
|
|
18
|
+
* @default 0
|
|
19
|
+
*/
|
|
20
|
+
defaultValue?: number | [number, number];
|
|
21
|
+
/** 是否禁用 */
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
/** 标记 */
|
|
24
|
+
marks?: Record<number, React.ReactNode>;
|
|
25
|
+
/** 是否为范围滑块 */
|
|
26
|
+
range?: boolean;
|
|
27
|
+
/** 值变化回调(拖拽 / 点击 / 键盘调节过程中持续触发) */
|
|
28
|
+
onChange?: (value: number | [number, number]) => void;
|
|
29
|
+
/** 一次调节结束后的回调(松开拖拽、轨道点击、单次键盘调节) */
|
|
30
|
+
onChangeComplete?: (value: number | [number, number]) => void;
|
|
31
|
+
/** 自定义类名 */
|
|
32
|
+
className?: string;
|
|
33
|
+
/** 自定义样式 */
|
|
34
|
+
style?: React.CSSProperties;
|
|
35
|
+
}
|
|
36
|
+
export declare const Slider: React.ForwardRefExoticComponent<SliderProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -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';
|