Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added isVisible api on toast object #40

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions __test__/__snapshots__/plugin.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`Toast plugin has close method on instance returned by open() 1`] = `
<div
class="v-toast v-toast-success is-bottom-right v-enter fadeInUp"
id="vue_toast_notification_1"
role="alert"
style=""
>
Expand Down
37 changes: 34 additions & 3 deletions examples/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
<input type="text" required class="form-control" v-model.trim="form.message" name="message"/>
</div>

<div class="form-group">
<label>ID</label>
<input type="text" class="form-control" v-model="form.id" name="notification-id"/>
</div>

<div class="form-group">
<label>Type</label>
<div>
<div v-for="item in types" class="custom-control custom-radio custom-control-inline">
<div v-for="(item,index) in types" class="custom-control custom-radio custom-control-inline" :key="index">
<input v-model="form.type" :value="item" type="radio" :id="`radio-type-${item}`"
class="custom-control-input">
<label class="custom-control-label text-capitalize" :for="`radio-type-${item}`">{{ item }}</label>
Expand Down Expand Up @@ -63,7 +68,7 @@
<div class="form-group">
<label>Position</label>
<div>
<div v-for="item in positions" class="custom-control custom-radio custom-control-inline">
<div v-for="(item,key) in positions" class="custom-control custom-radio custom-control-inline" :key="key">
<input v-model="form.position" :value="item" type="radio" :id="`radio-position-${item}`"
class="custom-control-input">
<label class="custom-control-label text-capitalize"
Expand All @@ -72,6 +77,13 @@
</div>
</div>

<div class="form-group">
<label>Visible Toasts</label>
<div style="height:4rem;overflow-y:auto;">
{{visisbleToastsId}}
</div>
</div>

<hr>

<button type="submit" class="btn btn-primary">Show notification</button>
Expand Down Expand Up @@ -105,16 +117,19 @@
<script>
import Vue from 'vue';
import Plugin, {Positions} from '../src/index';
import lodash from "lodash";
import {getElementId} from "../src/js/helpers"
//import '../src/themes/default/index.scss'
import '../src/themes/sugar/index.scss'

let oldId, visibleIds = [];
Vue.use(Plugin);

export default {
name: 'app',
data() {
return {
form: {
id: getElementId(),
message: 'This is a sample message',
type: 'success',
duration: 10000,
Expand All @@ -124,6 +139,7 @@ export default {
onClick: this.onClick,
onClose: this.onClose,
},
visisbleToastsId:"",
types: [
'success',
'error',
Expand Down Expand Up @@ -153,10 +169,25 @@ export default {
console.log("User dismissed the notification.")
},
onClose() {
setTimeout(()=>{
visibleIds = visibleIds.filter((id)=>{
return this.$toast.isVisible(id)
});
this.visisbleToastsId = visibleIds.join(",");
},0);
console.log("Toast was closed.")
},
show() {
if(!this.form.id || (oldId === this.form.id))
this.form.id = getElementId();
oldId = this.form.id;
this.$toast.open(this.form);
setTimeout(()=>{
if(this.$toast.isVisible(oldId)) {
visibleIds.push(oldId);
this.visisbleToastsId = visibleIds.join(",");
}
},0)
},
clearAll() {
this.$toast.clear()
Expand Down
Loading