The SnackbarStack plugin for Vue and Vuetify adds features on top of the existing Vuetify snackbar
Source and issues: github.com/code-evolve/snackbarstack
Version 1.x of this package supports Vuetify 1
npm install snackbarstack
import SnackbarStackPlugin from 'snackbarstack'
Vue.use(SnackbarStackPlugin)
// Or change defaults
// Vue.use(SnackbarStackPlugin, {duration:4000})
new Vue({
el:'#app'
})
Show snackbars using this.$snackbar.show('the message')
onButtonPress() {
this.$snackbar.show("You pressed the button")
this.$snackbar.show("This message was queued")
}
You can also call $snackbar on the Vue instance. This is helpful when posting a message from outside of a component.
Vue.$snackbar.show("You pressed the button")
Or use options
onButtonPress() {
this.$snackbar.show("Press the button to continue.", {
duration: -1,
closeable: false,
actions: [{
caption:'Close Me',
handler(snackbar, options){
snackbar.close()
}
}]
})
}
This example hides the default close button, and adds a custom action that does the closing
type: number [optional]\ default: 6000
The duration of each snackbar message in milliseconds. This is used for messages that do not specify their own duration.
Shows or queues a snackbar message
The message is rendered as HTML, both in the snackbar and in outlets.
Escape any text that comes from users or other untrusted sources
before passing it to show().
type: number [optional] \ default: undefined
The duration of the snackbar message in milliseconds. -1 to show until user presses Close. If not set, the plugin's duration setting is used.
type: boolean [optional]\ default: true
Determines if a close button appears with the snackbar message
type: boolean [optional]\ default: false
If this is set, the message will be interpreted as an x-template. (x-template names must start with '#')
<script type="text/x-template" id="my-x-template">
<div>
<h2 style="display: inline-block">Hello</h2>
<h3 style="display: inline-block">X-Template</h3>
</div>
</script>
this.$snackbar.show('#my-x-template', {template:true})
type: object [optional]\ default: undefined
Actions to be added to the snackbar message. Can be an object or an array of objects.
var action = {
caption: '',
icon: '',
handler: function(api, options){}
}
The handler api object has 1 function, close(), to close the snackbar. The options object is the object passed in to the show() call.
type: string [optional]\ default: undefined
The selector for the outlet to display the message
If undefined, the default snackbar is used
If found, the innerHTML will be set. If the outlet element is not found, the message will be sent to the console as an info message.
The only option currently implemented when specifying outlets is duration
type: boolean [optional]\ default: false
Remove all other messages before displaying the message
type: boolean [optional]\ default: false
Remove all other messages of the same group before displaying the message
type: boolean [optional]\ default: false
Remove all other messages not matching the message group before displaying the message
type: string [optional]\ default: undefined
The message id or group
npm install
npm run build # writes dist/index.node.js (package entry) and dist/index.js (script tag)
npm test # builds, then runs the tests
Open demo/index.html in a browser after building to try the plugin
MIT. Versions before 2.0.0 were published under the ISC license.