Skip to content

Commit

Permalink
fix(modal): 添加showCancel属性,修复无icon是container宽度异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanaMaid committed Jul 8, 2018
1 parent 63c7290 commit 3484836
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
9 changes: 6 additions & 3 deletions components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface IModalProps extends IBaseComponent {
onClose?: () => void;
okText?: React.ReactNode;
cancelText?: React.ReactNode;
showCancel?: boolean;
title?: React.ReactNode;
content?: React.ReactNode;
bodyCotent?: React.ReactNode;
Expand All @@ -36,6 +37,7 @@ export class Modal extends Component<IModalComponentProps, IModalComponentState>
static defaultProps = {
zIndex: 1000,
width: 256,
showCancel: true,
};

state = {
Expand Down Expand Up @@ -75,7 +77,7 @@ export class Modal extends Component<IModalComponentProps, IModalComponentState>
render() {
const {
className, style, title, bodyCotent,
content, icon, width, zIndex,
content, icon, width, zIndex, showCancel,
okText, cancelText, type,
} = this.props;
const preCls = 'yoshino-modal';
Expand All @@ -88,6 +90,7 @@ export class Modal extends Component<IModalComponentProps, IModalComponentState>
warning: 'android-alert',
error: 'close-circled',
};
const hasIcon = type !== 'confirm' || icon;
return this.state.show ? (
<div
className={clsName}
Expand All @@ -104,7 +107,7 @@ export class Modal extends Component<IModalComponentProps, IModalComponentState>
</div>
) : null
}
<div className={`${preCls}-word-container`}>
<div className={`${preCls}-word-container ${!hasIcon ? `${preCls}-word-container-no-icon` : ''}`}>
<div className={`${preCls}-title`}>{title}</div>
<div className={`${preCls}-content`}>{content}</div>
</div>
Expand All @@ -114,7 +117,7 @@ export class Modal extends Component<IModalComponentProps, IModalComponentState>
</div>
<div className={`${preCls}-footer`}>
{
type === 'confirm' ? (
type === 'confirm' && showCancel ? (
<div className={`${preCls}-cancel`} onClick={this.onCancel}>
{
typeof cancelText === 'string' || !cancelText ? (
Expand Down
5 changes: 4 additions & 1 deletion components/Modal/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
display: inline-block;
width: calc(100% - @icon-width);
vertical-align: middle;


&-no-icon {
width: 100%;
}
}

&-footer {
Expand Down
6 changes: 6 additions & 0 deletions docs/pages/Modal/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ export default [
type: "ReactNode",
defaultValue: "-",
},
{
props: "showCancel",
intro: "是否显示取消按钮",
type: "boolean",
defaultValue: "false",
},
]
}
]
2 changes: 1 addition & 1 deletion docs/pages/Modal/demo/modalDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export default function () {

const autoClose = () => {
const ref =Modal.confirm({
icon: <Icon type='checkmark-round'/>,
title: '这是一个标题!!!',
content: '这是一个内容主题!这是一个内容主题!这是一个内容主题!这是一个内容主题!!',
width: 400,
showCancel: false,
});
setTimeout(() => {
Modal.close(ref);
Expand Down

0 comments on commit 3484836

Please sign in to comment.