2023-11-29 17:23:45 +08:00
|
|
|
import { type CSSObject, unit } from '@ant-design/cssinjs';
|
2023-11-13 17:10:39 +08:00
|
|
|
|
2023-05-26 17:59:13 +08:00
|
|
|
import { resetComponent } from '../../style';
|
2023-11-13 17:10:39 +08:00
|
|
|
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
|
2023-11-29 17:23:45 +08:00
|
|
|
import { genStyleHooks, mergeToken } from '../../theme/internal';
|
2022-04-07 21:50:35 +08:00
|
|
|
|
2023-05-26 17:59:13 +08:00
|
|
|
export interface ComponentToken {
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
2023-09-05 23:19:06 +08:00
|
|
|
* @desc 头像尺寸
|
|
|
|
* @descEN Size of Avatar
|
2023-07-05 17:49:59 +08:00
|
|
|
*/
|
2023-05-26 17:59:13 +08:00
|
|
|
containerSize: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 大号头像尺寸
|
|
|
|
* @descEN Size of large Avatar
|
|
|
|
*/
|
2023-05-26 17:59:13 +08:00
|
|
|
containerSizeLG: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 小号头像尺寸
|
|
|
|
* @descEN Size of small Avatar
|
|
|
|
*/
|
2023-05-26 17:59:13 +08:00
|
|
|
containerSizeSM: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 头像文字大小
|
|
|
|
* @descEN Font size of Avatar
|
|
|
|
*/
|
2023-05-26 17:59:13 +08:00
|
|
|
textFontSize: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 大号头像文字大小
|
|
|
|
* @descEN Font size of large Avatar
|
|
|
|
*/
|
2023-05-26 17:59:13 +08:00
|
|
|
textFontSizeLG: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 小号头像文字大小
|
|
|
|
* @descEN Font size of small Avatar
|
|
|
|
*/
|
2023-05-26 17:59:13 +08:00
|
|
|
textFontSizeSM: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 头像组间距
|
|
|
|
* @descEN Spacing between avatars in a group
|
|
|
|
*/
|
2023-05-26 17:59:13 +08:00
|
|
|
groupSpace: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 头像组重叠宽度
|
|
|
|
* @descEN Overlapping of avatars in a group
|
|
|
|
*/
|
2023-05-26 17:59:13 +08:00
|
|
|
groupOverlapping: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 头像组边框颜色
|
|
|
|
* @descEN Border color of avatars in a group
|
|
|
|
*/
|
2023-05-26 17:59:13 +08:00
|
|
|
groupBorderColor: string;
|
|
|
|
}
|
2022-05-27 13:37:24 +08:00
|
|
|
|
2022-04-07 21:50:35 +08:00
|
|
|
type AvatarToken = FullToken<'Avatar'> & {
|
2023-05-26 17:59:13 +08:00
|
|
|
avatarBgColor: string;
|
2022-03-29 13:56:19 +08:00
|
|
|
avatarBg: string;
|
|
|
|
avatarColor: string;
|
2022-04-07 21:50:35 +08:00
|
|
|
};
|
2022-03-29 13:56:19 +08:00
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
const genBaseStyle: GenerateStyle<AvatarToken> = (token) => {
|
2022-03-29 13:56:19 +08:00
|
|
|
const {
|
2022-04-07 21:50:35 +08:00
|
|
|
antCls,
|
|
|
|
componentCls,
|
|
|
|
iconCls,
|
2022-03-29 13:56:19 +08:00
|
|
|
avatarBg,
|
|
|
|
avatarColor,
|
2023-05-26 17:59:13 +08:00
|
|
|
containerSize,
|
|
|
|
containerSizeLG,
|
|
|
|
containerSizeSM,
|
|
|
|
textFontSize,
|
|
|
|
textFontSizeLG,
|
|
|
|
textFontSizeSM,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius,
|
|
|
|
borderRadiusLG,
|
|
|
|
borderRadiusSM,
|
2022-05-27 13:37:24 +08:00
|
|
|
lineWidth,
|
|
|
|
lineType,
|
2023-11-13 17:10:39 +08:00
|
|
|
calc,
|
2022-03-29 13:56:19 +08:00
|
|
|
} = token;
|
|
|
|
|
2022-05-27 13:37:24 +08:00
|
|
|
// Avatar size style
|
2022-08-19 10:10:51 +08:00
|
|
|
const avatarSizeStyle = (size: number, fontSize: number, radius: number): CSSObject => ({
|
2022-05-27 13:37:24 +08:00
|
|
|
width: size,
|
|
|
|
height: size,
|
2023-11-13 17:10:39 +08:00
|
|
|
lineHeight: unit(calc(size).sub(calc(lineWidth).mul(2)).equal()),
|
2022-05-27 13:37:24 +08:00
|
|
|
borderRadius: '50%',
|
|
|
|
|
2022-08-19 10:10:51 +08:00
|
|
|
[`&${componentCls}-square`]: {
|
|
|
|
borderRadius: radius,
|
|
|
|
},
|
|
|
|
|
2022-05-27 13:37:24 +08:00
|
|
|
[`${componentCls}-string`]: {
|
|
|
|
position: 'absolute',
|
|
|
|
left: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: '50%',
|
|
|
|
},
|
|
|
|
transformOrigin: '0 center',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&${componentCls}-icon`]: {
|
|
|
|
fontSize,
|
|
|
|
[`> ${iconCls}`]: {
|
|
|
|
margin: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-03-29 13:56:19 +08:00
|
|
|
return {
|
2022-04-07 21:50:35 +08:00
|
|
|
[componentCls]: {
|
2022-03-29 13:56:19 +08:00
|
|
|
...resetComponent(token),
|
|
|
|
position: 'relative',
|
|
|
|
display: 'inline-block',
|
|
|
|
overflow: 'hidden',
|
|
|
|
color: avatarColor,
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
textAlign: 'center',
|
|
|
|
verticalAlign: 'middle',
|
|
|
|
background: avatarBg,
|
2023-11-13 17:10:39 +08:00
|
|
|
border: `${unit(lineWidth)} ${lineType} transparent`,
|
2022-03-29 13:56:19 +08:00
|
|
|
|
|
|
|
[`&-image`]: {
|
|
|
|
background: 'transparent',
|
|
|
|
},
|
|
|
|
|
2022-04-07 21:50:35 +08:00
|
|
|
[`${antCls}-image-img`]: {
|
2022-03-29 13:56:19 +08:00
|
|
|
display: 'block',
|
|
|
|
},
|
|
|
|
|
2023-05-26 17:59:13 +08:00
|
|
|
...avatarSizeStyle(containerSize, textFontSize, borderRadius),
|
2022-03-29 13:56:19 +08:00
|
|
|
|
|
|
|
[`&-lg`]: {
|
2023-05-26 17:59:13 +08:00
|
|
|
...avatarSizeStyle(containerSizeLG, textFontSizeLG, borderRadiusLG),
|
2022-03-29 13:56:19 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&-sm`]: {
|
2023-05-26 17:59:13 +08:00
|
|
|
...avatarSizeStyle(containerSizeSM, textFontSizeSM, borderRadiusSM),
|
2022-03-29 13:56:19 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'> img': {
|
|
|
|
display: 'block',
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
|
|
|
objectFit: 'cover',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
const genGroupStyle: GenerateStyle<AvatarToken> = (token) => {
|
2023-05-26 17:59:13 +08:00
|
|
|
const { componentCls, groupBorderColor, groupOverlapping, groupSpace } = token;
|
2022-03-29 13:56:19 +08:00
|
|
|
|
|
|
|
return {
|
2022-04-07 21:50:35 +08:00
|
|
|
[`${componentCls}-group`]: {
|
2022-03-29 13:56:19 +08:00
|
|
|
display: 'inline-flex',
|
|
|
|
|
2022-04-07 21:50:35 +08:00
|
|
|
[`${componentCls}`]: {
|
2023-05-26 17:59:13 +08:00
|
|
|
borderColor: groupBorderColor,
|
2022-03-29 13:56:19 +08:00
|
|
|
},
|
|
|
|
|
2023-01-04 17:31:31 +08:00
|
|
|
[`> *:not(:first-child)`]: {
|
2023-05-26 17:59:13 +08:00
|
|
|
marginInlineStart: groupOverlapping,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[`${componentCls}-group-popover`]: {
|
|
|
|
[`${componentCls} + ${componentCls}`]: {
|
|
|
|
marginInlineStart: groupSpace,
|
2022-03-29 13:56:19 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-11-13 17:10:39 +08:00
|
|
|
export const prepareComponentToken: GetDefaultToken<'Avatar'> = (token) => {
|
|
|
|
const {
|
|
|
|
controlHeight,
|
|
|
|
controlHeightLG,
|
|
|
|
controlHeightSM,
|
|
|
|
fontSize,
|
|
|
|
fontSizeLG,
|
|
|
|
fontSizeXL,
|
|
|
|
fontSizeHeading3,
|
|
|
|
marginXS,
|
|
|
|
marginXXS,
|
|
|
|
colorBorderBg,
|
|
|
|
} = token;
|
|
|
|
return {
|
|
|
|
containerSize: controlHeight,
|
|
|
|
containerSizeLG: controlHeightLG,
|
|
|
|
containerSizeSM: controlHeightSM,
|
|
|
|
textFontSize: Math.round((fontSizeLG + fontSizeXL) / 2),
|
|
|
|
textFontSizeLG: fontSizeHeading3,
|
|
|
|
textFontSizeSM: fontSize,
|
|
|
|
groupSpace: marginXXS,
|
|
|
|
groupOverlapping: -marginXS,
|
|
|
|
groupBorderColor: colorBorderBg,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-11-29 17:23:45 +08:00
|
|
|
export default genStyleHooks(
|
2023-05-26 17:59:13 +08:00
|
|
|
'Avatar',
|
|
|
|
(token) => {
|
|
|
|
const { colorTextLightSolid, colorTextPlaceholder } = token;
|
|
|
|
const avatarToken = mergeToken<AvatarToken>(token, {
|
|
|
|
avatarBg: colorTextPlaceholder,
|
|
|
|
avatarColor: colorTextLightSolid,
|
|
|
|
});
|
|
|
|
return [genBaseStyle(avatarToken), genGroupStyle(avatarToken)];
|
|
|
|
},
|
2023-11-13 17:10:39 +08:00
|
|
|
prepareComponentToken,
|
2023-05-26 17:59:13 +08:00
|
|
|
);
|