@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.
- 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 +163 -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 +107 -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 +175 -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 +247 -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 +258 -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 +118 -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 +182 -0
- package/esm/pagination/index.less +230 -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 +155 -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 +104 -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 +471 -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 +179 -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 +160 -0
- package/esm/tabs/index.d.ts +45 -0
- package/esm/tabs/index.js +170 -0
- package/esm/tabs/index.less +228 -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 +226 -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 +107 -0
- package/esm/upload/index.d.ts +68 -0
- package/esm/upload/index.js +447 -0
- package/esm/upload/index.less +376 -0
- package/esm/upload/request.d.ts +26 -0
- package/esm/upload/request.js +38 -0
- package/package.json +56 -3
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import React, { forwardRef, createContext, useContext, useState } from 'react';
|
|
2
|
+
import { classNames, prefixCls } from '@aura-react-comp/shared';
|
|
3
|
+
import "./index.less";
|
|
4
|
+
|
|
5
|
+
/* ===== Radio Context(用于 Radio.Group) ===== */
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
+
const RadioGroupContext = /*#__PURE__*/createContext(null);
|
|
9
|
+
|
|
10
|
+
/* ===== Radio ===== */
|
|
11
|
+
|
|
12
|
+
export const Radio = /*#__PURE__*/forwardRef(({
|
|
13
|
+
size,
|
|
14
|
+
disabled,
|
|
15
|
+
checked: controlledChecked,
|
|
16
|
+
onChange: controlledOnChange,
|
|
17
|
+
className,
|
|
18
|
+
children,
|
|
19
|
+
value,
|
|
20
|
+
...rest
|
|
21
|
+
}, ref) => {
|
|
22
|
+
// 尝试从 Group context 获取
|
|
23
|
+
const groupCtx = useContext(RadioGroupContext);
|
|
24
|
+
const isDisabled = disabled ?? groupCtx?.disabled;
|
|
25
|
+
const resolvedSize = size ?? groupCtx?.size ?? 'md';
|
|
26
|
+
|
|
27
|
+
// 受控:group > 单独 controlled > 非受控
|
|
28
|
+
let isChecked;
|
|
29
|
+
let handleChange;
|
|
30
|
+
if (groupCtx) {
|
|
31
|
+
// Group 模式
|
|
32
|
+
const val = value;
|
|
33
|
+
isChecked = groupCtx.value === val;
|
|
34
|
+
handleChange = () => {
|
|
35
|
+
groupCtx.onChange(val);
|
|
36
|
+
};
|
|
37
|
+
} else {
|
|
38
|
+
// 单独 Radio 模式
|
|
39
|
+
isChecked = !!controlledChecked;
|
|
40
|
+
handleChange = controlledOnChange;
|
|
41
|
+
}
|
|
42
|
+
const cls = classNames(prefixCls('radio'), prefixCls(`radio-${resolvedSize}`), isChecked && prefixCls('radio-checked'), isDisabled && prefixCls('radio-disabled'), className);
|
|
43
|
+
|
|
44
|
+
// 在 Group 模式下,通过 label onClick 确保点击已选中项也能触发回调
|
|
45
|
+
// 因为 React 受控 radio 在 checked=true 时不会触发 input 的 onChange
|
|
46
|
+
const handleLabelClick = groupCtx ? () => {
|
|
47
|
+
if (!isDisabled) {
|
|
48
|
+
groupCtx.onChange(value);
|
|
49
|
+
}
|
|
50
|
+
} : undefined;
|
|
51
|
+
return /*#__PURE__*/_jsxs("label", {
|
|
52
|
+
className: cls,
|
|
53
|
+
onClick: handleLabelClick,
|
|
54
|
+
children: [/*#__PURE__*/_jsxs("span", {
|
|
55
|
+
className: prefixCls('radio-input-wrapper'),
|
|
56
|
+
children: [/*#__PURE__*/_jsx("input", {
|
|
57
|
+
ref: ref,
|
|
58
|
+
type: "radio",
|
|
59
|
+
className: prefixCls('radio-input'),
|
|
60
|
+
checked: isChecked,
|
|
61
|
+
disabled: isDisabled,
|
|
62
|
+
onChange: handleChange,
|
|
63
|
+
value: value,
|
|
64
|
+
onClick: e => {
|
|
65
|
+
// 阻止 input 的默认 click 事件冒泡到 label 的 onClick,
|
|
66
|
+
// 避免 Group 模式下重复触发
|
|
67
|
+
if (groupCtx) {
|
|
68
|
+
e.stopPropagation();
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
...rest
|
|
72
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
73
|
+
className: prefixCls('radio-inner')
|
|
74
|
+
})]
|
|
75
|
+
}), children !== undefined && /*#__PURE__*/_jsx("span", {
|
|
76
|
+
className: prefixCls('radio-label'),
|
|
77
|
+
children: children
|
|
78
|
+
})]
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
Radio.displayName = 'Radio';
|
|
82
|
+
|
|
83
|
+
/* ===== Radio.Group ===== */
|
|
84
|
+
|
|
85
|
+
export const RadioGroup = ({
|
|
86
|
+
value: controlledValue,
|
|
87
|
+
defaultValue,
|
|
88
|
+
options,
|
|
89
|
+
onChange,
|
|
90
|
+
direction = 'horizontal',
|
|
91
|
+
disabled = false,
|
|
92
|
+
size,
|
|
93
|
+
className
|
|
94
|
+
}) => {
|
|
95
|
+
const [internalValue, setInternalValue] = useState(defaultValue ?? '');
|
|
96
|
+
const currentValue = controlledValue ?? internalValue;
|
|
97
|
+
const handleChange = nextValue => {
|
|
98
|
+
if (controlledValue === undefined) {
|
|
99
|
+
setInternalValue(nextValue);
|
|
100
|
+
}
|
|
101
|
+
onChange?.(nextValue);
|
|
102
|
+
};
|
|
103
|
+
const ctx = {
|
|
104
|
+
value: currentValue,
|
|
105
|
+
onChange: handleChange,
|
|
106
|
+
disabled,
|
|
107
|
+
size
|
|
108
|
+
};
|
|
109
|
+
const cls = classNames(prefixCls('radio-group'), prefixCls(`radio-group-${direction}`), className);
|
|
110
|
+
return /*#__PURE__*/_jsx(RadioGroupContext.Provider, {
|
|
111
|
+
value: ctx,
|
|
112
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
113
|
+
className: cls,
|
|
114
|
+
children: options.map(opt => /*#__PURE__*/_jsx(Radio, {
|
|
115
|
+
value: opt.value,
|
|
116
|
+
disabled: opt.disabled,
|
|
117
|
+
children: opt.label
|
|
118
|
+
}, opt.value))
|
|
119
|
+
})
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
RadioGroup.displayName = 'RadioGroup';
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
.aura-radio {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
gap: var(--aura-spacing-2);
|
|
5
|
+
cursor: pointer;
|
|
6
|
+
user-select: none;
|
|
7
|
+
font-size: var(--aura-font-size-md);
|
|
8
|
+
color: var(--aura-text);
|
|
9
|
+
line-height: 1.5;
|
|
10
|
+
|
|
11
|
+
// 隐藏原生 input
|
|
12
|
+
&-input {
|
|
13
|
+
position: absolute;
|
|
14
|
+
width: 0;
|
|
15
|
+
height: 0;
|
|
16
|
+
opacity: 0;
|
|
17
|
+
margin: 0;
|
|
18
|
+
padding: 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&-input-wrapper {
|
|
22
|
+
position: relative;
|
|
23
|
+
display: inline-flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: center;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 自定义 radio 外观
|
|
29
|
+
&-inner {
|
|
30
|
+
display: inline-block;
|
|
31
|
+
width: 16px;
|
|
32
|
+
height: 16px;
|
|
33
|
+
border: 1.5px solid var(--aura-border);
|
|
34
|
+
border-radius: var(--aura-radius-full);
|
|
35
|
+
background: var(--aura-bg);
|
|
36
|
+
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
|
37
|
+
position: relative;
|
|
38
|
+
flex-shrink: 0;
|
|
39
|
+
|
|
40
|
+
// 选中状态的紫色圆点
|
|
41
|
+
&::after {
|
|
42
|
+
content: '';
|
|
43
|
+
position: absolute;
|
|
44
|
+
display: block;
|
|
45
|
+
top: 50%;
|
|
46
|
+
left: 50%;
|
|
47
|
+
width: 8px;
|
|
48
|
+
height: 8px;
|
|
49
|
+
background: var(--aura-primary-700);
|
|
50
|
+
border-radius: var(--aura-radius-full);
|
|
51
|
+
transform: translate(-50%, -50%) scale(0);
|
|
52
|
+
transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
|
|
53
|
+
opacity: 0;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 选中状态
|
|
58
|
+
&&-checked {
|
|
59
|
+
.aura-radio-inner {
|
|
60
|
+
border-color: var(--aura-primary-700);
|
|
61
|
+
|
|
62
|
+
&::after {
|
|
63
|
+
transform: translate(-50%, -50%) scale(1);
|
|
64
|
+
opacity: 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// hover
|
|
70
|
+
&:hover .aura-radio-inner {
|
|
71
|
+
border-color: var(--aura-primary-700);
|
|
72
|
+
box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.08);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// focus
|
|
76
|
+
&-input:focus-visible + .aura-radio-inner {
|
|
77
|
+
box-shadow: 0 0 0 2px var(--aura-primary-200);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 禁用状态
|
|
81
|
+
&&-disabled {
|
|
82
|
+
opacity: 0.5;
|
|
83
|
+
cursor: not-allowed;
|
|
84
|
+
&:hover .aura-radio-inner {
|
|
85
|
+
border-color: var(--aura-border);
|
|
86
|
+
box-shadow: none;
|
|
87
|
+
}
|
|
88
|
+
&.aura-radio-checked .aura-radio-inner {
|
|
89
|
+
border-color: var(--aura-border);
|
|
90
|
+
}
|
|
91
|
+
.aura-radio-inner::after {
|
|
92
|
+
background: var(--aura-text-tertiary);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 标签文本
|
|
97
|
+
&-label {
|
|
98
|
+
font-size: inherit;
|
|
99
|
+
line-height: inherit;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 尺寸
|
|
103
|
+
&&-sm {
|
|
104
|
+
font-size: var(--aura-font-size-sm);
|
|
105
|
+
.aura-radio-inner {
|
|
106
|
+
width: 14px;
|
|
107
|
+
height: 14px;
|
|
108
|
+
&::after {
|
|
109
|
+
width: 6px;
|
|
110
|
+
height: 6px;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
&&-lg {
|
|
116
|
+
font-size: var(--aura-font-size-lg);
|
|
117
|
+
.aura-radio-inner {
|
|
118
|
+
width: 18px;
|
|
119
|
+
height: 18px;
|
|
120
|
+
&::after {
|
|
121
|
+
width: 10px;
|
|
122
|
+
height: 10px;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/* ===== Radio.Group ===== */
|
|
129
|
+
.aura-radio-group {
|
|
130
|
+
display: flex;
|
|
131
|
+
gap: var(--aura-spacing-3);
|
|
132
|
+
&&-horizontal {
|
|
133
|
+
flex-direction: row;
|
|
134
|
+
flex-wrap: wrap;
|
|
135
|
+
align-items: center;
|
|
136
|
+
}
|
|
137
|
+
&&-vertical {
|
|
138
|
+
flex-direction: column;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// 暗色模式
|
|
143
|
+
[data-theme='dark'] {
|
|
144
|
+
.aura-radio {
|
|
145
|
+
&-inner {
|
|
146
|
+
border-color: rgba(139, 92, 246, 0.3);
|
|
147
|
+
}
|
|
148
|
+
&:hover .aura-radio-inner {
|
|
149
|
+
border-color: var(--aura-primary-600);
|
|
150
|
+
}
|
|
151
|
+
&-input:focus-visible + .aura-radio-inner {
|
|
152
|
+
box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.2);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface RateProps {
|
|
3
|
+
/** 星星数量
|
|
4
|
+
* @default 5
|
|
5
|
+
*/
|
|
6
|
+
count?: number;
|
|
7
|
+
/** 当前值(受控) */
|
|
8
|
+
value?: number;
|
|
9
|
+
/** 默认值(非受控)
|
|
10
|
+
* @default 0
|
|
11
|
+
*/
|
|
12
|
+
defaultValue?: number;
|
|
13
|
+
/** 是否允许半星 */
|
|
14
|
+
allowHalf?: boolean;
|
|
15
|
+
/** 是否允许清除(再次点击当前值清零) */
|
|
16
|
+
allowClear?: boolean;
|
|
17
|
+
/** 是否禁用 */
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
/** 星星大小
|
|
20
|
+
* @default 'md'
|
|
21
|
+
*/
|
|
22
|
+
size?: 'sm' | 'md' | 'lg';
|
|
23
|
+
/** 值变化回调 */
|
|
24
|
+
onChange?: (value: number) => void;
|
|
25
|
+
/** 自定义类名 */
|
|
26
|
+
className?: string;
|
|
27
|
+
/** 自定义样式 */
|
|
28
|
+
style?: React.CSSProperties;
|
|
29
|
+
}
|
|
30
|
+
export declare const Rate: React.ForwardRefExoticComponent<RateProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import React, { forwardRef, useState, useCallback, useRef } from 'react';
|
|
2
|
+
import { classNames, prefixCls } from '@aura-react-comp/shared';
|
|
3
|
+
import { StarFilled, StarEmpty, StarHalf } from '@aura-react-comp/icons';
|
|
4
|
+
import "./index.less";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
/** 星星图标组件 */
|
|
7
|
+
const StarIcon = ({
|
|
8
|
+
filled,
|
|
9
|
+
half
|
|
10
|
+
}) => {
|
|
11
|
+
if (filled && !half) return /*#__PURE__*/_jsx(StarFilled, {
|
|
12
|
+
size: 24
|
|
13
|
+
});
|
|
14
|
+
if (half) return /*#__PURE__*/_jsx(StarHalf, {
|
|
15
|
+
size: 24,
|
|
16
|
+
half: half
|
|
17
|
+
});
|
|
18
|
+
return /*#__PURE__*/_jsx(StarEmpty, {
|
|
19
|
+
size: 24
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
export const Rate = /*#__PURE__*/forwardRef(({
|
|
23
|
+
count = 5,
|
|
24
|
+
value: controlledValue,
|
|
25
|
+
defaultValue = 0,
|
|
26
|
+
allowHalf = false,
|
|
27
|
+
allowClear = false,
|
|
28
|
+
disabled = false,
|
|
29
|
+
size = 'md',
|
|
30
|
+
onChange,
|
|
31
|
+
className,
|
|
32
|
+
style
|
|
33
|
+
}, ref) => {
|
|
34
|
+
// 内部维护的值(非受控模式)
|
|
35
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
36
|
+
// hover 预览值
|
|
37
|
+
const [hoverValue, setHoverValue] = useState(null);
|
|
38
|
+
|
|
39
|
+
// 当前生效的值
|
|
40
|
+
const currentValue = controlledValue ?? internalValue;
|
|
41
|
+
// 显示值(优先 hover)
|
|
42
|
+
const displayValue = hoverValue ?? currentValue;
|
|
43
|
+
|
|
44
|
+
// 单个星星容器引用,用于判断半星区域
|
|
45
|
+
const starRefs = useRef([]);
|
|
46
|
+
|
|
47
|
+
// 根据鼠标位置计算星级值
|
|
48
|
+
const getValueFromEvent = useCallback((e, index) => {
|
|
49
|
+
if (!allowHalf || !starRefs.current[index]) {
|
|
50
|
+
return index + 1;
|
|
51
|
+
}
|
|
52
|
+
const rect = starRefs.current[index].getBoundingClientRect();
|
|
53
|
+
const isLeftHalf = e.clientX - rect.left < rect.width / 2;
|
|
54
|
+
return isLeftHalf ? index + 0.5 : index + 1;
|
|
55
|
+
}, [allowHalf]);
|
|
56
|
+
|
|
57
|
+
// 鼠标移入
|
|
58
|
+
const handleMouseMove = useCallback((e, index) => {
|
|
59
|
+
if (disabled) return;
|
|
60
|
+
setHoverValue(getValueFromEvent(e, index));
|
|
61
|
+
}, [disabled, getValueFromEvent]);
|
|
62
|
+
|
|
63
|
+
// 鼠标移出
|
|
64
|
+
const handleMouseLeave = useCallback(() => {
|
|
65
|
+
if (disabled) return;
|
|
66
|
+
setHoverValue(null);
|
|
67
|
+
}, [disabled]);
|
|
68
|
+
|
|
69
|
+
// 点击选择
|
|
70
|
+
const handleClick = useCallback((e, index) => {
|
|
71
|
+
if (disabled) return;
|
|
72
|
+
const newValue = getValueFromEvent(e, index);
|
|
73
|
+
|
|
74
|
+
// allowClear: 再次点击当前值清零
|
|
75
|
+
if (allowClear && newValue === currentValue) {
|
|
76
|
+
if (controlledValue === undefined) {
|
|
77
|
+
setInternalValue(0);
|
|
78
|
+
}
|
|
79
|
+
onChange?.(0);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (controlledValue === undefined) {
|
|
83
|
+
setInternalValue(newValue);
|
|
84
|
+
}
|
|
85
|
+
onChange?.(newValue);
|
|
86
|
+
}, [disabled, getValueFromEvent, allowClear, currentValue, controlledValue, onChange]);
|
|
87
|
+
const cls = classNames(prefixCls('rate'), prefixCls(`rate-${size}`), disabled && prefixCls('rate-disabled'), className);
|
|
88
|
+
|
|
89
|
+
// 渲染单个星星
|
|
90
|
+
const renderStar = index => {
|
|
91
|
+
const starValue = index + 1;
|
|
92
|
+
const isFilled = displayValue >= starValue;
|
|
93
|
+
const isHalfLeft = allowHalf && !isFilled && displayValue >= starValue - 0.5 && displayValue < starValue;
|
|
94
|
+
// 当使用半星预览时,如果 displayValue 是半星(如 2.5),当前星是第3颗
|
|
95
|
+
// 第2颗星完全填充,第3颗星的左半填充
|
|
96
|
+
const isHalfFilledLeft = allowHalf && isFilled === false && Math.ceil(displayValue) === starValue && displayValue % 1 !== 0;
|
|
97
|
+
let filled = isFilled;
|
|
98
|
+
let half;
|
|
99
|
+
if (isHalfFilledLeft) {
|
|
100
|
+
filled = true;
|
|
101
|
+
half = 'left';
|
|
102
|
+
} else if (isHalfLeft) {
|
|
103
|
+
filled = false;
|
|
104
|
+
half = 'left';
|
|
105
|
+
}
|
|
106
|
+
const starCls = classNames(prefixCls('rate-star'), filled && prefixCls('rate-star-filled'), half && prefixCls('rate-star-half'));
|
|
107
|
+
return /*#__PURE__*/_jsx("span", {
|
|
108
|
+
ref: el => {
|
|
109
|
+
starRefs.current[index] = el;
|
|
110
|
+
},
|
|
111
|
+
className: starCls,
|
|
112
|
+
onMouseMove: e => handleMouseMove(e, index),
|
|
113
|
+
onClick: e => handleClick(e, index),
|
|
114
|
+
role: "radio",
|
|
115
|
+
"aria-checked": filled,
|
|
116
|
+
"aria-label": `${starValue} 星`,
|
|
117
|
+
tabIndex: disabled ? -1 : 0,
|
|
118
|
+
onKeyDown: e => {
|
|
119
|
+
if (disabled) return;
|
|
120
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
handleClick(e, index);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
children: /*#__PURE__*/_jsx(StarIcon, {
|
|
126
|
+
filled: filled,
|
|
127
|
+
half: half
|
|
128
|
+
})
|
|
129
|
+
}, index);
|
|
130
|
+
};
|
|
131
|
+
return /*#__PURE__*/_jsx("div", {
|
|
132
|
+
ref: ref,
|
|
133
|
+
className: cls,
|
|
134
|
+
style: style,
|
|
135
|
+
role: "radiogroup",
|
|
136
|
+
"aria-label": "\u8BC4\u5206",
|
|
137
|
+
onMouseLeave: handleMouseLeave,
|
|
138
|
+
children: Array.from({
|
|
139
|
+
length: count
|
|
140
|
+
}, (_, i) => renderStar(i))
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
Rate.displayName = 'Rate';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/* ===== Rate 组件样式 ===== */
|
|
2
|
+
|
|
3
|
+
.aura-rate {
|
|
4
|
+
display: inline-flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
gap: var(--aura-spacing-1);
|
|
7
|
+
|
|
8
|
+
// 禁用状态
|
|
9
|
+
&&-disabled {
|
|
10
|
+
opacity: 0.5;
|
|
11
|
+
cursor: not-allowed;
|
|
12
|
+
pointer-events: none;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// ===== 星星尺寸 =====
|
|
17
|
+
.aura-rate-sm {
|
|
18
|
+
.aura-rate-star {
|
|
19
|
+
width: 16px;
|
|
20
|
+
height: 16px;
|
|
21
|
+
font-size: 16px;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.aura-rate-md {
|
|
26
|
+
.aura-rate-star {
|
|
27
|
+
width: 20px;
|
|
28
|
+
height: 20px;
|
|
29
|
+
font-size: 20px;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.aura-rate-lg {
|
|
34
|
+
.aura-rate-star {
|
|
35
|
+
width: 28px;
|
|
36
|
+
height: 28px;
|
|
37
|
+
font-size: 28px;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ===== 单个星星 =====
|
|
42
|
+
.aura-rate-star {
|
|
43
|
+
display: inline-flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
justify-content: center;
|
|
46
|
+
cursor: pointer;
|
|
47
|
+
color: var(--aura-gray-300);
|
|
48
|
+
transition:
|
|
49
|
+
transform var(--aura-duration-normal) cubic-bezier(0.34, 1.56, 0.64, 1),
|
|
50
|
+
color var(--aura-duration-fast) var(--aura-easing);
|
|
51
|
+
position: relative;
|
|
52
|
+
|
|
53
|
+
&:hover {
|
|
54
|
+
transform: scale(1.15);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&:focus-visible {
|
|
58
|
+
outline: none;
|
|
59
|
+
box-shadow: 0 0 0 2px var(--aura-primary-200);
|
|
60
|
+
border-radius: 2px;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 填充状态
|
|
64
|
+
&&-filled {
|
|
65
|
+
color: var(--aura-warning);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 半星状态
|
|
69
|
+
&&-half {
|
|
70
|
+
color: var(--aura-warning);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ===== 暗色模式 =====
|
|
75
|
+
[data-theme='dark'] {
|
|
76
|
+
.aura-rate-star {
|
|
77
|
+
color: var(--aura-gray-600);
|
|
78
|
+
|
|
79
|
+
&&-filled {
|
|
80
|
+
color: var(--aura-warning);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
&&-half {
|
|
84
|
+
color: var(--aura-warning);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface ResultProps {
|
|
3
|
+
/** 结果类型 */
|
|
4
|
+
variant?: 'success' | 'error' | 'warning' | 'info' | '404' | '403' | '500';
|
|
5
|
+
/** 标题 */
|
|
6
|
+
title: React.ReactNode;
|
|
7
|
+
/** 副标题 */
|
|
8
|
+
subtitle?: React.ReactNode;
|
|
9
|
+
/** 自定义图标(覆盖默认) */
|
|
10
|
+
icon?: React.ReactNode;
|
|
11
|
+
/** 附加内容(如操作按钮) */
|
|
12
|
+
extra?: React.ReactNode;
|
|
13
|
+
/** 自定义类名 */
|
|
14
|
+
className?: string;
|
|
15
|
+
/** 自定义样式 */
|
|
16
|
+
style?: React.CSSProperties;
|
|
17
|
+
}
|
|
18
|
+
export declare const Result: React.ForwardRefExoticComponent<ResultProps & React.RefAttributes<HTMLDivElement>>;
|
|
19
|
+
export default Result;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { classNames, prefixCls } from '@aura-react-comp/shared';
|
|
3
|
+
import { ResultSuccess, ResultError, ResultWarning, ResultInfo, NotFound, Forbidden, ServerError } from '@aura-react-comp/icons';
|
|
4
|
+
import "./index.less";
|
|
5
|
+
|
|
6
|
+
/* ===== 类型定义 ===== */
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
/* ===== 默认图标映射 ===== */
|
|
10
|
+
|
|
11
|
+
const defaultIcons = {
|
|
12
|
+
success: /*#__PURE__*/_jsx(ResultSuccess, {
|
|
13
|
+
size: 72
|
|
14
|
+
}),
|
|
15
|
+
error: /*#__PURE__*/_jsx(ResultError, {
|
|
16
|
+
size: 72
|
|
17
|
+
}),
|
|
18
|
+
warning: /*#__PURE__*/_jsx(ResultWarning, {
|
|
19
|
+
size: 72
|
|
20
|
+
}),
|
|
21
|
+
info: /*#__PURE__*/_jsx(ResultInfo, {
|
|
22
|
+
size: 72
|
|
23
|
+
}),
|
|
24
|
+
'404': /*#__PURE__*/_jsx(NotFound, {
|
|
25
|
+
size: 200
|
|
26
|
+
}),
|
|
27
|
+
'403': /*#__PURE__*/_jsx(Forbidden, {
|
|
28
|
+
size: 200
|
|
29
|
+
}),
|
|
30
|
+
'500': /*#__PURE__*/_jsx(ServerError, {
|
|
31
|
+
size: 200
|
|
32
|
+
})
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/* ===== Result 主组件 ===== */
|
|
36
|
+
|
|
37
|
+
export const Result = /*#__PURE__*/forwardRef(({
|
|
38
|
+
variant = 'info',
|
|
39
|
+
title,
|
|
40
|
+
subtitle,
|
|
41
|
+
icon,
|
|
42
|
+
extra,
|
|
43
|
+
className,
|
|
44
|
+
style
|
|
45
|
+
}, ref) => {
|
|
46
|
+
const wrapperCls = classNames(prefixCls('result'), prefixCls(`result-${variant}`), className);
|
|
47
|
+
const displayIcon = icon !== undefined ? icon : defaultIcons[variant] ?? defaultIcons.info;
|
|
48
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
49
|
+
ref: ref,
|
|
50
|
+
className: wrapperCls,
|
|
51
|
+
style: style,
|
|
52
|
+
role: "status",
|
|
53
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
54
|
+
className: prefixCls('result-icon'),
|
|
55
|
+
children: displayIcon
|
|
56
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
57
|
+
className: prefixCls('result-title'),
|
|
58
|
+
children: title
|
|
59
|
+
}), subtitle && /*#__PURE__*/_jsx("div", {
|
|
60
|
+
className: prefixCls('result-subtitle'),
|
|
61
|
+
children: subtitle
|
|
62
|
+
}), extra && /*#__PURE__*/_jsx("div", {
|
|
63
|
+
className: prefixCls('result-extra'),
|
|
64
|
+
children: extra
|
|
65
|
+
})]
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
Result.displayName = 'Result';
|
|
69
|
+
export default Result;
|