提交 6a7b9ee3 编写于 作者: A Amy 提交者: doly mood

Toast dev (#149)

* feat(toast): event hide

* test(toast): event hide

* feat: event hide -> timeout

* docs(toast): event timout
上级 269f47bd
...@@ -85,3 +85,9 @@ ...@@ -85,3 +85,9 @@
| mask | whether to show mask layer | Boolean | true/false | false | | mask | whether to show mask layer | Boolean | true/false | false |
| txt | tip text | String | - | '' | | txt | tip text | String | - | '' |
| time | display duration, millisecond | Number | - | 3000 | | time | display duration, millisecond | Number | - | 3000 |
### Events
| Event Name | Description |
| - | - |
| timeout | triggers when the display time is out |
...@@ -86,3 +86,9 @@ ...@@ -86,3 +86,9 @@
| mask | 遮罩 | Boolean | true/false | false | | mask | 遮罩 | Boolean | true/false | false |
| txt | 提示信息 | String | - | '' | | txt | 提示信息 | String | - | '' |
| time | 显示时间 | Number | - | 3000 | | time | 显示时间 | Number | - | 3000 |
### 事件
| 事件名 | 说明 |
| - | - |
| timeout | 当显示时间结束时派发 |
...@@ -20,7 +20,10 @@ ...@@ -20,7 +20,10 @@
showToastTime() { showToastTime() {
this.toast = this.$createToast({ this.toast = this.$createToast({
time: 1000, time: 1000,
txt: 'Toast time 1s' txt: 'Toast time 1s',
onHide: () => {
console.log('hide')
}
}) })
this.toast.show() this.toast.show()
}, },
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
const COMPONENT_NAME = 'cube-toast' const COMPONENT_NAME = 'cube-toast'
const EVENT_TIMEOUT = 'timeout'
export default { export default {
name: COMPONENT_NAME, name: COMPONENT_NAME,
mixins: [apiMixin], mixins: [apiMixin],
...@@ -65,6 +67,7 @@ ...@@ -65,6 +67,7 @@
if (this.time !== 0) { if (this.time !== 0) {
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
this.hide() this.hide()
this.$emit(EVENT_TIMEOUT)
}, this.time) }, this.time)
} }
}) })
......
import createAPI from '../../common/helpers/create-api' import createAPI from '../../common/helpers/create-api'
export default function addToast (Vue, Toast) { export default function addToast (Vue, Toast) {
createAPI(Vue, Toast, [], true) createAPI(Vue, Toast, ['timeout'], true)
} }
...@@ -113,5 +113,29 @@ describe('Toast', () => { ...@@ -113,5 +113,29 @@ describe('Toast', () => {
done() done()
}) })
}) })
it('should trigger correct event', function (done) {
const timeoutHandle = sinon.spy()
const vm = createToast({
time: 1000
}, {
timeout: timeoutHandle
})
vm.show()
setTimeout(() => {
expect(timeoutHandle).to.be.calledOnce
done()
}, 1200)
})
function createToast(props = {}, events = {}) {
return instantiateComponent(Vue, Toast, {
props: props,
on: events
})
}
}) })
}) })
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册