vue-clean-tabs 1.0.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/README.md +450 -0
- package/dist/index.esm.js +262 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/style.css +1 -0
- package/package.json +67 -0
- package/src/components/ConfigurableSimpleTabs.vue +406 -0
- package/src/index.ts +30 -0
- package/src/types.ts +250 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// 简洁标签页组件的类型定义
|
|
2
|
+
|
|
3
|
+
// 标签项接口
|
|
4
|
+
export interface TabItem {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
disabled?: boolean; // 是否禁用
|
|
8
|
+
route?: string; // 可选路由地址
|
|
9
|
+
icon?: string; // 可选图标
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 尺寸类型
|
|
13
|
+
export type TabSize = 'small' | 'medium' | 'large';
|
|
14
|
+
|
|
15
|
+
// 指示器样式类型
|
|
16
|
+
export type IndicatorStyle = 'line' | 'dot' | 'pill' | 'underline';
|
|
17
|
+
|
|
18
|
+
// 主题配置接口
|
|
19
|
+
export interface SimpleTabsTheme {
|
|
20
|
+
// 激活状态文字颜色
|
|
21
|
+
activeTextColor: string;
|
|
22
|
+
// 非激活状态文字颜色
|
|
23
|
+
inactiveTextColor: string;
|
|
24
|
+
// 悬浮状态文字颜色
|
|
25
|
+
hoverTextColor: string;
|
|
26
|
+
// 背景色
|
|
27
|
+
backgroundColor: string;
|
|
28
|
+
// 激活指示器颜色
|
|
29
|
+
indicatorColor: string;
|
|
30
|
+
// 字体系列
|
|
31
|
+
fontFamily: string;
|
|
32
|
+
// 边框颜色(如果需要)
|
|
33
|
+
borderColor?: string;
|
|
34
|
+
// 阴影(如果需要)
|
|
35
|
+
boxShadow?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 样式配置接口
|
|
39
|
+
export interface StyleConfig {
|
|
40
|
+
// 内边距
|
|
41
|
+
padding: string;
|
|
42
|
+
// 字体大小
|
|
43
|
+
fontSize: string;
|
|
44
|
+
// 字体粗细
|
|
45
|
+
fontWeight: string;
|
|
46
|
+
// 指示器高度
|
|
47
|
+
indicatorHeight: string;
|
|
48
|
+
// 指示器样式
|
|
49
|
+
indicatorStyle: IndicatorStyle;
|
|
50
|
+
// 圆角大小
|
|
51
|
+
borderRadius?: string;
|
|
52
|
+
// 标签间距
|
|
53
|
+
gap?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 动画配置接口
|
|
57
|
+
export interface AnimationConfig {
|
|
58
|
+
// 过渡时长
|
|
59
|
+
transitionDuration: string;
|
|
60
|
+
// 缓动函数
|
|
61
|
+
easing: string;
|
|
62
|
+
// 是否启用动画
|
|
63
|
+
enabled: boolean;
|
|
64
|
+
// 指示器动画时长
|
|
65
|
+
indicatorTransition?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 响应式配置接口
|
|
69
|
+
export interface ResponsiveConfig {
|
|
70
|
+
// 移动端断点
|
|
71
|
+
mobileBreakpoint: number;
|
|
72
|
+
// 移动端样式
|
|
73
|
+
mobileStyle?: Partial<StyleConfig>;
|
|
74
|
+
// 是否启用响应式
|
|
75
|
+
enabled: boolean;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 主组件Props接口
|
|
79
|
+
export interface SimpleTabsProps {
|
|
80
|
+
// 标签页数据
|
|
81
|
+
tabs: TabItem[];
|
|
82
|
+
|
|
83
|
+
// 默认激活的标签ID
|
|
84
|
+
defaultActive?: string;
|
|
85
|
+
|
|
86
|
+
// 尺寸
|
|
87
|
+
size?: TabSize;
|
|
88
|
+
|
|
89
|
+
// 主题配置
|
|
90
|
+
theme?: Partial<SimpleTabsTheme>;
|
|
91
|
+
|
|
92
|
+
// 样式配置
|
|
93
|
+
style?: Partial<StyleConfig>;
|
|
94
|
+
|
|
95
|
+
// 动画配置
|
|
96
|
+
animation?: Partial<AnimationConfig>;
|
|
97
|
+
|
|
98
|
+
// 响应式配置
|
|
99
|
+
responsive?: Partial<ResponsiveConfig>;
|
|
100
|
+
|
|
101
|
+
// 自定义类名
|
|
102
|
+
className?: string;
|
|
103
|
+
|
|
104
|
+
// 自定义内联样式
|
|
105
|
+
customStyle?: Record<string, any>;
|
|
106
|
+
|
|
107
|
+
// 是否显示为块级元素
|
|
108
|
+
block?: boolean;
|
|
109
|
+
|
|
110
|
+
// 居中对齐
|
|
111
|
+
centered?: boolean;
|
|
112
|
+
|
|
113
|
+
// 是否可滚动(当标签过多时)
|
|
114
|
+
scrollable?: boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 事件接口
|
|
118
|
+
export interface SimpleTabsEvents {
|
|
119
|
+
'tab-change': [tabId: string, tab: TabItem];
|
|
120
|
+
'tab-click': [tabId: string, tab: TabItem, event: Event];
|
|
121
|
+
'tab-hover': [tabId: string, tab: TabItem];
|
|
122
|
+
'tab-leave': [tabId: string, tab: TabItem];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 默认主题
|
|
126
|
+
export const defaultTheme: SimpleTabsTheme = {
|
|
127
|
+
activeTextColor: 'rgb(20, 23, 26)',
|
|
128
|
+
inactiveTextColor: 'rgb(76, 82, 89)',
|
|
129
|
+
hoverTextColor: 'rgb(55, 65, 81)',
|
|
130
|
+
backgroundColor: '#ffffff',
|
|
131
|
+
indicatorColor: 'rgb(20, 23, 26)',
|
|
132
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", "SF Pro Display", "Inter", sans-serif',
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// 尺寸配置
|
|
136
|
+
export const sizeConfigs: Record<TabSize, StyleConfig> = {
|
|
137
|
+
small: {
|
|
138
|
+
padding: '8px 10px',
|
|
139
|
+
fontSize: '14px',
|
|
140
|
+
fontWeight: '500',
|
|
141
|
+
indicatorHeight: '2px',
|
|
142
|
+
indicatorStyle: 'line',
|
|
143
|
+
gap: '16px',
|
|
144
|
+
},
|
|
145
|
+
medium: {
|
|
146
|
+
padding: '14px 12px',
|
|
147
|
+
fontSize: '16px',
|
|
148
|
+
fontWeight: '600',
|
|
149
|
+
indicatorHeight: '2px',
|
|
150
|
+
indicatorStyle: 'line',
|
|
151
|
+
gap: '20px',
|
|
152
|
+
},
|
|
153
|
+
large: {
|
|
154
|
+
padding: '16px 16px',
|
|
155
|
+
fontSize: '18px',
|
|
156
|
+
fontWeight: '700',
|
|
157
|
+
indicatorHeight: '3px',
|
|
158
|
+
indicatorStyle: 'line',
|
|
159
|
+
gap: '24px',
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// 默认动画配置
|
|
164
|
+
export const defaultAnimation: AnimationConfig = {
|
|
165
|
+
transitionDuration: '0.2s',
|
|
166
|
+
easing: 'ease',
|
|
167
|
+
enabled: true,
|
|
168
|
+
indicatorTransition: '0.3s ease',
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// 默认响应式配置
|
|
172
|
+
export const defaultResponsive: ResponsiveConfig = {
|
|
173
|
+
mobileBreakpoint: 768,
|
|
174
|
+
enabled: true,
|
|
175
|
+
mobileStyle: {
|
|
176
|
+
padding: '14px 0',
|
|
177
|
+
gap: '16px',
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// 指示器样式映射
|
|
182
|
+
export const indicatorStyles: Record<IndicatorStyle, (color: string, height: string) => Record<string, string>> = {
|
|
183
|
+
line: (color: string, height: string) => ({
|
|
184
|
+
position: 'absolute',
|
|
185
|
+
bottom: '0',
|
|
186
|
+
left: '12px',
|
|
187
|
+
right: '12px',
|
|
188
|
+
height,
|
|
189
|
+
backgroundColor: color,
|
|
190
|
+
borderRadius: '0',
|
|
191
|
+
}),
|
|
192
|
+
|
|
193
|
+
underline: (color: string, height: string) => ({
|
|
194
|
+
position: 'absolute',
|
|
195
|
+
bottom: '0',
|
|
196
|
+
left: '0',
|
|
197
|
+
right: '0',
|
|
198
|
+
height,
|
|
199
|
+
backgroundColor: color,
|
|
200
|
+
borderRadius: '0',
|
|
201
|
+
}),
|
|
202
|
+
|
|
203
|
+
dot: (color: string, height: string) => ({
|
|
204
|
+
position: 'absolute',
|
|
205
|
+
bottom: '4px',
|
|
206
|
+
left: '50%',
|
|
207
|
+
transform: 'translateX(-50%)',
|
|
208
|
+
width: height,
|
|
209
|
+
height,
|
|
210
|
+
backgroundColor: color,
|
|
211
|
+
borderRadius: '50%',
|
|
212
|
+
}),
|
|
213
|
+
|
|
214
|
+
pill: (color: string, height: string) => ({
|
|
215
|
+
position: 'absolute',
|
|
216
|
+
bottom: '4px',
|
|
217
|
+
left: '8px',
|
|
218
|
+
right: '8px',
|
|
219
|
+
height,
|
|
220
|
+
backgroundColor: color,
|
|
221
|
+
borderRadius: height,
|
|
222
|
+
}),
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// 工具函数:获取指示器样式
|
|
226
|
+
export const getIndicatorStyle = (
|
|
227
|
+
style: IndicatorStyle,
|
|
228
|
+
color: string,
|
|
229
|
+
height: string
|
|
230
|
+
): Record<string, string> => {
|
|
231
|
+
return indicatorStyles[style](color, height);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// 工具函数:合并配置
|
|
235
|
+
export const mergeConfig = <T extends Record<string, any>>(
|
|
236
|
+
defaultConfig: T,
|
|
237
|
+
userConfig?: Partial<T>
|
|
238
|
+
): T => {
|
|
239
|
+
return { ...defaultConfig, ...userConfig };
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// 工具函数:获取响应式样式
|
|
243
|
+
export const getResponsiveStyle = (
|
|
244
|
+
isMobile: boolean,
|
|
245
|
+
baseStyle: StyleConfig,
|
|
246
|
+
mobileStyle?: Partial<StyleConfig>
|
|
247
|
+
): StyleConfig => {
|
|
248
|
+
if (!isMobile || !mobileStyle) return baseStyle;
|
|
249
|
+
return { ...baseStyle, ...mobileStyle };
|
|
250
|
+
};
|