From 3c05b56a2d4eb5f8da4b299ac4877e4ab3e1bfef Mon Sep 17 00:00:00 2001 From: zhujun24 Date: Thu, 30 Jul 2015 21:04:52 +0800 Subject: [PATCH] modify notification #88 --- components/notification/demo/basic.md | 24 ++++--------- components/notification/demo/onclose.md | 26 ++++---------- .../notification/demo/with-btn-onclose.md | 34 +++++++------------ components/notification/demo/with-btn.md | 22 +++--------- components/notification/demo/with-icon.md | 22 +++--------- components/notification/index.jsx | 31 +++++++++-------- components/notification/index.md | 8 ++--- 7 files changed, 57 insertions(+), 110 deletions(-) diff --git a/components/notification/demo/basic.md b/components/notification/demo/basic.md index bf6281ac8d..f9b627f63e 100644 --- a/components/notification/demo/basic.md +++ b/components/notification/demo/basic.md @@ -7,29 +7,17 @@ --- ````jsx -var Notification = require('antd/lib/notification'); - -if(!Notification.notification){ - Notification.notification = Notification.newInstance({ - prefixCls: 'ant-notification', - style: { - top: 0, - right: 0 - } - }); -} +var notification = require('antd/lib/notification'); var openNotification = function() { var args = { message: "这是标题", description: "这是提示框的文案这是提示框的文案这是提示框的文案这是提示框的文案这是提示框的文案这是提示框的文案这是提示框的文案" - }; - Notification.show(args); -} + }; + notification.show(args); +}; React.render( -
- -
, -document.getElementById('components-notification-demo-basic')); + +, document.getElementById('components-notification-demo-basic')); ```` \ No newline at end of file diff --git a/components/notification/demo/onclose.md b/components/notification/demo/onclose.md index 8436404601..95a2efb20c 100644 --- a/components/notification/demo/onclose.md +++ b/components/notification/demo/onclose.md @@ -7,34 +7,22 @@ --- ````jsx -var Notification = require('antd/lib/notification'); - -if(!Notification.notification){ - Notification.notification = Notification.newInstance({ - prefixCls: 'ant-notification', - style: { - top: 0, - right: 0 - } - }); -} +var notification = require('antd/lib/notification'); var close = function() { console.log("我被默认的关闭按钮关闭了!"); -} +}; var openNotification = function() { var args = { message: "这是标题", description: "这是提示框的文案这是提示框示框的文案这是提示是提示框的文案这是提示框的文案", - defaultClose: close + onClose: close }; - Notification.show(args); -} + notification.show(args); +}; React.render( -
- -
, -document.getElementById('components-notification-demo-onclose')); + +, document.getElementById('components-notification-demo-onclose')); ```` \ No newline at end of file diff --git a/components/notification/demo/with-btn-onclose.md b/components/notification/demo/with-btn-onclose.md index 13e72ea1cd..f32f058c92 100644 --- a/components/notification/demo/with-btn-onclose.md +++ b/components/notification/demo/with-btn-onclose.md @@ -7,25 +7,19 @@ --- ````jsx -var Notification = require('antd/lib/notification'); +var notification = require('antd/lib/notification'); -if(!Notification.notification){ - Notification.notification = Notification.newInstance({ - prefixCls: 'ant-notification', - style: { - top: 0, - right: 0 - } - }); -} - -var customClose = function() { +var customClose = function(key) { + // 自定义按钮关闭时的业务处理 console.log("我被自定义的关闭按钮关闭了!"); -} + // 隐藏提醒框 + notification.notification.removeNotice(key); +}; var close = function() { + // 默认按钮关闭时的业务处理 console.log("我被默认的关闭按钮关闭了!"); -} +}; var btn = ; @@ -35,14 +29,12 @@ var openNotification = function() { description: "这是提示框的文案这是提示框示框的文案这是提示是提示框的文案这是提示框的文案", btn: btn, customClose: customClose, - defaultClose: close + onClose: close }; - Notification.show(args); -} + notification.show(args); +}; React.render( -
- -
, -document.getElementById('components-notification-demo-with-btn-onclose')); + +, document.getElementById('components-notification-demo-with-btn-onclose')); ```` \ No newline at end of file diff --git a/components/notification/demo/with-btn.md b/components/notification/demo/with-btn.md index 0e1cde950b..58536df7ed 100644 --- a/components/notification/demo/with-btn.md +++ b/components/notification/demo/with-btn.md @@ -7,17 +7,7 @@ --- ````jsx -var Notification = require('antd/lib/notification'); - -if(!Notification.notification){ - Notification.notification = Notification.newInstance({ - prefixCls: 'ant-notification', - style: { - top: 0, - right: 0 - } - }); -} +var notification = require('antd/lib/notification'); var btn = ; @@ -27,12 +17,10 @@ var openNotification = function() { description: "这是提示框的文案这是提示框示框的文案这是提示是提示框的文案这是提示框的文案", btn: btn }; - Notification.show(args); -} + notification.show(args); +}; React.render( -
- -
, -document.getElementById('components-notification-demo-with-btn')); + +, document.getElementById('components-notification-demo-with-btn')); ```` \ No newline at end of file diff --git a/components/notification/demo/with-icon.md b/components/notification/demo/with-icon.md index 736a201801..cf5f56e30b 100644 --- a/components/notification/demo/with-icon.md +++ b/components/notification/demo/with-icon.md @@ -7,17 +7,7 @@ --- ````jsx -var Notification = require('antd/lib/notification'); - -if(!Notification.notification){ - Notification.notification = Notification.newInstance({ - prefixCls: 'ant-notification', - style: { - top: 0, - right: 0 - } - }); -} +var notification = require('antd/lib/notification'); var openNotification = function() { var args = { @@ -25,12 +15,10 @@ var openNotification = function() { description: "这是提示框的文案这是提示框示框的文案这是提示是提示框的文案这是提示框的文案", icon: true }; - Notification.show(args); -} + notification.show(args); +}; React.render( -
- -
, -document.getElementById('components-notification-demo-with-icon')); + +, document.getElementById('components-notification-demo-with-icon')); ```` \ No newline at end of file diff --git a/components/notification/index.jsx b/components/notification/index.jsx index 282e9f3b5e..b00920e1c9 100644 --- a/components/notification/index.jsx +++ b/components/notification/index.jsx @@ -1,13 +1,16 @@ import Notification from 'rc-notification'; -function close(key, customCallback) { - Notification.notification.removeNotice(key); - if (customCallback) { - customCallback(); - } -} - Notification.show = function (args) { + if (!Notification.notification) { + Notification.notification = Notification.newInstance({ + prefixCls: 'ant-notification', + style: { + top: 0, + right: 0 + } + }); + } + if (args.icon) { let prefixCls = 'ant-notification-notice-content-icon-'; Notification.notification.notice({ @@ -18,7 +21,7 @@ Notification.show = function (args) { , duration: null, closable: true, - onClose: args.defaultClose, + onClose: args.onClose, style: {} }); } else { @@ -26,12 +29,12 @@ Notification.show = function (args) { let prefixCls = 'ant-notification-notice-content-'; Notification.notification.notice({ content:
-

{args.message}

-

{args.description}

-
, +

{args.message}

+

{args.description}

+ , duration: null, closable: true, - onClose: args.defaultClose, + onClose: args.onClose, style: {} }); } else { @@ -41,13 +44,13 @@ Notification.show = function (args) { content:

{args.message}

{args.description}

- + {args.btn}
, duration: null, closable: true, - onClose: args.defaultClose, + onClose: args.onClose, key: key, style: {} }); diff --git a/components/notification/index.md b/components/notification/index.md index 8a600c9442..a41d35f53a 100644 --- a/components/notification/index.md +++ b/components/notification/index.md @@ -17,7 +17,7 @@ |----------- |--------------------------------------------- | ----------- |--------| | message | 通知提醒标题,必选 | String | 无 | | description | 通知提醒内容,必选 | String | 无 | -| icon | 框的左侧有Icon | Boolean | false | -| btn | 自定义关闭按钮的文字 | String | 无 | -| defaultClose | 默认关闭按钮关闭时触发的回调函数 | Function | 无 | -| customClose | 自定义关闭按钮关闭时触发的回调函数 | Function | 无 | +| icon | 通知提醒框的左侧有Icon | Boolean | false | +| btn | 自定义关闭按钮 | String | 无 | +| onClose | 点击默认关闭按钮时触发的回调函数 | Function | 无 | +| customClose | 点击自定义按钮时触发的回调函数 | Function | 无 |