@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,165 @@
1
+ import React, { forwardRef, createContext, useContext, useCallback, useState } from 'react';
2
+ import { classNames, prefixCls } from '@aura-react-comp/shared';
3
+ import { CheckOutline } from '@aura-react-comp/icons';
4
+ import "./index.less";
5
+
6
+ /* ===== Context ===== */
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ import { jsxs as _jsxs } from "react/jsx-runtime";
9
+ const StepsContext = /*#__PURE__*/createContext(null);
10
+ function useStepsContext() {
11
+ const ctx = useContext(StepsContext);
12
+ if (!ctx) throw new Error('Steps.Step 必须在 Steps 内部使用');
13
+ return ctx;
14
+ }
15
+
16
+ /* ===== Steps.Step ===== */
17
+
18
+ const Step = /*#__PURE__*/forwardRef(({
19
+ title,
20
+ subTitle,
21
+ status,
22
+ description,
23
+ icon,
24
+ disabled = false,
25
+ className,
26
+ style
27
+ }, ref) => {
28
+ const {
29
+ current,
30
+ variant,
31
+ onChange
32
+ } = useStepsContext();
33
+ const index = useContext(StepIndexContext);
34
+ const isCompleted = index < current;
35
+ const isCurrent = index === current;
36
+ const isError = status === 'error';
37
+ const handleClick = () => {
38
+ if (disabled) return;
39
+ onChange(index);
40
+ };
41
+ const handleKeyDown = e => {
42
+ if (e.key === 'Enter' || e.key === ' ') {
43
+ e.preventDefault();
44
+ handleClick();
45
+ }
46
+ };
47
+ const stepCls = classNames(prefixCls('steps-step'), isCompleted && prefixCls('steps-step-completed'), isCurrent && prefixCls('steps-step-active'), isError && prefixCls('steps-step-error'), disabled && prefixCls('steps-step-disabled'), className);
48
+
49
+ /* --- 渲染图标区域 --- */
50
+ const renderIcon = () => {
51
+ if (icon) return icon;
52
+ if (variant === 'dot') {
53
+ return /*#__PURE__*/_jsx("span", {
54
+ className: prefixCls('steps-dot-icon')
55
+ });
56
+ }
57
+
58
+ // default / navigation variant
59
+ if (isCompleted) {
60
+ return /*#__PURE__*/_jsx("span", {
61
+ className: prefixCls('steps-check'),
62
+ children: /*#__PURE__*/_jsx(CheckOutline, {
63
+ size: 14
64
+ })
65
+ });
66
+ }
67
+ return /*#__PURE__*/_jsx("span", {
68
+ className: prefixCls('steps-number'),
69
+ children: index + 1
70
+ });
71
+ };
72
+ return /*#__PURE__*/_jsx("div", {
73
+ ref: ref,
74
+ className: stepCls,
75
+ style: style,
76
+ role: "listitem",
77
+ "aria-current": isCurrent ? 'step' : undefined,
78
+ children: /*#__PURE__*/_jsxs("div", {
79
+ className: prefixCls('steps-step-header'),
80
+ onClick: handleClick,
81
+ onKeyDown: handleKeyDown,
82
+ tabIndex: disabled ? -1 : 0,
83
+ "aria-disabled": disabled,
84
+ children: [/*#__PURE__*/_jsx("div", {
85
+ className: classNames(prefixCls('steps-icon'), isCompleted && prefixCls('steps-icon-completed'), isCurrent && prefixCls('steps-icon-active')),
86
+ children: renderIcon()
87
+ }), /*#__PURE__*/_jsxs("div", {
88
+ className: prefixCls('steps-step-content'),
89
+ children: [/*#__PURE__*/_jsxs("div", {
90
+ className: prefixCls('steps-step-title'),
91
+ children: [title, subTitle && /*#__PURE__*/_jsx("span", {
92
+ className: prefixCls('steps-step-subtitle'),
93
+ children: subTitle
94
+ })]
95
+ }), description && /*#__PURE__*/_jsx("div", {
96
+ className: prefixCls('steps-step-description'),
97
+ children: description
98
+ })]
99
+ })]
100
+ })
101
+ });
102
+ });
103
+ Step.displayName = 'Steps.Step';
104
+
105
+ /* ===== StepIndexContext — 用于 Step 获取自己的 index ===== */
106
+ const StepIndexContext = /*#__PURE__*/React.createContext(0);
107
+
108
+ /* ===== Steps(主组件) ===== */
109
+
110
+ const StepsBase = /*#__PURE__*/forwardRef(({
111
+ current: controlledCurrent,
112
+ defaultCurrent = 0,
113
+ variant = 'default',
114
+ size = 'md',
115
+ direction = 'horizontal',
116
+ onChange,
117
+ className,
118
+ style,
119
+ children
120
+ }, ref) => {
121
+ const [internalCurrent, setInternalCurrent] = useState(defaultCurrent);
122
+ const isControlled = controlledCurrent !== undefined;
123
+ const current = isControlled ? controlledCurrent : internalCurrent;
124
+ const handleChange = useCallback(next => {
125
+ if (!isControlled) setInternalCurrent(next);
126
+ onChange?.(next);
127
+ }, [isControlled, onChange]);
128
+ const childArray = React.Children.toArray(children);
129
+ const totalSteps = childArray.length;
130
+ const ctxValue = {
131
+ current,
132
+ variant,
133
+ size,
134
+ direction,
135
+ onChange: handleChange,
136
+ totalSteps
137
+ };
138
+ const wrapperCls = classNames(prefixCls('steps'), prefixCls(`steps-${variant}`), prefixCls(`steps-${size}`), prefixCls(`steps-${direction}`), className);
139
+ return /*#__PURE__*/_jsx(StepsContext.Provider, {
140
+ value: ctxValue,
141
+ children: /*#__PURE__*/_jsx("div", {
142
+ ref: ref,
143
+ className: wrapperCls,
144
+ style: style,
145
+ role: "list",
146
+ "aria-label": "\u6B65\u9AA4\u6761",
147
+ children: childArray.map((child, index) => /*#__PURE__*/_jsx(StepIndexContext.Provider, {
148
+ value: index,
149
+ children: /*#__PURE__*/_jsxs("div", {
150
+ className: prefixCls('steps-step-container'),
151
+ children: [child, index < totalSteps - 1 && /*#__PURE__*/_jsx("div", {
152
+ className: classNames(prefixCls('steps-tail'), index < current ? prefixCls('steps-tail-completed') : prefixCls('steps-tail-pending'))
153
+ })]
154
+ })
155
+ }, index))
156
+ })
157
+ });
158
+ });
159
+ StepsBase.displayName = 'Steps';
160
+
161
+ /* ===== 复合组件导出 ===== */
162
+
163
+ const Steps = StepsBase;
164
+ Steps.Step = Step;
165
+ export { Steps };
@@ -0,0 +1,394 @@
1
+ /* ===== Steps 组件样式 ===== */
2
+
3
+ .aura-steps {
4
+ display: flex;
5
+ align-items: flex-start;
6
+
7
+ /* ===== Direction: horizontal ===== */
8
+ &&-horizontal {
9
+ flex-direction: row;
10
+
11
+ .aura-steps-step-container {
12
+ flex: 1;
13
+ display: flex;
14
+ flex-direction: row;
15
+ align-items: flex-start;
16
+ position: relative;
17
+ }
18
+
19
+ .aura-steps-step {
20
+ flex: 1;
21
+ display: flex;
22
+ flex-direction: column;
23
+ align-items: center;
24
+ }
25
+
26
+ .aura-steps-step-header {
27
+ display: flex;
28
+ flex-direction: column;
29
+ align-items: center;
30
+ cursor: pointer;
31
+ text-align: center;
32
+ width: 100%;
33
+ }
34
+
35
+ .aura-steps-tail {
36
+ position: absolute;
37
+ top: 16px;
38
+ left: calc(50% + 20px);
39
+ right: calc(-50% + 20px);
40
+ height: 2px;
41
+ background: var(--aura-border);
42
+ transition: background var(--aura-duration-normal)
43
+ cubic-bezier(0.4, 0, 0.2, 1);
44
+
45
+ &-completed {
46
+ background: var(--aura-primary-600);
47
+ }
48
+
49
+ &-pending {
50
+ background: var(--aura-border);
51
+ }
52
+ }
53
+ }
54
+
55
+ /* ===== Direction: vertical ===== */
56
+ &&-vertical {
57
+ flex-direction: column;
58
+
59
+ .aura-steps-step-container {
60
+ display: flex;
61
+ flex-direction: column;
62
+ position: relative;
63
+ padding-bottom: var(--aura-spacing-4);
64
+ }
65
+
66
+ .aura-steps-step-header {
67
+ display: flex;
68
+ flex-direction: row;
69
+ align-items: flex-start;
70
+ cursor: pointer;
71
+ gap: var(--aura-spacing-3);
72
+ }
73
+
74
+ .aura-steps-tail {
75
+ position: absolute;
76
+ top: 32px;
77
+ left: 15px;
78
+ width: 2px;
79
+ bottom: var(--aura-spacing-4);
80
+ background: var(--aura-border);
81
+ transition: background var(--aura-duration-normal)
82
+ cubic-bezier(0.4, 0, 0.2, 1);
83
+
84
+ &-completed {
85
+ background: var(--aura-primary-600);
86
+ }
87
+
88
+ &-pending {
89
+ background: var(--aura-border);
90
+ }
91
+ }
92
+ }
93
+
94
+ /* ===== Size: sm ===== */
95
+ &&-sm {
96
+ .aura-steps-icon {
97
+ width: 24px;
98
+ height: 24px;
99
+ font-size: var(--aura-font-size-xs);
100
+ }
101
+
102
+ .aura-steps-step-title {
103
+ font-size: var(--aura-font-size-sm);
104
+ }
105
+
106
+ .aura-steps-step-description {
107
+ font-size: var(--aura-font-size-xs);
108
+ }
109
+
110
+ .aura-steps-dot-icon {
111
+ width: 8px;
112
+ height: 8px;
113
+ }
114
+ }
115
+ }
116
+
117
+ /* ===== Step Container ===== */
118
+ .aura-steps-step-container {
119
+ &:last-child {
120
+ .aura-steps-tail {
121
+ display: none;
122
+ }
123
+ }
124
+ }
125
+
126
+ /* ===== Step ===== */
127
+ .aura-steps-step {
128
+ transition: all var(--aura-duration-normal) cubic-bezier(0.4, 0, 0.2, 1);
129
+
130
+ &-disabled {
131
+ opacity: 0.5;
132
+ cursor: not-allowed;
133
+
134
+ .aura-steps-step-header {
135
+ cursor: not-allowed;
136
+ }
137
+ }
138
+ }
139
+
140
+ .aura-steps-step-header {
141
+ outline: none;
142
+
143
+ &:focus-visible {
144
+ .aura-steps-icon {
145
+ outline: 2px solid var(--aura-primary-500);
146
+ outline-offset: 2px;
147
+ }
148
+ }
149
+ }
150
+
151
+ .aura-steps-step-content {
152
+ margin-top: var(--aura-spacing-2);
153
+ text-align: center;
154
+ }
155
+
156
+ .aura-steps-step-title {
157
+ font-size: var(--aura-font-size-md);
158
+ font-weight: 500;
159
+ color: var(--aura-text);
160
+ line-height: 1.4;
161
+ }
162
+
163
+ .aura-steps-step-description {
164
+ font-size: var(--aura-font-size-sm);
165
+ color: var(--aura-text-secondary);
166
+ margin-top: 2px;
167
+ line-height: 1.4;
168
+ }
169
+
170
+ /* ===== Icon ===== */
171
+ .aura-steps-icon {
172
+ display: inline-flex;
173
+ align-items: center;
174
+ justify-content: center;
175
+ width: 32px;
176
+ height: 32px;
177
+ border-radius: var(--aura-radius-full);
178
+ font-size: var(--aura-font-size-sm);
179
+ font-weight: 600;
180
+ color: var(--aura-text-secondary);
181
+ background: var(--aura-bg-secondary);
182
+ border: 2px solid var(--aura-border);
183
+ transition: all var(--aura-duration-normal) cubic-bezier(0.34, 1.56, 0.64, 1);
184
+
185
+ &-completed {
186
+ color: var(--aura-text-inverse);
187
+ background: var(--aura-primary-600);
188
+ border-color: var(--aura-primary-600);
189
+ }
190
+
191
+ &-active {
192
+ color: var(--aura-primary-700);
193
+ border-color: var(--aura-primary-600);
194
+ background: var(--aura-primary-50);
195
+ box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
196
+ }
197
+ }
198
+
199
+ .aura-steps-number {
200
+ line-height: 1;
201
+ }
202
+
203
+ .aura-steps-check {
204
+ display: inline-flex;
205
+ align-items: center;
206
+ justify-content: center;
207
+ line-height: 1;
208
+ }
209
+
210
+ /* ===== Variant: dot ===== */
211
+ .aura-steps-dot {
212
+ .aura-steps-icon {
213
+ width: auto;
214
+ height: auto;
215
+ background: transparent;
216
+ border: none;
217
+ }
218
+
219
+ .aura-steps-dot-icon {
220
+ display: inline-block;
221
+ width: 10px;
222
+ height: 10px;
223
+ border-radius: var(--aura-radius-full);
224
+ background: var(--aura-border);
225
+ transition: all var(--aura-duration-normal)
226
+ cubic-bezier(0.34, 1.56, 0.64, 1);
227
+ }
228
+
229
+ .aura-steps-icon-active .aura-steps-dot-icon {
230
+ background: var(--aura-primary-600);
231
+ box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
232
+ }
233
+
234
+ .aura-steps-icon-completed .aura-steps-dot-icon {
235
+ background: var(--aura-primary-600);
236
+ }
237
+ }
238
+
239
+ /* ===== Variant: navigation ===== */
240
+ .aura-steps-navigation {
241
+ .aura-steps-step-container {
242
+ position: relative;
243
+ }
244
+
245
+ .aura-steps-step-active {
246
+ .aura-steps-step-title {
247
+ color: var(--aura-primary-700);
248
+ font-weight: 600;
249
+ }
250
+ }
251
+
252
+ .aura-steps-step-completed {
253
+ .aura-steps-step-title {
254
+ color: var(--aura-text-secondary);
255
+ }
256
+ }
257
+
258
+ /* 底部横线 */
259
+ .aura-steps-tail {
260
+ height: 3px;
261
+ border-radius: 2px;
262
+ top: auto;
263
+ bottom: 0;
264
+ left: 0;
265
+ right: 0;
266
+
267
+ &-completed {
268
+ background: var(--aura-primary-600);
269
+ }
270
+ }
271
+
272
+ .aura-steps-step {
273
+ padding-bottom: var(--aura-spacing-2);
274
+ position: relative;
275
+
276
+ &::after {
277
+ content: '';
278
+ position: absolute;
279
+ bottom: 0;
280
+ left: 0;
281
+ right: 0;
282
+ height: 3px;
283
+ background: var(--aura-border);
284
+ border-radius: 2px;
285
+ transition: background var(--aura-duration-normal)
286
+ cubic-bezier(0.4, 0, 0.2, 1);
287
+ }
288
+
289
+ &-active::after {
290
+ background: var(--aura-primary-600);
291
+ }
292
+
293
+ &-completed::after {
294
+ background: var(--aura-primary-600);
295
+ }
296
+ }
297
+
298
+ .aura-steps-tail {
299
+ display: none;
300
+ }
301
+ }
302
+
303
+ /* ===== vertical 模式下 steps-step-content 对齐 ===== */
304
+ .aura-steps-vertical {
305
+ .aura-steps-step-content {
306
+ text-align: left;
307
+ margin-top: 0;
308
+ }
309
+ }
310
+
311
+ /* ===== 暗色模式 ===== */
312
+ [data-theme='dark'] {
313
+ .aura-steps-icon {
314
+ color: var(--aura-text-secondary);
315
+ background: var(--aura-bg-tertiary);
316
+ border-color: var(--aura-border);
317
+
318
+ &-completed {
319
+ color: var(--aura-text-inverse);
320
+ background: var(--aura-primary-600);
321
+ border-color: var(--aura-primary-600);
322
+ }
323
+
324
+ &-active {
325
+ color: var(--aura-primary-400);
326
+ border-color: var(--aura-primary-500);
327
+ background: rgba(124, 58, 237, 0.1);
328
+ box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
329
+ }
330
+ }
331
+
332
+ .aura-steps-step-title {
333
+ color: var(--aura-text);
334
+ }
335
+
336
+ .aura-steps-step-description {
337
+ color: var(--aura-text-tertiary);
338
+ }
339
+
340
+ .aura-steps-tail-pending {
341
+ background: var(--aura-border);
342
+ }
343
+
344
+ .aura-steps-navigation {
345
+ .aura-steps-step-active {
346
+ .aura-steps-step-title {
347
+ color: var(--aura-primary-400);
348
+ }
349
+ }
350
+
351
+ .aura-steps-step::after {
352
+ background: var(--aura-border);
353
+ }
354
+
355
+ .aura-steps-step-active::after,
356
+ .aura-steps-step-completed::after {
357
+ background: var(--aura-primary-500);
358
+ }
359
+ }
360
+
361
+ .aura-steps-dot {
362
+ .aura-steps-dot-icon {
363
+ background: var(--aura-border);
364
+ }
365
+
366
+ .aura-steps-icon-active .aura-steps-dot-icon {
367
+ background: var(--aura-primary-500);
368
+ }
369
+
370
+ .aura-steps-icon-completed .aura-steps-dot-icon {
371
+ background: var(--aura-primary-500);
372
+ }
373
+ }
374
+ }
375
+
376
+ /* ===== 出错态 ===== */
377
+ .aura-steps-step-error {
378
+ .aura-steps-icon {
379
+ border-color: var(--aura-error);
380
+ color: var(--aura-error);
381
+ }
382
+
383
+ .aura-steps-step-title {
384
+ color: var(--aura-error);
385
+ }
386
+ }
387
+
388
+ /* ===== 副标题 ===== */
389
+ .aura-steps-step-subtitle {
390
+ margin-left: var(--aura-spacing-2);
391
+ font-size: var(--aura-font-size-sm);
392
+ font-weight: 400;
393
+ color: var(--aura-text-tertiary);
394
+ }
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ /**
3
+ * Switch 的可访问性依赖调用方通过 `aria-label` / `aria-labelledby` 提供名称,
4
+ * 因此这里继承 button 的原生属性并向下转发(`onChange` 因签名不同而排除)。
5
+ */
6
+ export interface SwitchProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'onChange'> {
7
+ /** 开关尺寸
8
+ * @default 'md'
9
+ */
10
+ size?: 'sm' | 'md' | 'lg';
11
+ /** 是否禁用 */
12
+ disabled?: boolean;
13
+ /** 是否加载中 */
14
+ loading?: boolean;
15
+ /** 是否选中(受控) */
16
+ checked?: boolean;
17
+ /** 默认是否选中 */
18
+ defaultChecked?: boolean;
19
+ /** 选中时显示的内容 */
20
+ checkedChildren?: React.ReactNode;
21
+ /** 未选中时显示的内容 */
22
+ unCheckedChildren?: React.ReactNode;
23
+ /** 切换回调 */
24
+ onChange?: (checked: boolean) => void;
25
+ /** 自定义类名 */
26
+ className?: string;
27
+ /** 自定义样式 */
28
+ style?: React.CSSProperties;
29
+ }
30
+ export declare const Switch: React.ForwardRefExoticComponent<SwitchProps & React.RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,56 @@
1
+ import React, { forwardRef, useState, useCallback } from 'react';
2
+ import { classNames, prefixCls } from '@aura-react-comp/shared';
3
+ import "./index.less";
4
+
5
+ /**
6
+ * Switch 的可访问性依赖调用方通过 `aria-label` / `aria-labelledby` 提供名称,
7
+ * 因此这里继承 button 的原生属性并向下转发(`onChange` 因签名不同而排除)。
8
+ */
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ import { jsxs as _jsxs } from "react/jsx-runtime";
11
+ export const Switch = /*#__PURE__*/forwardRef(({
12
+ size = 'md',
13
+ disabled = false,
14
+ loading = false,
15
+ checked: controlledChecked,
16
+ defaultChecked = false,
17
+ checkedChildren,
18
+ unCheckedChildren,
19
+ onChange,
20
+ className,
21
+ style,
22
+ ...rest
23
+ }, ref) => {
24
+ const isControlled = controlledChecked !== undefined;
25
+ const [internalChecked, setInternalChecked] = useState(defaultChecked);
26
+ const checked = isControlled ? controlledChecked : internalChecked;
27
+ const handleClick = useCallback(() => {
28
+ if (disabled || loading) return;
29
+ if (!isControlled) {
30
+ setInternalChecked(!checked);
31
+ }
32
+ onChange?.(!checked);
33
+ }, [checked, disabled, loading, isControlled, onChange]);
34
+ const cls = classNames(prefixCls('switch'), prefixCls(`switch-${size}`), checked && prefixCls('switch-checked'), disabled && prefixCls('switch-disabled'), loading && prefixCls('switch-loading'), className);
35
+ return /*#__PURE__*/_jsxs("button", {
36
+ ref: ref,
37
+ type: "button",
38
+ ...rest,
39
+ role: "switch",
40
+ "aria-checked": checked,
41
+ className: cls,
42
+ style: style,
43
+ onClick: handleClick,
44
+ disabled: disabled,
45
+ children: [/*#__PURE__*/_jsx("span", {
46
+ className: prefixCls('switch-inner'),
47
+ children: checked ? checkedChildren : unCheckedChildren
48
+ }), /*#__PURE__*/_jsx("span", {
49
+ className: prefixCls('switch-handle'),
50
+ children: loading && /*#__PURE__*/_jsx("span", {
51
+ className: prefixCls('switch-loading-icon')
52
+ })
53
+ })]
54
+ });
55
+ });
56
+ Switch.displayName = 'Switch';