add icon style and top

This commit is contained in:
zhujun24 2015-08-03 15:17:12 +08:00
parent 47606396c3
commit 4ef0ac9e9b
8 changed files with 111 additions and 27 deletions

View File

@ -1,6 +1,6 @@
# 回调函数 # 回调函数
- order: 2 - order: 3
点击关闭按钮时触发回调函数。 点击关闭按钮时触发回调函数。

View File

@ -0,0 +1,24 @@
# 距离顶部距离
- order: 1
自定义通知框距离顶部的距离, **只在初始化时设置有效** ,默认距离顶部`24px`。
---
````jsx
var notification = require('antd/lib/notification');
var openNotification = function() {
var args = {
message: "这是标题",
description: "这是提示框的文案这是提示框的文案这是提示框的文案这是提示框的文案这是提示框的文案这是提示框的文案这是提示框的文案",
top: 100
};
notification.open(args);
};
React.render(
<button className='ant-btn ant-btn-primary' onClick={openNotification}>距离顶部100px</button>
, document.getElementById('components-notification-demo-top'));
````

View File

@ -1,6 +1,6 @@
# 自定义关闭按钮同时触发回调函数 # 自定义关闭按钮同时触发回调函数
- order: 4 - order: 5
关闭自定义的关闭按钮时触发回调函数,同时还可以在默认关闭按钮上添加另一个回调函数。 关闭自定义的关闭按钮时触发回调函数,同时还可以在默认关闭按钮上添加另一个回调函数。

View File

@ -1,6 +1,6 @@
# 自定义关闭按钮 # 自定义关闭按钮
- order: 3 - order: 4
自定义关闭按钮的样式和文字。 自定义关闭按钮的样式和文字。

View File

@ -1,6 +1,6 @@
# 带有Icon的通知提醒框 # 带有Icon的通知提醒框
- order: 1 - order: 2
通知提醒框左侧有Icon图标。 通知提醒框左侧有Icon图标。
@ -9,16 +9,47 @@
````jsx ````jsx
var notification = require('antd/lib/notification'); var notification = require('antd/lib/notification');
var openNotification = function() { var openNotificationSuccess = function() {
var args = { var args = {
message: "这是标题", message: "这是标题",
description: "这是提示框的文案这是提示框示框的文案这是提示是提示框的文案这是提示框的文案", description: "这是提示框的文案这是提示框示框的文案这是提示是提示框的文案这是提示框的文案",
icon: true icon: "success"
}; };
notification.open(args); notification.open(args);
}; };
React.render( var openNotificationInfo = function() {
<button className="ant-btn ant-btn-primary" onClick={openNotification}>带有Icon的通知提醒框</button> var args = {
message: "这是标题",
description: "这是提示框的文案这是提示框示框的文案这是提示是提示框的文案这是提示框的文案",
icon: "info"
};
notification.open(args);
};
var openNotificationWarn = function() {
var args = {
message: "这是标题",
description: "这是提示框的文案这是提示框示框的文案这是提示是提示框的文案这是提示框的文案",
icon: "warn"
};
notification.open(args);
};
var openNotificationError = function() {
var args = {
message: "这是标题",
description: "这是提示框的文案这是提示框示框的文案这是提示是提示框的文案这是提示框的文案",
icon: "error"
};
notification.open(args);
};
React.render(<div>
<button className="ant-btn ant-btn-primary" onClick={openNotificationSuccess}>Success</button>
<button className="ant-btn ant-btn-primary" onClick={openNotificationInfo}>Info</button>
<button className="ant-btn ant-btn-primary" onClick={openNotificationWarn}>Warn</button>
<button className="ant-btn ant-btn-primary" onClick={openNotificationError}>Error</button>
</div>
, document.getElementById('components-notification-demo-with-icon')); , document.getElementById('components-notification-demo-with-icon'));
```` ````

View File

@ -1,11 +1,11 @@
import Notification from 'rc-notification'; import Notification from 'rc-notification';
function getNotificationInstance() { function getNotificationInstance(top) {
if (!Notification.notification) { if (!Notification.notification) {
Notification.notification = Notification.newInstance({ Notification.notification = Notification.newInstance({
prefixCls: 'ant-notification', prefixCls: 'ant-notification',
style: { style: {
top: 0, top: isNaN(top) ? 24 : top,
right: 0 right: 0
} }
}); });
@ -14,12 +14,31 @@ function getNotificationInstance() {
} }
function notice(args) { function notice(args) {
getNotificationInstance(); getNotificationInstance(args.top);
if (args.icon) { if (args.icon) {
let prefixCls = 'ant-notification-notice-content-icon-'; let prefixCls = ' ant-notification-notice-content-icon-';
let iconClass = 'anticon anticon-';
switch (args.icon) {
case 'success':
iconClass += 'check-circle-o';
break;
case 'info':
iconClass += 'info-circle-o';
break;
case 'error':
iconClass += 'exclamation-circle-o';
break;
case 'warn':
iconClass += 'question-circle-o';
break;
default:
iconClass += 'info-circle';
}
Notification.notification.notice({ Notification.notification.notice({
content: <div> content: <div>
<i className={'anticon anticon-question-circle-o ' + prefixCls + 'icon'}></i> <i className={iconClass + prefixCls + 'icon-' + args.icon + prefixCls + 'icon'}></i>
<p className={prefixCls + 'message'}>{args.message}</p> <p className={prefixCls + 'message'}>{args.message}</p>
<p className={prefixCls + 'description'}>{args.description}</p> <p className={prefixCls + 'description'}>{args.description}</p>
</div>, </div>,
@ -29,20 +48,19 @@ function notice(args) {
style: {} style: {}
}); });
} else { } else {
let prefixCls = 'ant-notification-notice-content-';
if (!args.btn) { if (!args.btn) {
let prefixCls = 'ant-notification-notice-content-';
Notification.notification.notice({ Notification.notification.notice({
content: <div> content: <div>
<p className={prefixCls + 'message'}>{args.message}</p> <p className={prefixCls + 'message'}>{args.message}</p>
<p className={prefixCls + 'description'}>{args.description}</p> <p className={prefixCls + 'description'}>{args.description}</p>
</div>, </div>,
duration: null, duration: null,
closable: true, closable: true,
onClose: args.onClose, onClose: args.onClose,
style: {} style: {}
}); });
} else { } else {
let prefixCls = 'ant-notification-notice-content-';
Notification.notification.notice({ Notification.notification.notice({
content: <div> content: <div>
<p className={prefixCls + 'message'}>{args.message}</p> <p className={prefixCls + 'message'}>{args.message}</p>

View File

@ -17,7 +17,7 @@
|----------- |--------------------------------------------- | ----------- |--------| |----------- |--------------------------------------------- | ----------- |--------|
| message | 通知提醒标题,必选 | String | 无 | | message | 通知提醒标题,必选 | String | 无 |
| description | 通知提醒内容,必选 | String | 无 | | description | 通知提醒内容,必选 | String | 无 |
| icon | 通知提醒框的左侧有Icon | Boolean | false | | icon | 通知提醒框的左侧Icon默认没有有四种选择`success`、`info`、`warn`、`error` | String | 无 |
| btn | 自定义关闭按钮 | String | 无 | | btn | 自定义关闭按钮 | String | 无 |
| top | 通知提醒框距离顶部的距离,只在初始化时设置有效,默认`24` | Number | 24 |
| onClose | 点击默认关闭按钮时触发的回调函数 | Function | 无 | | onClose | 点击默认关闭按钮时触发的回调函数 | Function | 无 |
| customClose | 点击自定义按钮时触发的回调函数 | Function | 无 |

View File

@ -2,16 +2,15 @@
@notificationPrefixCls: ~"@{css-prefix}notification"; @notificationPrefixCls: ~"@{css-prefix}notification";
@notificationPosition: 24px;
@noticeWidth: 335px; @noticeWidth: 335px;
@noticePadding: 16px; @noticePadding: 16px;
@noticeMarginTop: 10px; @noticeMarginBottom: 10px;
.@{notificationPrefixCls} { .@{notificationPrefixCls} {
position: fixed; position: fixed;
z-index: 1000; z-index: 1000;
width: @noticeWidth; width: @noticeWidth;
margin: (@notificationPosition - @noticeMarginTop) @notificationPosition 0 0; margin-right: 24px;
&-notice { &-notice {
padding: @noticePadding; padding: @noticePadding;
@ -20,7 +19,7 @@
background: @body-background; background: @body-background;
line-height: 1.5; line-height: 1.5;
position: relative; position: relative;
margin-top: @noticeMarginTop; margin-bottom: @noticeMarginBottom;
overflow: hidden; overflow: hidden;
&-content { &-content {
@ -54,7 +53,19 @@
top: 50%; top: 50%;
margin-top: -26px; margin-top: -26px;
font-size: 35px; font-size: 35px;
color: @primary-color;
&-success{
color: @success-color;
}
&-info{
color: @primary-color;
}
&-warn{
color: @warning-color;
}
&-error{
color: @error-color;
}
} }
} }
@ -92,7 +103,7 @@
&-fade-leave { &-fade-leave {
opacity: 1; opacity: 1;
margin-top: @noticeMarginTop; margin-bottom: @noticeMarginBottom;
padding-top: @noticePadding; padding-top: @noticePadding;
padding-bottom: @noticePadding; padding-bottom: @noticePadding;
max-height: 150px; max-height: 150px;
@ -102,7 +113,7 @@
&-fade-leave&-fade-leave-active { &-fade-leave&-fade-leave-active {
opacity: 0; opacity: 0;
max-height: 0; max-height: 0;
margin-top: 0; margin-bottom: 0;
padding-top: 0; padding-top: 0;
padding-bottom: 0; padding-bottom: 0;
} }