Skip to content

Commit

Permalink
feat(Message): can remove icon by iconType: false
Browse files Browse the repository at this point in the history
Co-authored-by: ranrui.cwj <[email protected]>
  • Loading branch information
2 people authored and 潕量 committed Mar 25, 2022
1 parent 3768a0d commit b0f732e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/message/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
| children | 内容 | ReactNode | - |
| defaultVisible | 默认是否显示 | Boolean | true |
| visible | 当前是否显示 | Boolean | - |
| iconType | 显示的图标类型,会覆盖内部设置的IconType | String | - |
| iconType | 显示的图标类型,会覆盖内部设置的IconType,传false不显示图标 | String \| false | - |
| closeable | 显示关闭按钮 | Boolean | false |
| onClose | 关闭按钮的回调<br/><br/>**签名**:<br/>Function() => void | Function | () => {} |
| afterClose | 关闭之后调用的函数<br/><br/>**签名**:<br/>Function() => void | Function | () => {} |
Expand Down
16 changes: 9 additions & 7 deletions src/message/message.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ class Message extends Component {
*/
visible: PropTypes.bool,
/**
* 显示的图标类型,会覆盖内部设置的IconType
* 显示的图标类型,会覆盖内部设置的IconType,传false不显示图标
*/
iconType: PropTypes.string,
iconType: PropTypes.string | false,
/**
* 显示关闭按钮
*/
Expand Down Expand Up @@ -175,11 +175,13 @@ class Message extends Component {
<Icon type="close" />
</a>
) : null}
<Icon
className={`${messagePrefix}-symbol ${!icon &&
`${messagePrefix}-symbol-icon`}`}
type={icon}
/>
{icon !== false ? (
<Icon
className={`${messagePrefix}-symbol ${!icon &&
`${messagePrefix}-symbol-icon`}`}
type={icon}
/>
) : null}
{title ? (
<div className={`${messagePrefix}-title`}>{title}</div>
) : null}
Expand Down
6 changes: 6 additions & 0 deletions test/message/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ describe('Message', () => {
wrapper.unmount();
});

it('should not show icon if set iconType to false', () => {
const wrapper = mount(<Message iconType={false} />);
assert(wrapper.find(Icon).length === 0);
wrapper.unmount();
});

it('should custom icon type', () => {
const wrapper = mount(<Message iconType="smile" />);
assert(wrapper.find(Icon).prop('type') === 'smile');
Expand Down
4 changes: 2 additions & 2 deletions types/message/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export interface MessageProps extends HTMLAttributesWeak, CommonProps {
visible?: boolean;

/**
* 显示的图标类型,会覆盖内部设置的IconType
* 显示的图标类型,会覆盖内部设置的IconType,传false不显示图标
*/
iconType?: string;
iconType?: string | false;

/**
* 显示关闭按钮
Expand Down

0 comments on commit b0f732e

Please sign in to comment.