2022-03-29 13:56:19 +08:00
|
|
|
// import '../../style/index.less';
|
|
|
|
// import './index.less';
|
2020-07-13 12:45:37 +08:00
|
|
|
|
2022-03-29 13:56:19 +08:00
|
|
|
// // style dependencies
|
|
|
|
// // deps-lint-skip: grid
|
|
|
|
// import '../../popover/style';
|
|
|
|
|
|
|
|
// deps-lint-skip-all
|
2022-04-07 21:50:35 +08:00
|
|
|
import { CSSObject } from '@ant-design/cssinjs';
|
2022-04-11 16:04:00 +08:00
|
|
|
import {
|
|
|
|
GenerateStyle,
|
|
|
|
resetComponent,
|
|
|
|
FullToken,
|
|
|
|
genComponentStyleHook,
|
|
|
|
mergeToken,
|
|
|
|
} from '../../_util/theme';
|
2022-04-07 21:50:35 +08:00
|
|
|
|
|
|
|
type AvatarToken = FullToken<'Avatar'> & {
|
2022-03-29 13:56:19 +08:00
|
|
|
avatarBg: string;
|
|
|
|
avatarColor: string;
|
|
|
|
avatarSizeBase: number;
|
|
|
|
avatarSizeLG: number;
|
|
|
|
avatarSizeSM: number;
|
|
|
|
avatarFontSizeBase: number;
|
|
|
|
avatarFontSizeLG: number;
|
|
|
|
avatarFontSizeSM: number;
|
|
|
|
avatarBorderRadius: number;
|
|
|
|
avatarGroupBorderColor: string;
|
|
|
|
avatarGroupOverlapping: number;
|
|
|
|
avatarGroupSpace: number;
|
2022-04-07 21:50:35 +08:00
|
|
|
};
|
2022-03-29 13:56:19 +08:00
|
|
|
|
|
|
|
const avatarSizeStyle = (
|
|
|
|
avatarCls: string,
|
2022-04-07 21:50:35 +08:00
|
|
|
iconCls: string,
|
2022-03-29 13:56:19 +08:00
|
|
|
size: number,
|
|
|
|
fontSize: number,
|
|
|
|
): CSSObject => ({
|
|
|
|
width: size,
|
|
|
|
height: size,
|
|
|
|
lineHeight: `${size}px`,
|
|
|
|
borderRadius: '50%',
|
|
|
|
|
|
|
|
[`${avatarCls}-string`]: {
|
|
|
|
position: 'absolute',
|
|
|
|
insetInlineStart: '50%',
|
|
|
|
transformOrigin: '0 center',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&${avatarCls}-icon`]: {
|
|
|
|
fontSize,
|
2022-04-07 21:50:35 +08:00
|
|
|
[`> ${iconCls}`]: {
|
2022-03-29 13:56:19 +08:00
|
|
|
margin: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const genBaseStyle: GenerateStyle<AvatarToken> = token => {
|
|
|
|
const {
|
2022-04-07 21:50:35 +08:00
|
|
|
antCls,
|
|
|
|
componentCls,
|
|
|
|
iconCls,
|
2022-03-29 13:56:19 +08:00
|
|
|
avatarBg,
|
|
|
|
avatarColor,
|
|
|
|
avatarSizeBase,
|
|
|
|
avatarSizeLG,
|
|
|
|
avatarSizeSM,
|
|
|
|
avatarFontSizeBase,
|
|
|
|
avatarFontSizeLG,
|
|
|
|
avatarFontSizeSM,
|
|
|
|
avatarBorderRadius,
|
|
|
|
} = token;
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
|
[`&-image`]: {
|
|
|
|
background: 'transparent',
|
|
|
|
},
|
|
|
|
|
2022-04-07 21:50:35 +08:00
|
|
|
[`${antCls}-image-img`]: {
|
2022-03-29 13:56:19 +08:00
|
|
|
display: 'block',
|
|
|
|
},
|
|
|
|
|
2022-04-07 21:50:35 +08:00
|
|
|
...avatarSizeStyle(componentCls, iconCls, avatarSizeBase, avatarFontSizeBase),
|
2022-03-29 13:56:19 +08:00
|
|
|
|
|
|
|
[`&-lg`]: {
|
2022-04-07 21:50:35 +08:00
|
|
|
...avatarSizeStyle(componentCls, iconCls, avatarSizeLG, avatarFontSizeLG),
|
2022-03-29 13:56:19 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&-sm`]: {
|
2022-04-07 21:50:35 +08:00
|
|
|
...avatarSizeStyle(componentCls, iconCls, avatarSizeSM, avatarFontSizeSM),
|
2022-03-29 13:56:19 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&-square`]: {
|
|
|
|
borderRadius: avatarBorderRadius,
|
|
|
|
},
|
|
|
|
|
|
|
|
'> img': {
|
|
|
|
display: 'block',
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
|
|
|
objectFit: 'cover',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const genGroupStyle: GenerateStyle<AvatarToken> = token => {
|
2022-04-07 21:50:35 +08:00
|
|
|
const { componentCls, avatarGroupBorderColor, avatarGroupOverlapping, avatarGroupSpace } = 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}`]: {
|
2022-03-29 13:56:19 +08:00
|
|
|
border: `1px solid ${avatarGroupBorderColor}`,
|
|
|
|
|
|
|
|
[`&:not(:first-child)`]: {
|
|
|
|
marginInlineStart: avatarGroupOverlapping,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&-popover`]: {
|
2022-04-07 21:50:35 +08:00
|
|
|
[`${componentCls} + ${componentCls}`]: {
|
2022-03-29 13:56:19 +08:00
|
|
|
marginInlineStart: avatarGroupSpace,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-04-07 21:50:35 +08:00
|
|
|
export default genComponentStyleHook('Avatar', token => {
|
2022-04-11 16:04:00 +08:00
|
|
|
const avatarToken = mergeToken<AvatarToken>(token, {
|
2022-03-29 13:56:19 +08:00
|
|
|
// FIXME
|
|
|
|
avatarBg: '#ccc',
|
|
|
|
// FIXME
|
|
|
|
avatarColor: '#fff',
|
|
|
|
// FIXME
|
|
|
|
avatarSizeBase: 32,
|
|
|
|
avatarSizeLG: 40,
|
|
|
|
avatarSizeSM: 24,
|
|
|
|
avatarFontSizeBase: 18,
|
|
|
|
avatarFontSizeLG: 24,
|
|
|
|
avatarFontSizeSM: 14,
|
|
|
|
avatarBorderRadius: token.radiusBase,
|
|
|
|
// FIXME
|
|
|
|
avatarGroupBorderColor: '#fff',
|
|
|
|
avatarGroupOverlapping: -8,
|
|
|
|
avatarGroupSpace: 3,
|
2022-04-11 16:04:00 +08:00
|
|
|
});
|
2022-03-29 13:56:19 +08:00
|
|
|
|
|
|
|
return [genBaseStyle(avatarToken), genGroupStyle(avatarToken)];
|
2022-04-07 21:50:35 +08:00
|
|
|
});
|