diff --git a/demo/Entry.vue b/demo/Entry.vue index 369e96f66..676dfa037 100644 --- a/demo/Entry.vue +++ b/demo/Entry.vue @@ -6,17 +6,19 @@ :language="lang" > - - - - + + + + + + - + diff --git a/demo/documentation/components/notification/zhCN/basic.demo.md b/demo/documentation/components/notification/zhCN/basic.demo.md index 298f3c278..60247c479 100644 --- a/demo/documentation/components/notification/zhCN/basic.demo.md +++ b/demo/documentation/components/notification/zhCN/basic.demo.md @@ -1,17 +1,20 @@ # 基础用法 ```html - + Wouldn't it be Nice - + Satisfaction ``` ```js +import { h, resolveComponent } from 'vue' + export default { + inject: ['notification', 'message'], methods: { - notify1 () { - this.$NNotification.open({ + handleClick1 () { + this.notification.create({ title: `Wouldn't it be Nice`, description: 'From the Beach Boys', content: `Wouldn't it be nice if we were older @@ -25,47 +28,41 @@ In the morning when the day is new And after having spent the day together Hold each other close the whole night through`, meta: '2019-5-27 15:11', - avatar: h => - h('n-avatar', { - props: { - size: 'small', - round: true, - src:'https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg' - } + avatar: () => + h(resolveComponent('n-avatar'), { + size: 'small', + round: true, + src:'https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg' }), - onAfterHide: () => { - this.$NMessage.success(`Wouldn't it be Nice`) + onAfterLeave: () => { + this.message.success(`Wouldn't it be Nice`) }, }) }, - notify2 () { + handleClick2 () { let markAsRead = false - const notification = this.$NNotification.open({ + const notification = this.notification.create({ title: 'Satisfaction', content: `I cant get no satisfaction I cant get no satisfaction Cause I try and I try and I try and I try I cant get no, I cant get no`, meta: '2019-5-27 15:11', - action: h => h( - 'n-button', + action: () => h( + resolveComponent('n-button'), { - props: { - text: true, - type: 'primary' - }, - on: { - click: () => { - markAsRead = true - notification.hide() - } + text: true, + type: 'primary', + onClick: () => { + markAsRead = true + notification.destroy() } }, ['已读'] ), onClose: () => { if (!markAsRead) { - this.$NMessage.warning('请设为已读') + this.message.warning('请设为已读') return false } } diff --git a/demo/documentation/components/notification/zhCN/change-content.demo.md b/demo/documentation/components/notification/zhCN/change-content.demo.md index 88c179d2b..3235eaed1 100644 --- a/demo/documentation/components/notification/zhCN/change-content.demo.md +++ b/demo/documentation/components/notification/zhCN/change-content.demo.md @@ -9,7 +9,10 @@ ``` ```js +import { h, resolveComponent } from 'vue' + export default { + inject: ['notification'], data () { return { notification: null @@ -17,7 +20,7 @@ export default { }, methods: { open () { - this.notification = this.$NNotification.open({ + this.notification = this.notification.create({ title: `Wouldn't it be Nice`, description: 'From the Beach Boys', content: `Wouldn't it be nice if we were older @@ -31,13 +34,11 @@ In the morning when the day is new And after having spent the day together Hold each other close the whole night through`, meta: '2019-5-27 15:11', - avatar: h => - h('n-avatar', { - props: { - size: 'small', - round: true, - src:'https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg' - } + avatar: () => + h(resolveComponent('n-avatar'), { + size: 'small', + round: true, + src:'https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg' }), onClose: () => { this.notification = null @@ -46,13 +47,9 @@ Hold each other close the whole night through`, }, change () { if (this.notification) { - this.notification.content = h => h('img', { - attrs: { - src: 'https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg' - }, - style: { - width: '100%' - } + this.notification.content = () => h('img', { + src: 'https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg', + style: 'width: 100%;' }) } } diff --git a/demo/documentation/components/notification/zhCN/closable.demo.md b/demo/documentation/components/notification/zhCN/closable.demo.md index ecaa3d712..b3e4b1fa8 100644 --- a/demo/documentation/components/notification/zhCN/closable.demo.md +++ b/demo/documentation/components/notification/zhCN/closable.demo.md @@ -1,28 +1,30 @@ # 不可关闭 通知可以不能被关闭 ```html - + 不能关闭 ``` ```js export default { + inject: ['notification'], methods: { - notify (type) { - this.$NNotification.open({ - title: `你能关掉我吗?`, + handleClick () { + const notification = this.notification + notification.create({ + title: '你能关掉我吗?', duration: 2000, closable: false, - onAfterHide: () => { - this.$NNotification.open({ + onAfterLeave: () => { + notification.create({ title: `哈哈哈哈!`, duration: 2000, closable: false, - onAfterHide: () => { - this.$NNotification.open({ + onAfterLeave: () => { + notification.create({ title: `你不能`, duration: 2000, - closable: false, + closable: false }) } }) diff --git a/demo/documentation/components/notification/zhCN/duration.demo.md b/demo/documentation/components/notification/zhCN/duration.demo.md index 080ff3f36..8a1b637bc 100644 --- a/demo/documentation/components/notification/zhCN/duration.demo.md +++ b/demo/documentation/components/notification/zhCN/duration.demo.md @@ -1,21 +1,22 @@ # 持续时间 自动关闭。 ```html - + 持续时间 10000ms ``` ```js export default { + inject: ['notification'], methods: { - notify (type) { + handleClick () { let count = 10 - const notification = this.$NNotification.open({ + const notification = this.notification.create({ title: `平山道 + 雨 = 什么?`, content: `你有 ${count} 秒来回答这个问题`, duration: 10000, closable: false, - onAfterShow: () => { + onAfterEnter: () => { const minusCount = () => { count-- notification.content = `你有 ${count} 秒来回答这个问题` @@ -25,8 +26,8 @@ export default { } window.setTimeout(minusCount, 1000) }, - onAfterHide: () => { - this.$NNotification.open({ + onAfterLeave: () => { + this.notification.create({ title: `答案是平山河`, content: '这其实连个冷笑话都算不上', duration: 10000 diff --git a/demo/documentation/components/notification/zhCN/index.demo-entry.md b/demo/documentation/components/notification/zhCN/index.demo-entry.md index 2c211bb15..c25217203 100644 --- a/demo/documentation/components/notification/zhCN/index.demo-entry.md +++ b/demo/documentation/components/notification/zhCN/index.demo-entry.md @@ -12,60 +12,60 @@ closable duration ``` ## API -#### $Notification API -#### $NNotification Methods -|名称|类型|说明| -|-|-|-| -|open|`(option: NotificationOption, type: string = 'default') => NotificationEnvironment`|`type` 可以是 `'default'`, `'warning'`, `'info'`, `'success'` 或 `'error'`| -|success|`(option: NofiticationOption) => NotificationEnvironment`|| -|info|`(option: NofiticationOption) => NotificationEnvironment`|| -|warning|`(option: NofiticationOption) => NotificationEnvironment`|| -|error|`(option: NofiticationOption) => NotificationEnvironment`|| - -#### $Notification Properties - +### NotificationProvider Props |名称|类型|默认值|说明| |-|-|-|-| -|scrollable|`boolean`|`false`|| +|scrollable|`boolean`|`true`|| +|to|`string \| HTMLElement`|`'body'`|| + +### NotificationProvider Injection API +#### NotificationProvider Injection Methods +|名称|类型|说明| +|-|-|-| +|create|`(option: NotificationOption) => NotificationReactive`|| +|success|`(option: NotificationOption) => NotificationReactive`|| +|info|`(option: NotificationOption) => NotificationReactive`|| +|warning|`(option: NotificationOption) => NotificationReactive`|| +|error|`(option: NotificationOption) => NotificationReactive`|| ### NotificationOption API #### NotificationOption Properties - |名称|类型|默认值|说明| |-|-|-|-| -|theme|`'light' \| 'dark'`|`null`|如果设定会将该通知的主题设为该主题,如果没有设定则全局主题则取决于调用位置(它工作起来和 $NMessage 的主题比较像,在大多数情况下你不用为此而操心)| -|avatar|`() => VNode \| Array`|`null`|可以是 render 函数| -|title|`string \| (() => VNode \| Array)`|`null`|可以是 render 函数| -|description|`string \| (() => VNode \| Array)`|`null`|可以是 render 函数| -|content|`string \| (() => VNode \| Array)`|`null`|可以是 render 函数| -|meta|`string \| (() => VNode \| Array)`|`null`|可以是 render 函数| |action|`string \| (() => VNode \| Array)`|`null`|可以是 render 函数| +|avatar|`() => VNode \| Array`|`null`|可以是 render 函数| |closable|`boolean`|`true`|| -|onClose|`() => boolean \| Promise \| any`|`() => {}`|关闭通知的回调。返回 `false`、Promise resolve `false` 或者 reject 会取消这次关闭| -|onAfterHide|`Function`|`null`|| -|onAfterShow|`Function`|`null`|| +|content|`string \| (() => VNode \| Array)`|`null`|可以是 render 函数| +|description|`string \| (() => VNode \| Array)`|`null`|可以是 render 函数| |duration|`number`|`null`|如果没有设定则不会自动关闭,单位毫秒| +|meta|`string \| (() => VNode \| Array)`|`null`|可以是 render 函数| +|theme|`'light' \| 'dark' \| null \| string`|`null`|| +|title|`string \| (() => VNode \| Array)`|`null`|可以是 render 函数| +|onAfterEnter|`Function`|`null`|| +|onAfterLeave|`Function`|`null`|| +|onClose|`() => boolean \| Promise`|`() => {}`|关闭通知的回调。返回 `false`、Promise resolve `false` 或者 reject 会取消这次关闭| +|onLeave|`Function`|| -### NotificationEnvironment API -#### NotificationEnvironment Properties +### NotificationReactive API +#### NotificationReactive Properties NofiticationEnvironment 实例的属性可以被动态改变。 |名称|类型|说明| |-|-|-| -|theme|`'light' \| 'dark'`|如果设定会将该通知的主题设为该主题,如果没有设定则全局主题则取决于调用位置(它工作起来和 $NMessage 的主题比较像,在大多数情况下你不用为此而操心)| -|avatar|`() => VNode \| Array`|可以是 render 函数| -|title|`string \| (() => VNode \| Array)`|可以是 render 函数| -|description|`string \| (() => VNode \| Array)`|可以是 render 函数| -|content|`string \| (() => VNode \| Array)`|可以是 render 函数| -|meta|`string \| (() => VNode \| Array)`|可以是 render 函数| |action|`string \| (() => VNode \| Array)`|可以是 render 函数| +|avatar|`() => VNode \| Array`|可以是 render 函数| |closable|`boolean`|| -|onClose|`(next: function) => any`|点击了关闭按钮的回调。只有调用了 next 通知才会被关闭| -|onHide|`Function`|| -|onAfterHide|`Function`|| -|onAfterShow|`Function`|| +|content|`string \| (() => VNode \| Array)`|可以是 render 函数| +|description|`string \| (() => VNode \| Array)`|可以是 render 函数| +|meta|`string \| (() => VNode \| Array)`|可以是 render 函数| +|theme|`'light' \| 'dark' \| null \| string`|| +|title|`string \| (() => VNode \| Array)`|可以是 render 函数| +|onAfterEnter|`Function`|| +|onAfterLeave|`Function`|| +|onClose|`() => boolean \| Promise`|`() => {}`|关闭通知的回调。返回 `false`、Promise resolve `false` 或者 reject 会取消这次关闭| +|onLeave|`Function`|| -#### NotificationEnvironment Methods +#### NotificationReactive Methods |名称|类型|说明| |-|-|-| -|hide|`()`|| \ No newline at end of file +|destroy|`()`|销毁该通知| \ No newline at end of file diff --git a/demo/documentation/components/notification/zhCN/scrollable.demo.md b/demo/documentation/components/notification/zhCN/scrollable.demo.md index 2c38af33a..213e7a746 100644 --- a/demo/documentation/components/notification/zhCN/scrollable.demo.md +++ b/demo/documentation/components/notification/zhCN/scrollable.demo.md @@ -1,16 +1,27 @@ # 可滚动 -如果有太多信息,你可以通过设定 `$NNotification.scrollable = true` 让他们变得可以滚动。但是在那种情况下,通知会比他们看起来的多占据一点点空间,会挡住一些通知外面离通知很近的鼠标操作。如果你不想要这个特性,什么都不做就好。 +如果有太多信息,通知的容器是可以滚动的。但是在那种情况下,通知会比他们看起来的多占据一点点空间,会挡住一些通知外面离通知很近的鼠标操作。如果你不想要这个特性,你可以通过设定 `` 来使通知不可滚动。 改变这个属性会导致已经存在全部通知被清空,确保你在合适的时机修改了这个属性。 ```html -可以滚动(点完多开几个通知) -不可以滚动 +看看这个东西怎么滚动 ``` ```js export default { + inject: ['notification'], methods: { handleClick (scrollable) { - this.$NNotification.scrollable = scrollable + Array.apply(null, { length: 5 }).forEach( + notification => this.notification.create({ + title: '很多个通知', + content: `试着滚起来 +试着滚起来 +试着滚起来 +试着滚起来 +试着滚起来 +试着滚起来 +试着滚起来` + }) + ) } } } diff --git a/demo/documentation/components/notification/zhCN/type.demo.md b/demo/documentation/components/notification/zhCN/type.demo.md index 50129dc84..45ae1fa2d 100644 --- a/demo/documentation/components/notification/zhCN/type.demo.md +++ b/demo/documentation/components/notification/zhCN/type.demo.md @@ -15,10 +15,11 @@ ``` ```js export default { + inject: ['notification'], methods: { notify (type) { - this.$NNotification[type]({ - content: `说点啥呢`, + this.notification[type]({ + content: '说点啥呢', meta: '想不出来' }) } diff --git a/src/_utils/composition/index.js b/src/_utils/composition/index.js index 4d154e7c2..ff0b8c73f 100644 --- a/src/_utils/composition/index.js +++ b/src/_utils/composition/index.js @@ -44,4 +44,3 @@ export function useIsMounted () { } export { default as useLastClickPosition } from './use-last-click-position' -export { default as useContainer } from './use-container' diff --git a/src/_utils/composition/use-container.js b/src/_utils/composition/use-container.js deleted file mode 100644 index 176dba323..000000000 --- a/src/_utils/composition/use-container.js +++ /dev/null @@ -1,31 +0,0 @@ -import { computed } from 'vue' - -export default function useContainer ( - toRef, - containerClassNameRef -) { - const getContainerTarget = computed( - () => typeof toRef.value === 'string' ? () => document.querySelector(toRef.value) : () => toRef.value - ) - const getContainer = computed( - () => () => getContainerTarget.value().querySelector('.' + containerClassNameRef.value) - ) - const mountIfNotExist = () => { - const targetEl = getContainerTarget.value() - if (!targetEl.querySelector('.' + containerClassNameRef.value)) { - const containerEl = document.createElement('div') - containerEl.className = containerClassNameRef.value - targetEl.appendChild(containerEl) - } - } - const unmountIfEmpty = () => { - const container = getContainer.value() - if (!container.childElementCount) { - container.parentNode.removeChild(container) - } - } - return [ - mountIfNotExist, - unmountIfEmpty - ] -} diff --git a/src/index.js b/src/index.js index 497146cc6..0b18a5d94 100644 --- a/src/index.js +++ b/src/index.js @@ -41,7 +41,7 @@ import Log from './log' import Menu from './menu' import Message from './message' import Modal from './modal' -// import Notification from './notification' +import Notification from './notification' import Pagination from './pagination' import Popconfirm from './popconfirm' import Popselect from './popselect' @@ -232,7 +232,7 @@ export default create({ Modal, Input, Message, - // Notification, + Notification, Pagination, Tooltip, Popup, diff --git a/src/notification/index.js b/src/notification/index.js index cd6cff906..bcfb52d9b 100644 --- a/src/notification/index.js +++ b/src/notification/index.js @@ -1,9 +1,7 @@ -import Notification from './src/NotificationPlugin' -import { install } from '../_utils/naive/installThemeAwarableProperty' +import NotificationProvider from './src/NotificationProvider' Notification.install = function (app, naive) { - Notification.Vue = app - install(app, Notification, `$${naive.componentPrefix}Notification`) + app.component(naive.componentPrefix + NotificationProvider.name, NotificationProvider) } export default Notification diff --git a/src/notification/src/Notification.vue b/src/notification/src/Notification.vue index 3583352d2..f158a8a8d 100644 --- a/src/notification/src/Notification.vue +++ b/src/notification/src/Notification.vue @@ -1,23 +1,23 @@