snackbar component

This commit is contained in:
Davide Alberani 2017-01-19 21:14:52 +01:00
parent 8ceaabf5b8
commit 9a3633139f
3 changed files with 38 additions and 19 deletions

30
src/IbtSnackbar.vue Normal file
View file

@ -0,0 +1,30 @@
<template>
<md-snackbar md-position="top center" ref="snackbar">
<span>{{ snackbackMessage }}</span>
<md-button @click="$refs.snackbar.close()" class="snackbar-close">[x]</md-button>
</md-snackbar>
</template>
<script>
export default {
data: function() {
return {snackbackMessage: 'something happened'};
},
methods: {
show(message) {
this.snackbackMessage = message || snackbackMessage;
this.$refs.snackbar.open();
}
}
}
</script>
<style>
.snackbar-close {
font-weight: bold;
color: #f6f72f;
}
</style>

View file

@ -45,23 +45,20 @@
</span> </span>
</span> </span>
</span> </span>
<md-snackbar md-position="top center" ref="snackbar"> <ibt-snackbar ref="snackbarObj" />
<span>{{ snackbackMessage }}</span>
<md-button @click="$refs.snackbar.close()" class="snackbar-close">[x]</md-button>
</md-snackbar>
<ibt-dialog ref="dialogObj" /> <ibt-dialog ref="dialogObj" />
</md-toolbar> </md-toolbar>
</template> </template>
<script> <script>
import IbtDialog from './IbtDialog.vue'; import IbtDialog from './IbtDialog.vue';
import IbtSnackbar from './IbtSnackbar.vue';
export default { export default {
data () { data () {
return { return {
username: '', username: '',
password: '', password: '',
snackbackMessage: '',
dialog: { dialog: {
text: 'some error', text: 'some error',
ok: 'ok' ok: 'ok'
@ -146,7 +143,7 @@ export default {
this.$refs.dialogObj.show({text: 'failed to logout'}); this.$refs.dialogObj.show({text: 'failed to logout'});
}).then((json) => { }).then((json) => {
this.$store.commit('clearLoggedInUser'); this.$store.commit('clearLoggedInUser');
this.showMessage('logged out'); this.$refs.snackbarObj.show('logged out');
}); });
}, },
@ -175,15 +172,10 @@ export default {
callback(data); callback(data);
} }
}); });
},
showMessage(message) {
this.snackbackMessage = message;
this.$refs.snackbar.open();
} }
}, },
components: { IbtDialog } components: { IbtDialog, IbtSnackbar }
} }
</script> </script>
<style> <style>
@ -251,10 +243,4 @@ export default {
font-weight: bold; font-weight: bold;
color: white !important; color: white !important;
} }
.snackbar-close {
font-weight: bold;
color: #f6f72f;
}
</style> </style>

View file

@ -19,12 +19,14 @@
<md-button class="md-raised md-primary" @click="save()">Save</md-button> <md-button class="md-raised md-primary" @click="save()">Save</md-button>
</md-card-content> </md-card-content>
</md-card> </md-card>
<ibt-snackbar ref="snackbarObj" />
<ibt-dialog ref="dialogObj" /> <ibt-dialog ref="dialogObj" />
</div> </div>
</template> </template>
<script> <script>
import IbtDialog from './IbtDialog.vue'; import IbtDialog from './IbtDialog.vue';
import IbtSnackbar from './IbtSnackbar.vue';
export default { export default {
data () { data () {
@ -67,11 +69,12 @@ export default {
this.$refs.dialogObj.show({text: 'unable to save user settings'}); this.$refs.dialogObj.show({text: 'unable to save user settings'});
}).then((data) => { }).then((data) => {
this.user = data; this.user = data;
this.$refs.snackbarObj.show('user saved');
}); });
} }
}, },
components: { IbtDialog } components: { IbtDialog, IbtSnackbar }
} }
</script> </script>