Implements "pause on hover" feature & exposes onMouseEnter and onMouseLeave callback props
parent
bd7161298a
commit
48ed69b35e
|
@ -49,6 +49,14 @@ export default {
|
||||||
closeButtonProps: {
|
closeButtonProps: {
|
||||||
type: null,
|
type: null,
|
||||||
default: null
|
default: null
|
||||||
|
},
|
||||||
|
onMouseEnter: {
|
||||||
|
type: Function,
|
||||||
|
default: undefined
|
||||||
|
},
|
||||||
|
onMouseLeave: {
|
||||||
|
type: Function,
|
||||||
|
default: undefined
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
style: ToastStyle,
|
style: ToastStyle,
|
||||||
|
|
|
@ -250,6 +250,14 @@ export interface ToastProps {
|
||||||
* @defaultValue false
|
* @defaultValue false
|
||||||
*/
|
*/
|
||||||
unstyled?: boolean;
|
unstyled?: boolean;
|
||||||
|
/**
|
||||||
|
* Used to specify a callback function to be run when the @mouseenter event is fired on the message component.
|
||||||
|
*/
|
||||||
|
onMouseEnter?: Function | undefined;
|
||||||
|
/**
|
||||||
|
* Used to specify a callback function to be run when the @mouseleave event is fired on the message component.
|
||||||
|
*/
|
||||||
|
onMouseLeave?: Function | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<div :class="[cx('message'), message.styleClass]" role="alert" aria-live="assertive" aria-atomic="true" v-bind="ptm('message')">
|
<div :class="[cx('message'), message.styleClass]" role="alert" aria-live="assertive" aria-atomic="true" v-bind="ptm('message')" @mouseenter="onMouseEnter" @mouseleave="onMouseLeave">
|
||||||
<component v-if="templates.container" :is="templates.container" :message="message" :closeCallback="onCloseClick" />
|
<component v-if="templates.container" :is="templates.container" :message="message" :closeCallback="onCloseClick" />
|
||||||
<div v-else :class="[cx('messageContent'), message.contentStyleClass]" v-bind="ptm('messageContent')">
|
<div v-else :class="[cx('messageContent'), message.contentStyleClass]" v-bind="ptm('messageContent')">
|
||||||
<template v-if="!templates.message">
|
<template v-if="!templates.message">
|
||||||
|
@ -34,6 +34,8 @@ export default {
|
||||||
extends: BaseComponent,
|
extends: BaseComponent,
|
||||||
emits: ['close'],
|
emits: ['close'],
|
||||||
closeTimeout: null,
|
closeTimeout: null,
|
||||||
|
createdAt: null,
|
||||||
|
lifeRemaining: null,
|
||||||
props: {
|
props: {
|
||||||
message: {
|
message: {
|
||||||
type: null,
|
type: null,
|
||||||
|
@ -70,15 +72,20 @@ export default {
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
if (this.message.life) {
|
if (this.message.life) {
|
||||||
this.closeTimeout = setTimeout(() => {
|
this.lifeRemaining = this.message.life;
|
||||||
this.close({ message: this.message, type: 'life-end' });
|
this.startTimeout();
|
||||||
}, this.message.life);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeUnmount() {
|
beforeUnmount() {
|
||||||
this.clearCloseTimeout();
|
this.clearCloseTimeout();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
startTimeout() {
|
||||||
|
this.createdAt = new Date().valueOf();
|
||||||
|
this.closeTimeout = setTimeout(() => {
|
||||||
|
this.close({ message: this.message, type: 'life-end' });
|
||||||
|
}, this.lifeRemaining);
|
||||||
|
},
|
||||||
close(params) {
|
close(params) {
|
||||||
this.$emit('close', params);
|
this.$emit('close', params);
|
||||||
},
|
},
|
||||||
|
@ -91,6 +98,26 @@ export default {
|
||||||
clearTimeout(this.closeTimeout);
|
clearTimeout(this.closeTimeout);
|
||||||
this.closeTimeout = null;
|
this.closeTimeout = null;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
onMouseEnter(event) {
|
||||||
|
this.props.onMouseEnter && this.props.onMouseEnter(event);
|
||||||
|
if (event.defaultPrevented) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.message.life) {
|
||||||
|
this.lifeRemaining = this.createdAt + this.lifeRemaining - Date().valueOf();
|
||||||
|
this.createdAt = null;
|
||||||
|
this.clearCloseTimeout();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onMouseLeave(event) {
|
||||||
|
this.props.onMouseLeave && this.props.onMouseLeave(event);
|
||||||
|
if (event.defaultPrevented) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.message.life) {
|
||||||
|
this.startTimeout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|
Loading…
Reference in New Issue