allow user to override showIcon type of Alert[banner] (#5818)

This commit is contained in:
ddcat1115
2017-04-22 10:37:00 +08:00
committed by GitHub
parent 0a2fb1817f
commit c0125ff1ce
5 changed files with 42 additions and 10 deletions
@@ -42,6 +42,37 @@ exports[`renders ./components/alert/demo/banner.md correctly 1`] = `
/>
</a>
</div>
<br />
<div
class="ant-alert ant-alert-warning ant-alert-no-icon ant-alert-banner"
data-show="true"
>
<span
class="ant-alert-message"
>
Warning text without icon
</span>
<span
class="ant-alert-description"
/>
</div>
<br />
<div
class="ant-alert ant-alert-error ant-alert-banner"
data-show="true"
>
<i
class="anticon anticon-cross-circle ant-alert-icon"
/>
<span
class="ant-alert-message"
>
Error text
</span>
<span
class="ant-alert-description"
/>
</div>
</div>
`;
+5 -1
View File
@@ -1,6 +1,6 @@
---
order: 6
iframe: true
iframe: 250
title:
zh-CN: 顶部公告
en-US: Banner
@@ -22,6 +22,10 @@ ReactDOM.render(
<Alert message="Warning text" banner />
<br />
<Alert message="Very long warning text warning text text text text text text text" banner closable />
<br />
<Alert showIcon={false} message="Warning text without icon" banner />
<br />
<Alert type="error" message="Error text" banner />
</div>
, mountNode);
````
+2 -2
View File
@@ -15,11 +15,11 @@ Alert component for feedback.
| Property | Description | Type | Default |
|----------- |--------------------------------------------------------- | ---------- |-------|
| type | Type of Alert styles, options:`success`, `info`, `warning`, `error` | string | `info` |
| type | Type of Alert styles, options:`success`, `info`, `warning`, `error` | string | `info`, in `banner` mode it's `warning` |
| closable | Whether Alert can be closed | boolean | - |
| closeText | Close text to show | string\|ReactNode | - |
| message | Content of Alert | string\|ReactNode | - |
| description | Additional content of Alert | string\|ReactNode | - |
| onClose | Callback when close Alert | Function | - |
| showIcon | Whether to show icon | boolean | false |
| showIcon | Whether to show icon | boolean | false, in `banner` mode it's true |
| banner | Whether to show as banner | boolean | false |
+2 -5
View File
@@ -30,9 +30,6 @@ export interface AlertProps {
}
export default class Alert extends React.Component<AlertProps, any> {
static defaultProps = {
type: 'info',
};
constructor(props) {
super(props);
this.state = {
@@ -66,9 +63,9 @@ export default class Alert extends React.Component<AlertProps, any> {
} = this.props;
// banner模式默认有 Icon
showIcon = showIcon || banner;
showIcon = banner && showIcon === undefined ? true : showIcon;
// banner模式默认为警告
type = banner ? 'warning' : type;
type = banner && type === undefined ? 'warning' : type || 'info';
let iconType = '';
switch (type) {
+2 -2
View File
@@ -16,12 +16,12 @@ title: Alert
| 参数 | 说明 | 类型 | 默认值 |
|----------- |--------------------------------------------------------- | ---------- |-------|
| type | 指定警告提示的样式,有四种选择 `success``info``warning``error` | string | `info` |
| type | 指定警告提示的样式,有四种选择 `success``info``warning``error` | string | `info``banner` 模式下默认值为 `warning` |
| closable | 默认不显示关闭按钮 | boolean | 无 |
| closeText | 自定义关闭按钮 | string\|ReactNode | 无 |
| message | 警告提示内容 | string\|ReactNode | 无 |
| description | 警告提示的辅助性文字介绍 | string\|ReactNode | 无 |
| onClose | 关闭时触发的回调函数 | Function | 无 |
| showIcon | 是否显示辅助图标 | boolean | false |
| showIcon | 是否显示辅助图标 | boolean | false`banner` 模式下默认值为 true |
| banner | 是否用作顶部公告 | boolean | false |