1
+ import type { CSSProperties } from 'vue' ;
1
2
import type { CSSObject } from '../../_util/cssinjs' ;
2
- import type { FullToken , GenerateStyle } from '../../theme/internal ' ;
3
- import { genComponentStyleHook , mergeToken } from '../../theme/internal' ;
3
+ import { unit } from '../../_util/cssinjs ' ;
4
+
4
5
import { resetComponent } from '../../style' ;
6
+ import type { FullToken , GenerateStyle , GetDefaultToken } from '../../theme/internal' ;
7
+ import { genStyleHooks , mergeToken } from '../../theme/internal' ;
5
8
6
9
/** Component only token. Which will handle additional calculation of alias token */
7
10
export interface ComponentToken {
8
- sizePaddingEdgeHorizontal : number ;
11
+ /**
12
+ * @desc 文本横向内间距
13
+ * @descEN Horizontal padding of text
14
+ */
15
+ textPaddingInline : CSSProperties [ 'paddingInline' ] ;
16
+ /**
17
+ * @desc 文本与边缘距离,取值 0 ~ 1
18
+ * @descEN Distance between text and edge, which should be a number between 0 and 1.
19
+ */
20
+ orientationMargin : number ;
21
+ /**
22
+ * @desc 纵向分割线的横向外间距
23
+ * @descEN Horizontal margin of vertical Divider
24
+ */
25
+ verticalMarginInline : CSSProperties [ 'marginInline' ] ;
9
26
}
10
27
28
+ /**
29
+ * @desc Divider 组件的 Token
30
+ * @descEN Token for Divider component
31
+ */
11
32
interface DividerToken extends FullToken < 'Divider' > {
12
- dividerVerticalGutterMargin : number ;
13
- dividerHorizontalWithTextGutterMargin : number ;
14
- dividerHorizontalGutterMargin : number ;
33
+ /**
34
+ * @desc 尺寸边距
35
+ * @descEN Size padding edge horizontal
36
+ */
37
+ sizePaddingEdgeHorizontal : number | string ;
38
+ /**
39
+ * @desc 带文本的水平分割线的外边距
40
+ * @descEN Horizontal margin of divider with text
41
+ */
42
+ dividerHorizontalWithTextGutterMargin : number | string ;
43
+ /**
44
+ * @desc 水平分割线的外边距
45
+ * @descEN Horizontal margin of divider
46
+ */
47
+ dividerHorizontalGutterMargin : number | string ;
15
48
}
16
49
17
50
// ============================== Shared ==============================
18
51
const genSharedDividerStyle : GenerateStyle < DividerToken > = ( token ) : CSSObject => {
19
- const { componentCls, sizePaddingEdgeHorizontal, colorSplit, lineWidth } = token ;
52
+ const {
53
+ componentCls,
54
+ sizePaddingEdgeHorizontal,
55
+ colorSplit,
56
+ lineWidth,
57
+ textPaddingInline,
58
+ orientationMargin,
59
+ verticalMarginInline,
60
+ } = token ;
20
61
21
62
return {
22
63
[ componentCls ] : {
23
64
...resetComponent ( token ) ,
24
- borderBlockStart : `${ lineWidth } px solid ${ colorSplit } ` ,
65
+ borderBlockStart : `${ unit ( lineWidth ) } solid ${ colorSplit } ` ,
25
66
26
67
// vertical
27
68
'&-vertical' : {
28
69
position : 'relative' ,
29
70
top : '-0.06em' ,
30
71
display : 'inline-block' ,
31
72
height : '0.9em' ,
32
- margin : `0 ${ token . dividerVerticalGutterMargin } px` ,
73
+ marginInline : verticalMarginInline ,
74
+ marginBlock : 0 ,
33
75
verticalAlign : 'middle' ,
34
76
borderTop : 0 ,
35
- borderInlineStart : `${ lineWidth } px solid ${ colorSplit } ` ,
77
+ borderInlineStart : `${ unit ( lineWidth ) } solid ${ colorSplit } ` ,
36
78
} ,
37
79
38
80
'&-horizontal' : {
39
81
display : 'flex' ,
40
82
clear : 'both' ,
41
83
width : '100%' ,
42
84
minWidth : '100%' , // Fix https://github.com/ant-design/ant-design/issues/10914
43
- margin : `${ token . dividerHorizontalGutterMargin } px 0` ,
85
+ margin : `${ unit ( token . dividerHorizontalGutterMargin ) } 0` ,
44
86
} ,
45
87
46
88
[ `&-horizontal${ componentCls } -with-text` ] : {
47
89
display : 'flex' ,
48
90
alignItems : 'center' ,
49
- margin : `${ token . dividerHorizontalWithTextGutterMargin } px 0` ,
91
+ margin : `${ unit ( token . dividerHorizontalWithTextGutterMargin ) } 0` ,
50
92
color : token . colorTextHeading ,
51
93
fontWeight : 500 ,
52
94
fontSize : token . fontSizeLG ,
@@ -57,7 +99,7 @@ const genSharedDividerStyle: GenerateStyle<DividerToken> = (token): CSSObject =>
57
99
'&::before, &::after' : {
58
100
position : 'relative' ,
59
101
width : '50%' ,
60
- borderBlockStart : `${ lineWidth } px solid transparent` ,
102
+ borderBlockStart : `${ unit ( lineWidth ) } solid transparent` ,
61
103
// Chrome not accept `inherit` in `border-top`
62
104
borderBlockStartColor : 'inherit' ,
63
105
borderBlockEnd : 0 ,
@@ -68,34 +110,33 @@ const genSharedDividerStyle: GenerateStyle<DividerToken> = (token): CSSObject =>
68
110
69
111
[ `&-horizontal${ componentCls } -with-text-left` ] : {
70
112
'&::before' : {
71
- width : '5%' ,
113
+ width : `calc( ${ orientationMargin } * 100%)` ,
72
114
} ,
73
-
74
115
'&::after' : {
75
- width : '95%' ,
116
+ width : `calc(100% - ${ orientationMargin } * 100%)` ,
76
117
} ,
77
118
} ,
78
119
79
120
[ `&-horizontal${ componentCls } -with-text-right` ] : {
80
121
'&::before' : {
81
- width : '95%' ,
122
+ width : `calc(100% - ${ orientationMargin } * 100%)` ,
82
123
} ,
83
-
84
124
'&::after' : {
85
- width : '5%' ,
125
+ width : `calc( ${ orientationMargin } * 100%)` ,
86
126
} ,
87
127
} ,
88
128
89
129
[ `${ componentCls } -inner-text` ] : {
90
130
display : 'inline-block' ,
91
- padding : '0 1em' ,
131
+ paddingBlock : 0 ,
132
+ paddingInline : textPaddingInline ,
92
133
} ,
93
134
94
135
'&-dashed' : {
95
136
background : 'none' ,
96
137
borderColor : colorSplit ,
97
138
borderStyle : 'dashed' ,
98
- borderWidth : `${ lineWidth } px 0 0` ,
139
+ borderWidth : `${ unit ( lineWidth ) } 0 0` ,
99
140
} ,
100
141
101
142
[ `&-horizontal${ componentCls } -with-text${ componentCls } -dashed` ] : {
@@ -111,6 +152,26 @@ const genSharedDividerStyle: GenerateStyle<DividerToken> = (token): CSSObject =>
111
152
borderBlockEnd : 0 ,
112
153
} ,
113
154
155
+ '&-dotted' : {
156
+ background : 'none' ,
157
+ borderColor : colorSplit ,
158
+ borderStyle : 'dotted' ,
159
+ borderWidth : `${ unit ( lineWidth ) } 0 0` ,
160
+ } ,
161
+
162
+ [ `&-horizontal${ componentCls } -with-text${ componentCls } -dotted` ] : {
163
+ '&::before, &::after' : {
164
+ borderStyle : 'dotted none none' ,
165
+ } ,
166
+ } ,
167
+
168
+ [ `&-vertical${ componentCls } -dotted` ] : {
169
+ borderInlineStartWidth : lineWidth ,
170
+ borderInlineEnd : 0 ,
171
+ borderBlockStart : 0 ,
172
+ borderBlockEnd : 0 ,
173
+ } ,
174
+
114
175
[ `&-plain${ componentCls } -with-text` ] : {
115
176
color : token . colorText ,
116
177
fontWeight : 'normal' ,
@@ -150,18 +211,27 @@ const genSharedDividerStyle: GenerateStyle<DividerToken> = (token): CSSObject =>
150
211
} ;
151
212
} ;
152
213
214
+ export const prepareComponentToken : GetDefaultToken < 'Divider' > = token => ( {
215
+ textPaddingInline : '1em' ,
216
+ orientationMargin : 0.05 ,
217
+ verticalMarginInline : token . marginXS ,
218
+ } ) ;
219
+
153
220
// ============================== Export ==============================
154
- export default genComponentStyleHook (
221
+ export default genStyleHooks (
155
222
'Divider' ,
156
223
token => {
157
224
const dividerToken = mergeToken < DividerToken > ( token , {
158
- dividerVerticalGutterMargin : token . marginXS ,
159
225
dividerHorizontalWithTextGutterMargin : token . margin ,
160
226
dividerHorizontalGutterMargin : token . marginLG ,
227
+ sizePaddingEdgeHorizontal : 0 ,
161
228
} ) ;
162
229
return [ genSharedDividerStyle ( dividerToken ) ] ;
163
230
} ,
231
+ prepareComponentToken ,
164
232
{
165
- sizePaddingEdgeHorizontal : 0 ,
233
+ unitless : {
234
+ orientationMargin : true ,
235
+ } ,
166
236
} ,
167
237
) ;
0 commit comments