-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notification): max, placement & destroyAll (#1685)
* feat(notification): add max & placement * feat(notification): add destroyAll method * doc: add changelog * test(notification): fix test lint Co-authored-by: [email protected] <[email protected]>
- Loading branch information
1 parent
db4cbc0
commit 297aaae
Showing
12 changed files
with
435 additions
and
15 deletions.
There are no files selected for viewing
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
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,44 @@ | ||
# Max | ||
|
||
```html | ||
<n-notification-provider :max="3"> | ||
<Button /> | ||
</n-notification-provider> | ||
``` | ||
|
||
```js | ||
import { defineComponent, ref, h } from 'vue' | ||
import { useNotification, NButton } from 'naive-ui' | ||
|
||
const Button = { | ||
setup () { | ||
const notification = useNotification() | ||
const number = ref(0) | ||
return { | ||
notification, | ||
number | ||
} | ||
}, | ||
render () { | ||
return h( | ||
NButton, | ||
{ | ||
onClick: () => { | ||
this.number++ | ||
this.notification.info({ | ||
title: `Notification number: ${this.number}`, | ||
content: 'You can limit the number of notifications' | ||
}) | ||
} | ||
}, | ||
{ default: 'Max notifications: 3' } | ||
) | ||
} | ||
} | ||
|
||
export default defineComponent({ | ||
components: { | ||
Button | ||
} | ||
}) | ||
``` |
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,64 @@ | ||
# Placement | ||
|
||
```html | ||
<n-notification-provider :placement="placement"> | ||
<Buttons @changePlacement="changePlacement" /> | ||
</n-notification-provider> | ||
``` | ||
|
||
```js | ||
import { defineComponent, h, ref } from 'vue' | ||
import { useNotification, NButton } from 'naive-ui' | ||
|
||
const Buttons = { | ||
emits: ['changePlacement'], | ||
setup () { | ||
const notification = useNotification() | ||
const placementArray = [ | ||
{ placement: 'top-left', text: 'TopLeft' }, | ||
{ placement: 'top-right', text: 'TopRight' }, | ||
{ placement: 'bottom-left', text: 'BottomLeft' }, | ||
{ placement: 'bottom-right', text: 'BottomRight' } | ||
] | ||
return { | ||
notification, | ||
placementArray | ||
} | ||
}, | ||
render () { | ||
return this.placementArray.map((item) => | ||
h( | ||
NButton, | ||
{ | ||
onClick: () => { | ||
this.$emit('changePlacement', item.placement) | ||
this.notification.info({ | ||
title: item.text, | ||
content: 'You can change the placement' | ||
}) | ||
}, | ||
style: { | ||
marginRight: '10px' | ||
} | ||
}, | ||
{ default: () => item.text } | ||
) | ||
) | ||
} | ||
} | ||
|
||
export default defineComponent({ | ||
components: { | ||
Buttons | ||
}, | ||
setup () { | ||
const placementRef = ref('top-right') | ||
return { | ||
placement: placementRef, | ||
changePlacement (val) { | ||
placementRef.value = val | ||
} | ||
} | ||
} | ||
}) | ||
``` |
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,44 @@ | ||
# 限制数量 | ||
|
||
```html | ||
<n-notification-provider :max="3"> | ||
<Button /> | ||
</n-notification-provider> | ||
``` | ||
|
||
```js | ||
import { defineComponent, ref, h } from 'vue' | ||
import { useNotification, NButton } from 'naive-ui' | ||
|
||
const Button = { | ||
setup () { | ||
const notification = useNotification() | ||
const number = ref(0) | ||
return { | ||
notification, | ||
number | ||
} | ||
}, | ||
render () { | ||
return h( | ||
NButton, | ||
{ | ||
onClick: () => { | ||
this.number++ | ||
this.notification.info({ | ||
title: `通知框序号: ${this.number}`, | ||
content: '你可以限制通知框的数量' | ||
}) | ||
} | ||
}, | ||
{ default: '通知框的最大数: 3' } | ||
) | ||
} | ||
} | ||
|
||
export default defineComponent({ | ||
components: { | ||
Button | ||
} | ||
}) | ||
``` |
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,64 @@ | ||
# Placement | ||
|
||
```html | ||
<n-notification-provider :placement="placement"> | ||
<Buttons @changePlacement="changePlacement" /> | ||
</n-notification-provider> | ||
``` | ||
|
||
```js | ||
import { defineComponent, h, ref } from 'vue' | ||
import { useNotification, NButton } from 'naive-ui' | ||
|
||
const Buttons = { | ||
emits: ['changePlacement'], | ||
setup () { | ||
const notification = useNotification() | ||
const placementArray = [ | ||
{ placement: 'top-left', text: '左上' }, | ||
{ placement: 'top-right', text: '右上' }, | ||
{ placement: 'bottom-left', text: '左下' }, | ||
{ placement: 'bottom-right', text: '右下' } | ||
] | ||
return { | ||
notification, | ||
placementArray | ||
} | ||
}, | ||
render () { | ||
return this.placementArray.map((item) => | ||
h( | ||
NButton, | ||
{ | ||
onClick: () => { | ||
this.$emit('changePlacement', item.placement) | ||
this.notification.info({ | ||
title: item.placement, | ||
content: 'You can change the placement' | ||
}) | ||
}, | ||
style: { | ||
marginRight: '10px' | ||
} | ||
}, | ||
{ default: () => item.text } | ||
) | ||
) | ||
} | ||
} | ||
|
||
export default defineComponent({ | ||
components: { | ||
Buttons | ||
}, | ||
setup () { | ||
const placementRef = ref('top-right') | ||
return { | ||
placement: placementRef, | ||
changePlacement (val) { | ||
placementRef.value = val | ||
} | ||
} | ||
} | ||
}) | ||
``` |
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.