diff --git a/components/notification/demo/top.md b/components/notification/demo/duration.md similarity index 65% rename from components/notification/demo/top.md rename to components/notification/demo/duration.md index 947145f26..11f35ba84 100644 --- a/components/notification/demo/top.md +++ b/components/notification/demo/duration.md @@ -1,26 +1,24 @@ -# 距离顶部距离 +# 自动关闭的延时 - order: 1 -自定义通知框距离顶部的距离,在`config`方法里设置`top`的值, **只在初始化时设置有效** ,默认距离顶部`24px`。 +自定义通知框自动关闭的延时,默认`3s`,取消自动关闭只要将该值设为`0`即可。 --- ````jsx var notification = require('antd/lib/notification'); -notification.config({ - top: 100 -}); var openNotification = function() { var args = { message: "这是标题", description: "这是提示框的文案这是提示框的文案这是提示框的文案这是提示框的文案这是提示框的文案这是提示框的文案这是提示框的文案", + duration: 10 }; notification.open(args); }; React.render( -, document.getElementById('components-notification-demo-top')); +, document.getElementById('components-notification-demo-duration')); ```` diff --git a/components/notification/index.jsx b/components/notification/index.jsx index 6b045fca0..771b667a4 100644 --- a/components/notification/index.jsx +++ b/components/notification/index.jsx @@ -3,6 +3,7 @@ import assign from 'object-assign'; import React from 'react'; let top = 24; +let duration = 3; var notificationInstance; @@ -46,7 +47,7 @@ function notice(args) {
{args.description}
, - duration: null, + duration: isNaN(args.duration) ? duration : args.duration, closable: true, onClose: args.onClose, style: {} @@ -60,7 +61,7 @@ function notice(args) {{args.description}
, - duration: null, + duration: isNaN(args.duration) ? duration : args.duration, closable: true, onClose: args.onClose, style: {} @@ -75,7 +76,7 @@ function notice(args) { {args.btn} , - duration: null, + duration: isNaN(args.duration) ? duration : args.duration, closable: true, onClose: args.onClose, key: args.key, diff --git a/components/notification/index.md b/components/notification/index.md index 62727786b..990fb0646 100644 --- a/components/notification/index.md +++ b/components/notification/index.md @@ -26,8 +26,9 @@ config 参数如下: |----------- |--------------------------------------------- | ----------- |--------| | message | 通知提醒标题,必选 | React.Element or String | 无 | | description | 通知提醒内容,必选 | React.Element or String | 无 | +| duration | 通知提醒自动关闭延时,值为`0`表示不自动关闭 | Number | 3 | | btn | 自定义关闭按钮 | React.Element | 无 | -| key | 当前通知唯一标志 | String | 无 | +| key | 当前通知唯一标志 | String | 无 | | onClose | 点击默认关闭按钮时触发的回调函数 | Function | 无 | 还提供了一个全局配置方法: