feat: Empty description support false value

This commit is contained in:
wadezhan 2019-07-15 23:24:20 +08:00
parent ac962a5bce
commit 61dc08f9c7
5 changed files with 30 additions and 5 deletions

View File

@ -7,4 +7,9 @@ describe('Empty', () => {
const wrapper = mount(<Empty imageStyle={{ height: 20 }} />);
expect(wrapper.find('.ant-empty-image').props().style.height).toBe(20);
});
it('description can be false', () => {
const wrapper = mount(<Empty description={false} />);
expect(wrapper.find('.ant-empty-description').length).toBe(0);
});
});

View File

@ -0,0 +1,20 @@
---
order: 0
title:
zh-CN: 无描述
en-US: Basic
---
## zh-CN
无描述展示。
## en-US
Simplest Usage with no description.
```jsx
import { Empty } from 'antd';
ReactDOM.render(<Empty description={false} />, mountNode);
```

View File

@ -22,7 +22,7 @@ Empty state placeholder.
| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
| description | Customize description | string \| ReactNode | - | 3.12.0 |
| description | Customize description | string \| ReactNode \| boolean | - | 3.12.0 |
| imageStyle | style of image | CSSProperties | - | 3.16.0 |
| image | Customize image. Will tread as image url when string provided. | string \| ReactNode | `Empty.PRESENTED_IMAGE_DEFAULT` | 3.12.0 |

View File

@ -18,7 +18,7 @@ export interface EmptyProps {
*/
imageStyle?: React.CSSProperties;
image?: React.ReactNode;
description?: React.ReactNode;
description?: React.ReactNode | boolean;
children?: React.ReactNode;
}
@ -39,7 +39,7 @@ const OriginEmpty: React.SFC<EmptyProps> = (props: EmptyProps) => (
<LocaleReceiver componentName="Empty">
{(locale: TransferLocale) => {
const prefixCls = getPrefixCls('empty', customizePrefixCls);
const des = description || locale.description;
const des = typeof description === 'boolean' ? description : (description || locale.description);
const alt = typeof des === 'string' ? des : 'empty';
let imageNode: React.ReactNode = null;
@ -64,7 +64,7 @@ const OriginEmpty: React.SFC<EmptyProps> = (props: EmptyProps) => (
<div className={`${prefixCls}-image`} style={imageStyle}>
{imageNode}
</div>
<p className={`${prefixCls}-description`}>{des}</p>
{des && <p className={`${prefixCls}-description`}>{des}</p>}
{children && <div className={`${prefixCls}-footer`}>{children}</div>}
</div>
);

View File

@ -23,7 +23,7 @@ cols: 1
| 参数 | 说明 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| description | 自定义描述内容 | string \| ReactNode | - | 3.12.0 |
| description | 自定义描述内容 | string \| ReactNode \| boolean | - | 3.12.0 |
| imageStyle | 图片样式 | CSSProperties | - | 3.16.0 |
| image | 设置显示图片,为 string 时表示自定义图片地址。 | string \| ReactNode | `Empty.PRESENTED_IMAGE_DEFAULT` | 3.12.0 |