-
-
Notifications
You must be signed in to change notification settings - Fork 47.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support notification pop up from topLeft or bottomRight or bottomLeft #4700
Merged
afc163
merged 7 commits into
ant-design:feature-2.7
from
ystarlongzi:notification-placement
Jan 27, 2017
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9b91fe5
update snapshots
ystarlongzi 6b467da
update snapshots
ystarlongzi 0f82d1f
support notification pop up from topLeft or bottomRight or bottomLeft
ystarlongzi a7b2e3f
update snapshots
ystarlongzi 546a789
1. add test
ystarlongzi 85fdda2
update doc
ystarlongzi c6b0780
update doc.
ystarlongzi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
components/notification/__tests__/Notification.placement.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import notification from '..'; | ||
|
||
describe('Notification.placement', () => { | ||
function $$(className) { | ||
return document.body.querySelectorAll(className); | ||
} | ||
|
||
function getStyle(el, prop, getComputedStyle, style) { | ||
getComputedStyle = window.getComputedStyle; | ||
style = getComputedStyle ? getComputedStyle(el) : el.currentStyle; | ||
|
||
// If a css property's value is `auto`, it will return an empty string. | ||
return prop ? style[prop] : style; | ||
} | ||
|
||
function open(args) { | ||
notification.open({ | ||
message: 'Notification Title', | ||
description: 'This is the content of the notification.', | ||
...args, | ||
}); | ||
} | ||
|
||
function config(args) { | ||
notification.config({ | ||
...args, | ||
}); | ||
open(); | ||
} | ||
|
||
it('change notification placement by `open` method', () => { | ||
const defaultTop = '24px'; | ||
const defaultBottom = '24px'; | ||
let style; | ||
|
||
// topLeft | ||
open({ | ||
placement: 'topLeft', | ||
}); | ||
style = getStyle($$('.ant-notification-topLeft')[0]); | ||
expect(style.top).toBe(defaultTop); | ||
expect(style.left).toBe('0px'); | ||
expect(style.bottom).toBe(''); | ||
|
||
|
||
// topRight | ||
open({ | ||
placement: 'topRight', | ||
}); | ||
style = getStyle($$('.ant-notification-topRight')[0]); | ||
expect(style.top).toBe(defaultTop); | ||
expect(style.right).toBe('0px'); | ||
expect(style.bottom).toBe(''); | ||
|
||
// bottomRight | ||
open({ | ||
placement: 'bottomRight', | ||
}); | ||
style = getStyle($$('.ant-notification-bottomRight')[0]); | ||
expect(style.top).toBe(''); | ||
expect(style.right).toBe('0px'); | ||
expect(style.bottom).toBe(defaultBottom); | ||
|
||
// bottomLeft | ||
open({ | ||
placement: 'bottomLeft', | ||
}); | ||
style = getStyle($$('.ant-notification-bottomLeft')[0]); | ||
expect(style.top).toBe(''); | ||
expect(style.left).toBe('0px'); | ||
expect(style.bottom).toBe(defaultBottom); | ||
}); | ||
|
||
it('change notification placement by `config` method', () => { | ||
let style; | ||
|
||
// topLeft | ||
config({ | ||
placement: 'topLeft', | ||
top: 50, | ||
bottom: 50, | ||
}); | ||
style = getStyle($$('.ant-notification-topLeft')[1]); | ||
expect(style.top).toBe('50px'); | ||
expect(style.left).toBe('0px'); | ||
expect(style.bottom).toBe(''); | ||
|
||
// topRight | ||
config({ | ||
placement: 'topRight', | ||
top: 100, | ||
bottom: 50, | ||
}); | ||
style = getStyle($$('.ant-notification-topRight')[1]); | ||
expect(style.top).toBe('100px'); | ||
expect(style.right).toBe('0px'); | ||
expect(style.bottom).toBe(''); | ||
|
||
// bottomRight | ||
config({ | ||
placement: 'bottomRight', | ||
top: 50, | ||
bottom: 100, | ||
}); | ||
style = getStyle($$('.ant-notification-bottomRight')[1]); | ||
expect(style.top).toBe(''); | ||
expect(style.right).toBe('0px'); | ||
expect(style.bottom).toBe('100px'); | ||
|
||
// bottomLeft | ||
config({ | ||
placement: 'bottomLeft', | ||
top: 100, | ||
bottom: 50, | ||
}); | ||
style = getStyle($$('.ant-notification-bottomLeft')[1]); | ||
expect(style.top).toBe(''); | ||
expect(style.left).toBe('0px'); | ||
expect(style.bottom).toBe('50px'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
order: 5 | ||
title: | ||
zh-CN: 位置 | ||
en-US: Placement | ||
--- | ||
|
||
## zh-CN | ||
|
||
可以设置通知从右上角、右下角、左下角、左上角弹出。 | ||
|
||
## en-US | ||
|
||
A notification box can pop up from `topRight` or `bottomRight` or `bottomLeft` or `topLeft`. | ||
|
||
````__react | ||
import { Button, Select, notification } from 'antd'; | ||
|
||
const { Option } = Select; | ||
const options = ['topLeft', 'topRight','bottomLeft', 'bottomRight']; | ||
const openNotification = () => { | ||
notification.open({ | ||
message: 'Notification Title', | ||
description: 'This is the content of the notification. This is the content of the notification. This is the content of the notification.', | ||
}); | ||
}; | ||
|
||
ReactDOM.render( | ||
<div> | ||
<Select | ||
defaultValue="topRight" | ||
style={{ width: 120, marginRight: 10 }} | ||
onChange={val => { | ||
notification.config({ | ||
placement: val, | ||
}); | ||
}} | ||
> | ||
{options.map(val => <Option key={val} value={val}>{val}</Option>)} | ||
</Select> | ||
<Button | ||
type="primary" | ||
onClick={openNotification} | ||
> | ||
Open the notification box | ||
</Button> | ||
</div> | ||
, mountNode); | ||
```` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
open 这里也支持一下
placement
如何?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,我也加下。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afc163
在实现上支持
placement
,然后 demo 里的open
方法内就不用体现placement
了吧,因为 demo 里是通过config
方法修改placement
。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那文档里补充一下。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯嗯,好的。