feat: Support SkeletonAvatarProps.size accept number (#16078) (#16128)

This commit is contained in:
He Linming 2019-04-19 01:06:20 +08:00 committed by zombieJ
parent 98fc8a14e0
commit 2ac02e0035
5 changed files with 47 additions and 3 deletions

View File

@ -27,7 +27,20 @@ class SkeletonAvatar extends React.Component<SkeletonAvatarProps, any> {
[`${prefixCls}-square`]: shape === 'square',
});
return <span className={classNames(prefixCls, className, sizeCls, shapeCls)} style={style} />;
const sizeStyle: React.CSSProperties =
typeof size === 'number'
? {
width: size,
height: size,
lineHeight: `${size}px`,
}
: {};
return (
<span
className={classNames(prefixCls, className, sizeCls, shapeCls)}
style={{ ...sizeStyle, ...style }}
/>
);
}
}

View File

@ -140,6 +140,35 @@ exports[`Skeleton avatar size 3`] = `
</div>
`;
exports[`Skeleton avatar size 4`] = `
<div
class="ant-skeleton ant-skeleton-with-avatar"
>
<div
class="ant-skeleton-header"
>
<span
class="ant-skeleton-avatar ant-skeleton-avatar-circle"
style="width: 20px; height: 20px; line-height: 20px;"
/>
</div>
<div
class="ant-skeleton-content"
>
<h3
class="ant-skeleton-title"
style="width: 50%;"
/>
<ul
class="ant-skeleton-paragraph"
>
<li />
<li />
</ul>
</div>
</div>
`;
exports[`Skeleton paragraph rows 1`] = `
<div
class="ant-skeleton"

View File

@ -18,6 +18,8 @@ describe('Skeleton', () => {
expect(wrapperDefault.render()).toMatchSnapshot();
const wrapperLarge = genSkeleton({ avatar: { size: 'large' } });
expect(wrapperLarge.render()).toMatchSnapshot();
const wrapperNumber = genSkeleton({ avatar: { size: 20 } });
expect(wrapperNumber.render()).toMatchSnapshot();
});
it('shape', () => {

View File

@ -29,7 +29,7 @@ Provide a placeholder at the place which need waiting for loading.
| Property | Description | Type | Default |
| --- | --- | --- | --- |
| size | Set the size of avatar | Enum{ 'large', 'small', 'default' } | - |
| size | Set the size of avatar | number \| Enum{ 'large', 'small', 'default' } | - |
| shape | Set the shape of avatar | Enum{ 'circle', 'square' } | - |
### SkeletonTitleProps

View File

@ -31,7 +31,7 @@ cols: 1
| 属性 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| size | 设置头像占位图的大小 | Enum{ 'large', 'small', 'default' } | - |
| size | 设置头像占位图的大小 | number \| Enum{ 'large', 'small', 'default' } | - |
| shape | 指定头像的形状 | Enum{ 'circle', 'square' } | - |
### SkeletonTitleProps