mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-09 04:31:35 +08:00
feat(notification): specify theme
This commit is contained in:
parent
78e4ec0bdd
commit
a8afd8a8be
@ -15,6 +15,7 @@ duration
|
||||
### $NNotification Methods
|
||||
|Name|Type|Description|
|
||||
|-|-|-|
|
||||
|theme|`'light' \| 'dark'`|||
|
||||
|open|`(option: NotificationOption, type: string = 'default') => NotificationEnvironment`|`type` can be `'default'`, `'warning'`, `'info'`, `'success'` and `'error'`|
|
||||
|success|`(option: NofiticationOption) => NotificationEnvironment`||
|
||||
|info|`(option: NofiticationOption) => NotificationEnvironment`||
|
||||
@ -29,12 +30,13 @@ duration
|
||||
### NotificationOption Type
|
||||
|Name|Type|Default|Description|
|
||||
|-|-|-|-|
|
||||
|avatar|`string \| (() => VNode \| Array<VNode>)`|`null`|Can be render function|
|
||||
|title|`string \| (() => VNode \| Array<VNode>)`|`null`|Can be render function|
|
||||
|description|`string \| (() => VNode \| Array<VNode>)`|`null`|Can be render function|
|
||||
|content|`string \| (() => VNode \| Array<VNode>)`|`null`|Can be render function|
|
||||
|meta|`string \| (() => VNode \| Array<VNode>)`|`null`|Can be render function|
|
||||
|action|`string \| (() => VNode \| Array<VNode>)`|`null`|Can be render function|
|
||||
|theme|`'light' \| 'dark'`|`null`||
|
||||
|avatar|`() => VNode \| Array<VNode>`|`null`|Can be a render function|
|
||||
|title|`string \| (() => VNode \| Array<VNode>)`|`null`|Can be a render function|
|
||||
|description|`string \| (() => VNode \| Array<VNode>)`|`null`|Can be a render function|
|
||||
|content|`string \| (() => VNode \| Array<VNode>)`|`null`|Can be a render function|
|
||||
|meta|`string \| (() => VNode \| Array<VNode>)`|`null`|Can be a render function|
|
||||
|action|`string \| (() => VNode \| Array<VNode>)`|`null`|Can be a render function|
|
||||
|closable|`boolean`|`true`||
|
||||
|onClose|`() => boolean \| Promise<boolean>`|`() => {}`|The callback of notification closing. Returning `false`, promise resolve `false` or promise reject will cancel this closing.|
|
||||
|onAfterHide|`function`|`null`||
|
||||
@ -47,12 +49,12 @@ Properties of NofiticationEnvironment Instance can be dynamically set.
|
||||
|
||||
|Name|Type|Description|
|
||||
|-|-|-|
|
||||
|avatar|`string \| (() => VNode \| Array<VNode>)`|Can be render function|
|
||||
|title|`string \| (() => VNode \| Array<VNode>)`|Can be render function|
|
||||
|description|`string \| (() => VNode \| Array<VNode>)`|Can be render function|
|
||||
|content|`string \| (() => VNode \| Array<VNode>)`|Can be render function|
|
||||
|meta|`string \| (() => VNode \| Array<VNode>)`|Can be render function|
|
||||
|action|`string \| (() => VNode \| Array<VNode>)`|Can be render function|
|
||||
|avatar|`string \| (() => VNode \| Array<VNode>)`|Can be a render function|
|
||||
|title|`string \| (() => VNode \| Array<VNode>)`|Can be a render function|
|
||||
|description|`string \| (() => VNode \| Array<VNode>)`|Can be a render function|
|
||||
|content|`string \| (() => VNode \| Array<VNode>)`|Can be a render function|
|
||||
|meta|`string \| (() => VNode \| Array<VNode>)`|Can be a render function|
|
||||
|action|`string \| (() => VNode \| Array<VNode>)`|Can be a render function|
|
||||
|closable|`boolean`||
|
||||
|onClose|`(next: function) => any`|Callback when close button is clicked. Only if next is called notification will close|
|
||||
|onHide|`function`||
|
||||
|
@ -33,7 +33,8 @@ duration
|
||||
|
||||
|名称|类型|默认值|说明|
|
||||
|-|-|-|-|
|
||||
|avatar|`string \| (() => VNode \| Array<VNode>)`|`null`|可以是 render 函数|
|
||||
|theme|`'light' \| 'dark'`|`null`||
|
||||
|avatar|`() => VNode \| Array<VNode>`|`null`|可以是 render 函数|
|
||||
|title|`string \| (() => VNode \| Array<VNode>)`|`null`|可以是 render 函数|
|
||||
|description|`string \| (() => VNode \| Array<VNode>)`|`null`|可以是 render 函数|
|
||||
|content|`string \| (() => VNode \| Array<VNode>)`|`null`|可以是 render 函数|
|
||||
|
@ -18,6 +18,7 @@ export default {
|
||||
type: 'default',
|
||||
active: true,
|
||||
theme: null,
|
||||
inheritedTheme: null,
|
||||
avatar: null,
|
||||
title: null,
|
||||
description: null,
|
||||
@ -31,6 +32,11 @@ export default {
|
||||
onAfterHide: () => {}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
syntheticTheme () {
|
||||
return this.theme || this.inheritedTheme
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
if (this.duration !== null) {
|
||||
window.setTimeout(this.hide, this.duration)
|
||||
@ -100,7 +106,7 @@ export default {
|
||||
this.active ? h(NNotification, {
|
||||
props: {
|
||||
type: this.type,
|
||||
theme: this.theme,
|
||||
theme: this.syntheticTheme,
|
||||
avatar: this.avatar,
|
||||
title: this.title,
|
||||
description: this.description,
|
||||
|
@ -102,7 +102,7 @@ const Notification = {
|
||||
container.theme = theme
|
||||
}
|
||||
Notification.instances.forEach(instance => {
|
||||
instance.theme = theme
|
||||
instance.inheritedTheme = theme
|
||||
})
|
||||
},
|
||||
open (options, type = 'default') {
|
||||
@ -110,7 +110,7 @@ const Notification = {
|
||||
if (Notification.container && Notification.theme) {
|
||||
Notification.container.theme = Notification.theme
|
||||
}
|
||||
const notificationOptions = { theme: Notification.theme, type, ...options }
|
||||
const notificationOptions = { type, ...options, theme: options.theme || Notification.theme }
|
||||
const instance = createNotification(notificationOptions)
|
||||
mountNotification(instance)
|
||||
return instance
|
||||
|
Loading…
Reference in New Issue
Block a user