@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,170 @@
|
|
|
1
|
+
import React, { forwardRef, createContext, useContext, useState, useCallback, useRef, useEffect, useLayoutEffect } from 'react';
|
|
2
|
+
import { classNames, prefixCls } from '@aura-react-comp/shared';
|
|
3
|
+
import "./index.less";
|
|
4
|
+
|
|
5
|
+
/* ===== Context ===== */
|
|
6
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
const TabsContext = /*#__PURE__*/createContext(null);
|
|
10
|
+
function useTabsContext() {
|
|
11
|
+
const ctx = useContext(TabsContext);
|
|
12
|
+
if (!ctx) throw new Error('TabItem 必须在 Tabs 内部使用');
|
|
13
|
+
return ctx;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* ===== TabItem ===== */
|
|
17
|
+
|
|
18
|
+
/** 内部组件:单个选项卡面板 */
|
|
19
|
+
const TabItem = ({
|
|
20
|
+
children
|
|
21
|
+
}) => {
|
|
22
|
+
const {
|
|
23
|
+
activeKey
|
|
24
|
+
} = useTabsContext();
|
|
25
|
+
// 只渲染占位,不显示内容 —— Tabs 组件自己控制渲染
|
|
26
|
+
void activeKey;
|
|
27
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
28
|
+
children: children
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
TabItem.displayName = 'TabItem';
|
|
32
|
+
|
|
33
|
+
/* ===== Tabs ===== */
|
|
34
|
+
|
|
35
|
+
export const Tabs = /*#__PURE__*/forwardRef(({
|
|
36
|
+
defaultActiveKey,
|
|
37
|
+
activeKey: controlledActiveKey,
|
|
38
|
+
variant = 'default',
|
|
39
|
+
size = 'md',
|
|
40
|
+
onChange,
|
|
41
|
+
destroyInactiveTabPane = false,
|
|
42
|
+
className,
|
|
43
|
+
style,
|
|
44
|
+
children
|
|
45
|
+
}, ref) => {
|
|
46
|
+
/* --- 受控/非受控 --- */
|
|
47
|
+
const [internalKey, setInternalKey] = useState(defaultActiveKey);
|
|
48
|
+
const isControlled = controlledActiveKey !== undefined;
|
|
49
|
+
const activeKey = isControlled ? controlledActiveKey : internalKey;
|
|
50
|
+
|
|
51
|
+
/* --- 从 children 提取 tab 信息 --- */
|
|
52
|
+
const tabItems = [];
|
|
53
|
+
React.Children.forEach(children, child => {
|
|
54
|
+
if ( /*#__PURE__*/React.isValidElement(child) && child.type === TabItem) {
|
|
55
|
+
const {
|
|
56
|
+
tabKey,
|
|
57
|
+
title,
|
|
58
|
+
disabled,
|
|
59
|
+
children: content
|
|
60
|
+
} = child.props;
|
|
61
|
+
tabItems.push({
|
|
62
|
+
tabKey,
|
|
63
|
+
title,
|
|
64
|
+
disabled: !!disabled,
|
|
65
|
+
children: content
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// 如果没有 activeKey,取第一个
|
|
71
|
+
const resolvedActiveKey = activeKey ?? tabItems[0]?.tabKey ?? '';
|
|
72
|
+
|
|
73
|
+
// 已访问过的面板:非 destroy 模式下保持挂载(hidden 隐藏),保留内部状态
|
|
74
|
+
const [visitedKeys, setVisitedKeys] = useState(() => new Set(resolvedActiveKey ? [resolvedActiveKey] : []));
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
setVisitedKeys(prev => prev.has(resolvedActiveKey) ? prev : new Set(prev).add(resolvedActiveKey));
|
|
77
|
+
}, [resolvedActiveKey]);
|
|
78
|
+
const handleChange = useCallback(key => {
|
|
79
|
+
if (!isControlled) setInternalKey(key);
|
|
80
|
+
onChange?.(key);
|
|
81
|
+
}, [isControlled, onChange]);
|
|
82
|
+
|
|
83
|
+
/* --- 指示器定位(仅 default variant) --- */
|
|
84
|
+
const navRef = useRef(null);
|
|
85
|
+
const [indicatorStyle, setIndicatorStyle] = React.useState({});
|
|
86
|
+
const updateIndicator = useCallback(() => {
|
|
87
|
+
if (variant !== 'default' || !navRef.current) return;
|
|
88
|
+
const activeTab = navRef.current.querySelector(`[data-tab-key="${resolvedActiveKey}"]`);
|
|
89
|
+
if (activeTab) {
|
|
90
|
+
const navRect = navRef.current.getBoundingClientRect();
|
|
91
|
+
const tabRect = activeTab.getBoundingClientRect();
|
|
92
|
+
setIndicatorStyle({
|
|
93
|
+
width: tabRect.width,
|
|
94
|
+
transform: `translateX(${tabRect.left - navRect.left}px)`
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}, [variant, resolvedActiveKey]);
|
|
98
|
+
|
|
99
|
+
// 用 useLayoutEffect 保证指示器在渲染后同步更新,避免闪烁
|
|
100
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
101
|
+
useIsomorphicLayoutEffect(() => {
|
|
102
|
+
updateIndicator();
|
|
103
|
+
}, [updateIndicator]);
|
|
104
|
+
|
|
105
|
+
/* --- 查找当前激活的内容 --- */
|
|
106
|
+
const activeContent = tabItems.find(item => item.tabKey === resolvedActiveKey)?.children;
|
|
107
|
+
|
|
108
|
+
/* --- 需要渲染的面板 --- */
|
|
109
|
+
const panelsToRender = destroyInactiveTabPane ? tabItems.filter(item => item.tabKey === resolvedActiveKey) : tabItems.filter(item => visitedKeys.has(item.tabKey));
|
|
110
|
+
|
|
111
|
+
/* --- className --- */
|
|
112
|
+
const wrapperCls = classNames(prefixCls('tabs'), prefixCls(`tabs-${variant}`), prefixCls(`tabs-${size}`), className);
|
|
113
|
+
const ctxValue = {
|
|
114
|
+
activeKey: resolvedActiveKey,
|
|
115
|
+
onChange: handleChange,
|
|
116
|
+
variant,
|
|
117
|
+
size
|
|
118
|
+
};
|
|
119
|
+
return /*#__PURE__*/_jsx(TabsContext.Provider, {
|
|
120
|
+
value: ctxValue,
|
|
121
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
122
|
+
ref: ref,
|
|
123
|
+
className: wrapperCls,
|
|
124
|
+
style: style,
|
|
125
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
126
|
+
ref: navRef,
|
|
127
|
+
className: prefixCls('tabs-nav'),
|
|
128
|
+
role: "tablist",
|
|
129
|
+
children: [tabItems.map(item => {
|
|
130
|
+
const isActive = item.tabKey === resolvedActiveKey;
|
|
131
|
+
const tabCls = classNames(prefixCls('tabs-tab'), isActive && prefixCls('tabs-tab-active'), item.disabled && prefixCls('tabs-tab-disabled'));
|
|
132
|
+
return /*#__PURE__*/_jsx("button", {
|
|
133
|
+
type: "button",
|
|
134
|
+
role: "tab",
|
|
135
|
+
"data-tab-key": item.tabKey,
|
|
136
|
+
className: tabCls,
|
|
137
|
+
"aria-selected": isActive,
|
|
138
|
+
"aria-disabled": item.disabled,
|
|
139
|
+
onClick: () => {
|
|
140
|
+
if (!item.disabled) handleChange(item.tabKey);
|
|
141
|
+
},
|
|
142
|
+
children: item.title
|
|
143
|
+
}, item.tabKey);
|
|
144
|
+
}), variant === 'default' && /*#__PURE__*/_jsx("span", {
|
|
145
|
+
className: prefixCls('tabs-indicator'),
|
|
146
|
+
style: indicatorStyle
|
|
147
|
+
})]
|
|
148
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
149
|
+
className: classNames(prefixCls('tabs-content'), activeContent == null && prefixCls('tabs-content-empty')),
|
|
150
|
+
children: panelsToRender.map(item => /*#__PURE__*/_jsx("div", {
|
|
151
|
+
className: prefixCls('tabs-panel'),
|
|
152
|
+
role: "tabpanel",
|
|
153
|
+
hidden: item.tabKey !== resolvedActiveKey,
|
|
154
|
+
children: item.children
|
|
155
|
+
}, item.tabKey))
|
|
156
|
+
})]
|
|
157
|
+
})
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
Tabs.displayName = 'Tabs';
|
|
161
|
+
|
|
162
|
+
// 子组件挂载
|
|
163
|
+
const TabsCompound = Tabs;
|
|
164
|
+
TabsCompound.Tab = TabItem;
|
|
165
|
+
|
|
166
|
+
// 导出复合类型
|
|
167
|
+
|
|
168
|
+
export const TabsWithSub = Tabs;
|
|
169
|
+
export { TabItem };
|
|
170
|
+
export default Tabs;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
.aura-tabs {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
|
|
5
|
+
/* ===== Nav Bar ===== */
|
|
6
|
+
&-nav {
|
|
7
|
+
position: relative;
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
gap: 0;
|
|
11
|
+
border-bottom: 1px solid var(--aura-border);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/* ===== Tab 按钮 ===== */
|
|
15
|
+
&-tab {
|
|
16
|
+
position: relative;
|
|
17
|
+
display: inline-flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
padding: 8px 16px;
|
|
21
|
+
font-size: var(--aura-font-size-md);
|
|
22
|
+
font-family: inherit;
|
|
23
|
+
line-height: 1.5;
|
|
24
|
+
color: var(--aura-text-secondary);
|
|
25
|
+
background: transparent;
|
|
26
|
+
border: none;
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
transition:
|
|
29
|
+
color var(--aura-duration-normal) var(--aura-easing),
|
|
30
|
+
background-color var(--aura-duration-normal) var(--aura-easing),
|
|
31
|
+
border-color var(--aura-duration-normal) var(--aura-easing),
|
|
32
|
+
transform var(--aura-duration-fast) var(--aura-easing);
|
|
33
|
+
white-space: nowrap;
|
|
34
|
+
user-select: none;
|
|
35
|
+
|
|
36
|
+
&:hover {
|
|
37
|
+
color: var(--aura-primary-700);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&:active {
|
|
41
|
+
transform: scale(0.97);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&-active {
|
|
45
|
+
color: var(--aura-primary-700);
|
|
46
|
+
font-weight: 600;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
&-disabled {
|
|
50
|
+
color: var(--aura-text-tertiary);
|
|
51
|
+
cursor: not-allowed;
|
|
52
|
+
|
|
53
|
+
&:hover {
|
|
54
|
+
color: var(--aura-text-tertiary);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&:active {
|
|
58
|
+
transform: none;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* ===== 指示器(default variant) ===== */
|
|
64
|
+
&-indicator {
|
|
65
|
+
position: absolute;
|
|
66
|
+
bottom: -1px;
|
|
67
|
+
left: 0;
|
|
68
|
+
height: 2px;
|
|
69
|
+
background: var(--aura-primary-700);
|
|
70
|
+
border-radius: 2px 2px 0 0;
|
|
71
|
+
transition:
|
|
72
|
+
transform var(--aura-duration-slow) var(--aura-easing),
|
|
73
|
+
width var(--aura-duration-slow) var(--aura-easing);
|
|
74
|
+
will-change: transform, width;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* ===== Content ===== */
|
|
78
|
+
&-content {
|
|
79
|
+
padding-top: var(--aura-spacing-4);
|
|
80
|
+
|
|
81
|
+
&-empty {
|
|
82
|
+
padding-top: 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/* ===== Panel 切换动画 ===== */
|
|
87
|
+
&-panel {
|
|
88
|
+
animation: aura-tabs-fade-in var(--aura-duration-slow) var(--aura-easing);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* ===== Size 变体 ===== */
|
|
92
|
+
&-sm {
|
|
93
|
+
.aura-tabs-tab {
|
|
94
|
+
padding: 4px 12px;
|
|
95
|
+
font-size: var(--aura-font-size-sm);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
&-lg {
|
|
100
|
+
.aura-tabs-tab {
|
|
101
|
+
padding: 12px 24px;
|
|
102
|
+
font-size: var(--aura-font-size-lg);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/* ===== Variant: card ===== */
|
|
107
|
+
&&-card {
|
|
108
|
+
.aura-tabs-nav {
|
|
109
|
+
border-bottom: none;
|
|
110
|
+
gap: 0;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.aura-tabs-tab {
|
|
114
|
+
border: 1px solid transparent;
|
|
115
|
+
border-bottom: none;
|
|
116
|
+
border-radius: var(--aura-radius-md) var(--aura-radius-md) 0 0;
|
|
117
|
+
background: transparent;
|
|
118
|
+
transition: all var(--aura-duration-normal) var(--aura-easing);
|
|
119
|
+
|
|
120
|
+
&:hover {
|
|
121
|
+
background: var(--aura-bg-secondary);
|
|
122
|
+
border-color: var(--aura-border);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
&-active {
|
|
126
|
+
background: var(--aura-bg);
|
|
127
|
+
border-color: var(--aura-border);
|
|
128
|
+
color: var(--aura-primary-700);
|
|
129
|
+
|
|
130
|
+
&:hover {
|
|
131
|
+
background: var(--aura-bg);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/* ===== Variant: pill ===== */
|
|
138
|
+
&&-pill {
|
|
139
|
+
.aura-tabs-nav {
|
|
140
|
+
border-bottom: none;
|
|
141
|
+
gap: var(--aura-spacing-2);
|
|
142
|
+
background: var(--aura-bg-secondary);
|
|
143
|
+
padding: var(--aura-spacing-1);
|
|
144
|
+
border-radius: var(--aura-radius-full);
|
|
145
|
+
display: inline-flex;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.aura-tabs-tab {
|
|
149
|
+
border-radius: var(--aura-radius-full);
|
|
150
|
+
padding: 6px 16px;
|
|
151
|
+
transition: all var(--aura-duration-normal) var(--aura-easing);
|
|
152
|
+
|
|
153
|
+
&:hover {
|
|
154
|
+
background: var(--aura-bg-tertiary);
|
|
155
|
+
color: var(--aura-text);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
&-active {
|
|
159
|
+
background: var(--aura-primary-700);
|
|
160
|
+
color: var(--aura-text-inverse);
|
|
161
|
+
box-shadow: 0 2px 6px rgba(124, 58, 237, 0.3);
|
|
162
|
+
|
|
163
|
+
&:hover {
|
|
164
|
+
background: var(--aura-primary-600);
|
|
165
|
+
color: var(--aura-text-inverse);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// pill size sm
|
|
171
|
+
&.aura-tabs-sm {
|
|
172
|
+
.aura-tabs-tab {
|
|
173
|
+
padding: 3px 12px;
|
|
174
|
+
font-size: var(--aura-font-size-sm);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// pill size lg
|
|
179
|
+
&.aura-tabs-lg {
|
|
180
|
+
.aura-tabs-tab {
|
|
181
|
+
padding: 8px 24px;
|
|
182
|
+
font-size: var(--aura-font-size-lg);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/* ===== 动画关键帧 ===== */
|
|
189
|
+
@keyframes aura-tabs-fade-in {
|
|
190
|
+
from {
|
|
191
|
+
opacity: 0;
|
|
192
|
+
transform: translateY(4px);
|
|
193
|
+
}
|
|
194
|
+
to {
|
|
195
|
+
opacity: 1;
|
|
196
|
+
transform: translateY(0);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/* ===== 暗色模式 ===== */
|
|
201
|
+
[data-theme='dark'] {
|
|
202
|
+
.aura-tabs {
|
|
203
|
+
&-tab {
|
|
204
|
+
&:hover {
|
|
205
|
+
color: var(--aura-primary-400);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
&-active {
|
|
209
|
+
color: var(--aura-primary-400);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
&-indicator {
|
|
214
|
+
background: var(--aura-primary-400);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
&&-pill {
|
|
218
|
+
.aura-tabs-tab-active {
|
|
219
|
+
background: var(--aura-primary-600);
|
|
220
|
+
box-shadow: 0 2px 8px rgba(124, 58, 237, 0.4);
|
|
221
|
+
|
|
222
|
+
&:hover {
|
|
223
|
+
background: var(--aura-primary-500);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface TagProps {
|
|
3
|
+
/** 标签变体样式
|
|
4
|
+
* @default 'default'
|
|
5
|
+
*/
|
|
6
|
+
variant?: 'default' | 'primary' | 'success' | 'warning' | 'error' | 'info';
|
|
7
|
+
/** 标签尺寸
|
|
8
|
+
* @default 'md'
|
|
9
|
+
*/
|
|
10
|
+
size?: 'sm' | 'md' | 'lg';
|
|
11
|
+
/** 是否可关闭 */
|
|
12
|
+
closable?: boolean;
|
|
13
|
+
/** 关闭回调 */
|
|
14
|
+
onClose?: () => void;
|
|
15
|
+
/** 自定义类名 */
|
|
16
|
+
className?: string;
|
|
17
|
+
/** 自定义样式 */
|
|
18
|
+
style?: React.CSSProperties;
|
|
19
|
+
/** 标签内容 */
|
|
20
|
+
children?: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
export declare const Tag: React.ForwardRefExoticComponent<TagProps & React.RefAttributes<HTMLSpanElement>>;
|
|
23
|
+
export interface TagCheckableProps {
|
|
24
|
+
/** 是否选中
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
27
|
+
checked?: boolean;
|
|
28
|
+
/** 选中状态变化回调 */
|
|
29
|
+
onChange?: (checked: boolean) => void;
|
|
30
|
+
/** 标签值(在 Group 中使用) */
|
|
31
|
+
value?: string | number;
|
|
32
|
+
/** 自定义类名 */
|
|
33
|
+
className?: string;
|
|
34
|
+
/** 自定义样式 */
|
|
35
|
+
style?: React.CSSProperties;
|
|
36
|
+
/** 标签内容 */
|
|
37
|
+
children?: React.ReactNode;
|
|
38
|
+
}
|
|
39
|
+
export declare const TagCheckable: React.ForwardRefExoticComponent<TagCheckableProps & React.RefAttributes<HTMLSpanElement>>;
|
|
40
|
+
export interface TagGroupProps {
|
|
41
|
+
/** 当前选中值(受控,配合 Tag.Checkable 使用) */
|
|
42
|
+
value?: (string | number)[];
|
|
43
|
+
/** 选中值变化回调 */
|
|
44
|
+
onChange?: (value: (string | number)[]) => void;
|
|
45
|
+
/** 自定义类名 */
|
|
46
|
+
className?: string;
|
|
47
|
+
/** 自定义样式 */
|
|
48
|
+
style?: React.CSSProperties;
|
|
49
|
+
/** 子元素 */
|
|
50
|
+
children?: React.ReactNode;
|
|
51
|
+
}
|
|
52
|
+
export declare const TagGroup: React.FC<TagGroupProps>;
|
package/esm/tag/index.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import React, { forwardRef, useState, useCallback, createContext, useContext } from 'react';
|
|
2
|
+
import { classNames, prefixCls } from '@aura-react-comp/shared';
|
|
3
|
+
import { Close } from '@aura-react-comp/icons';
|
|
4
|
+
import "./index.less";
|
|
5
|
+
|
|
6
|
+
/* ===== Tag Context(用于 Tag.Group) ===== */
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
const TagGroupContext = /*#__PURE__*/createContext(null);
|
|
10
|
+
|
|
11
|
+
/* ===== Tag ===== */
|
|
12
|
+
|
|
13
|
+
export const Tag = /*#__PURE__*/forwardRef(({
|
|
14
|
+
variant = 'default',
|
|
15
|
+
size = 'md',
|
|
16
|
+
closable = false,
|
|
17
|
+
onClose,
|
|
18
|
+
className,
|
|
19
|
+
style,
|
|
20
|
+
children
|
|
21
|
+
}, ref) => {
|
|
22
|
+
const [visible, setVisible] = useState(true);
|
|
23
|
+
const [closing, setClosing] = useState(false);
|
|
24
|
+
const handleClose = useCallback(e => {
|
|
25
|
+
e.stopPropagation();
|
|
26
|
+
setClosing(true);
|
|
27
|
+
// 等待动画结束后真正移除
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
setVisible(false);
|
|
30
|
+
onClose?.();
|
|
31
|
+
}, 250);
|
|
32
|
+
}, [onClose]);
|
|
33
|
+
if (!visible) return null;
|
|
34
|
+
const cls = classNames(prefixCls('tag'), variant !== 'default' && prefixCls(`tag-${variant}`), prefixCls(`tag-${size}`), closing && prefixCls('tag-closing'), className);
|
|
35
|
+
return /*#__PURE__*/_jsxs("span", {
|
|
36
|
+
ref: ref,
|
|
37
|
+
className: cls,
|
|
38
|
+
style: style,
|
|
39
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
40
|
+
className: prefixCls('tag-content'),
|
|
41
|
+
children: children
|
|
42
|
+
}), closable && /*#__PURE__*/_jsx("span", {
|
|
43
|
+
className: prefixCls('tag-close'),
|
|
44
|
+
onClick: handleClose,
|
|
45
|
+
role: "button",
|
|
46
|
+
"aria-label": "\u5173\u95ED",
|
|
47
|
+
children: /*#__PURE__*/_jsx(Close, {
|
|
48
|
+
size: 12
|
|
49
|
+
})
|
|
50
|
+
})]
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
Tag.displayName = 'Tag';
|
|
54
|
+
|
|
55
|
+
/* ===== Tag.Checkable(可选中标签) ===== */
|
|
56
|
+
|
|
57
|
+
export const TagCheckable = /*#__PURE__*/forwardRef(({
|
|
58
|
+
checked: controlledChecked,
|
|
59
|
+
onChange,
|
|
60
|
+
value,
|
|
61
|
+
className,
|
|
62
|
+
style,
|
|
63
|
+
children
|
|
64
|
+
}, ref) => {
|
|
65
|
+
const groupCtx = useContext(TagGroupContext);
|
|
66
|
+
const [internalChecked, setInternalChecked] = useState(false);
|
|
67
|
+
const isChecked = groupCtx ? groupCtx.value !== undefined && value !== undefined ? groupCtx.value.includes(value) : internalChecked : controlledChecked ?? internalChecked;
|
|
68
|
+
const handleClick = useCallback(() => {
|
|
69
|
+
if (groupCtx && groupCtx.onChange && value !== undefined) {
|
|
70
|
+
const nextChecked = !isChecked;
|
|
71
|
+
const nextValue = nextChecked ? [...(groupCtx.value ?? []), value] : (groupCtx.value ?? []).filter(v => v !== value);
|
|
72
|
+
groupCtx.onChange(nextValue);
|
|
73
|
+
} else {
|
|
74
|
+
const nextChecked = !isChecked;
|
|
75
|
+
if (controlledChecked === undefined) {
|
|
76
|
+
setInternalChecked(nextChecked);
|
|
77
|
+
}
|
|
78
|
+
onChange?.(nextChecked);
|
|
79
|
+
}
|
|
80
|
+
}, [groupCtx, isChecked, controlledChecked, onChange, value]);
|
|
81
|
+
const cls = classNames(prefixCls('tag'), prefixCls('tag-checkable'), isChecked && prefixCls('tag-checkable-checked'), className);
|
|
82
|
+
return /*#__PURE__*/_jsx("span", {
|
|
83
|
+
ref: ref,
|
|
84
|
+
className: cls,
|
|
85
|
+
style: style,
|
|
86
|
+
onClick: handleClick,
|
|
87
|
+
role: "checkbox",
|
|
88
|
+
"aria-checked": isChecked,
|
|
89
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
90
|
+
className: prefixCls('tag-content'),
|
|
91
|
+
children: children
|
|
92
|
+
})
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
TagCheckable.displayName = 'TagCheckable';
|
|
96
|
+
|
|
97
|
+
/* ===== Tag.Group(标签组容器) ===== */
|
|
98
|
+
|
|
99
|
+
export const TagGroup = ({
|
|
100
|
+
value,
|
|
101
|
+
onChange,
|
|
102
|
+
className,
|
|
103
|
+
style,
|
|
104
|
+
children
|
|
105
|
+
}) => {
|
|
106
|
+
const ctx = {
|
|
107
|
+
value,
|
|
108
|
+
onChange
|
|
109
|
+
};
|
|
110
|
+
const cls = classNames(prefixCls('tag-group'), className);
|
|
111
|
+
return /*#__PURE__*/_jsx(TagGroupContext.Provider, {
|
|
112
|
+
value: ctx,
|
|
113
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
114
|
+
className: cls,
|
|
115
|
+
style: style,
|
|
116
|
+
children: children
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
TagGroup.displayName = 'TagGroup';
|