fix: fixed an issue where the avatar size control could change

pull/146/head
moonrailgun 2 years ago
parent 7900a3e17f
commit d1035cc57c

@ -33,33 +33,34 @@ const _Avatar: React.FC<AvatarProps> = React.memo((_props) => {
[src, props.icon, props.name] [src, props.icon, props.name]
); );
const style: React.CSSProperties = useMemo( const style = useMemo(() => {
() => ({ const _style: React.CSSProperties = {
userSelect: 'none', userSelect: 'none',
...props.style, ...props.style,
backgroundColor: color, backgroundColor: color,
display: 'flex', display: 'flex',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
}), };
[props.style, color]
);
if (_isNumber(props.size)) { if (_isNumber(props.size)) {
// 为了支持rem统一管理宽度将size转换为样式宽度(size类型上不支持rem单位) // 为了支持rem统一管理宽度将size转换为样式宽度(size类型上不支持rem单位)
if (!style.width) { if (!_style.width) {
style.width = px2rem(props.size); _style.width = px2rem(props.size);
} }
if (!style.height) { if (!_style.height) {
style.height = px2rem(props.size); _style.height = px2rem(props.size);
} }
if (typeof style.fontSize === 'undefined') { if (typeof _style.fontSize === 'undefined') {
// 如果props.size是数字且没有指定文字大小 // 如果props.size是数字且没有指定文字大小
// 则自动增加fontSize大小 // 则自动增加fontSize大小
style.fontSize = px2rem(props.size * 0.4); _style.fontSize = px2rem(props.size * 0.4);
}
} }
}
return _style;
}, [props.style, props.size, color]);
const inner = ( const inner = (
<AntdAvatar <AntdAvatar

Loading…
Cancel
Save