1+ import { unit } from '../../_util/cssinjs' ;
12import type { CSSObject } from '../../_util/cssinjs' ;
2- import type { FullToken , GenerateStyle } from '../../theme/internal' ;
3- import { genComponentStyleHook , mergeToken } from '../../theme/internal' ;
3+ 44import { resetComponent } from '../../style' ;
5+ import type { FullToken , GenerateStyle , GetDefaultToken } from '../../theme/internal' ;
6+ import { genStyleHooks , mergeToken } from '../../theme/internal' ;
57
68export interface ComponentToken {
79 /**
8- * @desc 头像背景色
9- * @descEN Background color of Avatar
10+ * @desc 头像尺寸
11+ * @descEN Size of Avatar
1012 */
1113 containerSize : number ;
1214 /**
@@ -51,10 +53,14 @@ export interface ComponentToken {
5153 groupBorderColor : string ;
5254}
5355
56+ /**
57+ * @desc Avatar 组件的 Token
58+ * @descEN Token for Avatar component
59+ */
5460type AvatarToken = FullToken < 'Avatar' > & {
61+ avatarBgColor : string ;
5562 avatarBg : string ;
5663 avatarColor : string ;
57- avatarBgColor : string ;
5864} ;
5965
6066const genBaseStyle : GenerateStyle < AvatarToken > = token => {
@@ -81,22 +87,12 @@ const genBaseStyle: GenerateStyle<AvatarToken> = token => {
8187 const avatarSizeStyle = ( size : number , fontSize : number , radius : number ) : CSSObject => ( {
8288 width : size ,
8389 height : size ,
84- lineHeight : `${ size - lineWidth * 2 } px` ,
8590 borderRadius : '50%' ,
8691
8792 [ `&${ componentCls } -square` ] : {
8893 borderRadius : radius ,
8994 } ,
9095
91- [ `${ componentCls } -string` ] : {
92- position : 'absolute' ,
93- left : {
94- _skip_check_ : true ,
95- value : '50%' ,
96- } ,
97- transformOrigin : '0 center' ,
98- } ,
99- 10096 [ `&${ componentCls } -icon` ] : {
10197 fontSize,
10298 [ `> ${ iconCls } ` ] : {
@@ -109,16 +105,18 @@ const genBaseStyle: GenerateStyle<AvatarToken> = token => {
109105 [ componentCls ] : {
110106 ...resetComponent ( token ) ,
111107 position : 'relative' ,
112- display : 'inline-block' ,
108+ display : 'inline-flex' ,
109+ justifyContent : 'center' ,
110+ alignItems : 'center' ,
113111 overflow : 'hidden' ,
114112 color : avatarColor ,
115113 whiteSpace : 'nowrap' ,
116114 textAlign : 'center' ,
117115 verticalAlign : 'middle' ,
118116 background : avatarBg ,
119- border : `${ lineWidth } px ${ lineType } transparent` ,
117+ border : `${ unit ( lineWidth ) } ${ lineType } transparent` ,
120118
121- [ ` &-image` ] : {
119+ ' &-image' : {
122120 background : 'transparent' ,
123121 } ,
124122
@@ -128,11 +126,11 @@ const genBaseStyle: GenerateStyle<AvatarToken> = token => {
128126
129127 ...avatarSizeStyle ( containerSize , textFontSize , borderRadius ) ,
130128
131- [ ` &-lg` ] : {
129+ ' &-lg' : {
132130 ...avatarSizeStyle ( containerSizeLG , textFontSizeLG , borderRadiusLG ) ,
133131 } ,
134132
135- [ ` &-sm` ] : {
133+ ' &-sm' : {
136134 ...avatarSizeStyle ( containerSizeSM , textFontSizeSM , borderRadiusSM ) ,
137135 } ,
138136
@@ -153,11 +151,11 @@ const genGroupStyle: GenerateStyle<AvatarToken> = token => {
153151 [ `${ componentCls } -group` ] : {
154152 display : 'inline-flex' ,
155153
156- [ ` ${ componentCls } ` ] : {
154+ [ componentCls ] : {
157155 borderColor : groupBorderColor ,
158156 } ,
159157
160- [ ` > *:not(:first-child)` ] : {
158+ ' > *:not(:first-child)' : {
161159 marginInlineStart : groupOverlapping ,
162160 } ,
163161 } ,
@@ -169,7 +167,33 @@ const genGroupStyle: GenerateStyle<AvatarToken> = token => {
169167 } ;
170168} ;
171169
172- export default genComponentStyleHook (
170+ export const prepareComponentToken : GetDefaultToken < 'Avatar' > = token => {
171+ const {
172+ controlHeight,
173+ controlHeightLG,
174+ controlHeightSM,
175+ fontSize,
176+ fontSizeLG,
177+ fontSizeXL,
178+ fontSizeHeading3,
179+ marginXS,
180+ marginXXS,
181+ colorBorderBg,
182+ } = token ;
183+ return {
184+ containerSize : controlHeight ,
185+ containerSizeLG : controlHeightLG ,
186+ containerSizeSM : controlHeightSM ,
187+ textFontSize : Math . round ( ( fontSizeLG + fontSizeXL ) / 2 ) ,
188+ textFontSizeLG : fontSizeHeading3 ,
189+ textFontSizeSM : fontSize ,
190+ groupSpace : marginXXS ,
191+ groupOverlapping : - marginXS ,
192+ groupBorderColor : colorBorderBg ,
193+ } ;
194+ } ;
195+ 196+ export default genStyleHooks (
173197 'Avatar' ,
174198 token => {
175199 const { colorTextLightSolid, colorTextPlaceholder } = token ;
@@ -179,33 +203,5 @@ export default genComponentStyleHook(
179203 } ) ;
180204 return [ genBaseStyle ( avatarToken ) , genGroupStyle ( avatarToken ) ] ;
181205 } ,
182- token => {
183- const {
184- controlHeight,
185- controlHeightLG,
186- controlHeightSM,
187- 188- fontSize,
189- fontSizeLG,
190- fontSizeXL,
191- fontSizeHeading3,
192- 193- marginXS,
194- marginXXS,
195- colorBorderBg,
196- } = token ;
197- return {
198- containerSize : controlHeight ,
199- containerSizeLG : controlHeightLG ,
200- containerSizeSM : controlHeightSM ,
201- 202- textFontSize : Math . round ( ( fontSizeLG + fontSizeXL ) / 2 ) ,
203- textFontSizeLG : fontSizeHeading3 ,
204- textFontSizeSM : fontSize ,
205- 206- groupSpace : marginXXS ,
207- groupOverlapping : - marginXS ,
208- groupBorderColor : colorBorderBg ,
209- } ;
210- } ,
206+ prepareComponentToken ,
211207) ;
0 commit comments