forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
183 lines (157 loc) · 5.32 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import type { CSSObject } from '../../_util/cssinjs';
import type { FullToken } from '../../theme/internal';
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
import { genPresetColor, resetComponent } from '../../style';
import type { CSSProperties } from 'vue';
import { capitalize } from '../../_util/util';
export interface ComponentToken {}
interface TagToken extends FullToken<'Tag'> {
tagFontSize: number;
tagLineHeight: CSSProperties['lineHeight'];
tagDefaultBg: string;
tagDefaultColor: string;
tagIconSize: number;
tagPaddingHorizontal: number;
tagBorderlessBg: string;
}
// ============================== Styles ==============================
type CssVariableType = 'Success' | 'Info' | 'Error' | 'Warning';
const genTagStatusStyle = (
token: TagToken,
status: 'success' | 'processing' | 'error' | 'warning',
cssVariableType: CssVariableType,
): CSSObject => {
const capitalizedCssVariableType = capitalize(cssVariableType);
return {
[`${token.componentCls}-${status}`]: {
color: token[`color${cssVariableType}`],
background: token[`color${capitalizedCssVariableType}Bg`],
borderColor: token[`color${capitalizedCssVariableType}Border`],
[`&${token.componentCls}-borderless`]: {
borderColor: 'transparent',
},
},
};
};
const genPresetStyle = (token: TagToken) =>
genPresetColor(token, (colorKey, { textColor, lightBorderColor, lightColor, darkColor }) => ({
[`${token.componentCls}-${colorKey}`]: {
color: textColor,
background: lightColor,
borderColor: lightBorderColor,
// Inverse color
'&-inverse': {
color: token.colorTextLightSolid,
background: darkColor,
borderColor: darkColor,
},
[`&${token.componentCls}-borderless`]: {
borderColor: 'transparent',
},
},
}));
const genBaseStyle = (token: TagToken): CSSObject => {
const { paddingXXS, lineWidth, tagPaddingHorizontal, componentCls } = token;
const paddingInline = tagPaddingHorizontal - lineWidth;
const iconMarginInline = paddingXXS - lineWidth;
return {
// Result
[componentCls]: {
...resetComponent(token),
display: 'inline-block',
height: 'auto',
marginInlineEnd: token.marginXS,
paddingInline,
fontSize: token.tagFontSize,
lineHeight: `${token.tagLineHeight}px`,
whiteSpace: 'nowrap',
background: token.tagDefaultBg,
border: `${token.lineWidth}px ${token.lineType} ${token.colorBorder}`,
borderRadius: token.borderRadiusSM,
opacity: 1,
transition: `all ${token.motionDurationMid}`,
textAlign: 'start',
// RTL
[`&${componentCls}-rtl`]: {
direction: 'rtl',
},
'&, a, a:hover': {
color: token.tagDefaultColor,
},
[`${componentCls}-close-icon`]: {
marginInlineStart: iconMarginInline,
color: token.colorTextDescription,
fontSize: token.tagIconSize,
cursor: 'pointer',
transition: `all ${token.motionDurationMid}`,
'&:hover': {
color: token.colorTextHeading,
},
},
[`&${componentCls}-has-color`]: {
borderColor: 'transparent',
[`&, a, a:hover, ${token.iconCls}-close, ${token.iconCls}-close:hover`]: {
color: token.colorTextLightSolid,
},
},
[`&-checkable`]: {
backgroundColor: 'transparent',
borderColor: 'transparent',
cursor: 'pointer',
[`&:not(${componentCls}-checkable-checked):hover`]: {
color: token.colorPrimary,
backgroundColor: token.colorFillSecondary,
},
'&:active, &-checked': {
color: token.colorTextLightSolid,
},
'&-checked': {
backgroundColor: token.colorPrimary,
'&:hover': {
backgroundColor: token.colorPrimaryHover,
},
},
'&:active': {
backgroundColor: token.colorPrimaryActive,
},
},
[`&-hidden`]: {
display: 'none',
},
// To ensure that a space will be placed between character and `Icon`.
[`> ${token.iconCls} + span, > span + ${token.iconCls}`]: {
marginInlineStart: paddingInline,
},
},
[`${componentCls}-borderless`]: {
borderColor: 'transparent',
background: token.tagBorderlessBg,
},
};
};
// ============================== Export ==============================
export default genComponentStyleHook('Tag', token => {
const { fontSize, lineHeight, lineWidth, fontSizeIcon } = token;
const tagHeight = Math.round(fontSize * lineHeight);
const tagFontSize = token.fontSizeSM;
const tagLineHeight = tagHeight - lineWidth * 2;
const tagDefaultBg = token.colorFillAlter;
const tagDefaultColor = token.colorText;
const tagToken = mergeToken<TagToken>(token, {
tagFontSize,
tagLineHeight,
tagDefaultBg,
tagDefaultColor,
tagIconSize: fontSizeIcon - 2 * lineWidth, // Tag icon is much more smaller
tagPaddingHorizontal: 8, // Fixed padding.
tagBorderlessBg: token.colorFillTertiary,
});
return [
genBaseStyle(tagToken),
genPresetStyle(tagToken),
genTagStatusStyle(tagToken, 'success', 'Success'),
genTagStatusStyle(tagToken, 'processing', 'Info'),
genTagStatusStyle(tagToken, 'error', 'Error'),
genTagStatusStyle(tagToken, 'warning', 'Warning'),
];
});