npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

snackbard

v1.0.8

Published

An Elizabethan Vue plugin to help with snackbar management.

Downloads

643

Readme

Snackbard

npm version Monthly Downloads License: MIT

Description

No need to know your iambs from your trochees to use this simple Vue plugin. After installing snackbard, you will have a global $snackbard prototype available in your script with which to programmatically manage a material-themed snackbar.

Here are a few examples to show how simple it is to use:

this.$snackbard.loading()
this.$snackbard.cancel()
this.$snackbard.success()
this.$snackbard.cancel()
this.$snackbard.show({ text: 'Heigh ho!' })

Install

npm install snackbard, or yarn add snackbard

Then, copy the pattern in this example main.js:

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
Vue.config.productionTip = false

import Snackbard from 'snackbard' // import snackbard
Vue.use(Snackbard) // tell Vue to use it

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

Usage

The $snackbard prototype is built on 4 basic methods:

$snackbard.show(payload)

$snackbard.loading() // with an optional payload, see below

$snackbard.cancel() // with an optional payload, see below

$snackbard.success() // again, payload optional

$snackbard.error() // payload optional

Let's go over each method in greater detail.

$snackbard.show(payload)

| Key Value | Description | Default | Accepted Type | |-------------- |:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |---------- |------------------------------------------------------------------------------------------------- | | buttonColor | This is the color that the text of the button will appear as. The "button" is always text. | white | String (hex values or any of the 140 supported color names) | | buttonText | This is the text of the button on the right hand side of the snackbar. The button is confined to a certain space, so longer buttonText values will wrap on to a new line. Also, the button will always be text-transformed to upper-case. | CLOSE | String | | color | The color of the background of the snackbar. This can be one of four predetermined colors: error, success, info,,or warning, or a custom hex string | #2c2c2c | String (hex values, 140 supported color names, or 4 predetermined colors described to the left) | | loading | A boolean meaning whether or not an indeterminate spinning circle should be shown in the place of a button. Important: when this boolean is set to true, the snackbar will never timeout. It must be cancelled in the code in order for it to be dismissed. | false | Boolean | | position | The position of the snack bar. Only top and bottom are supported. | 'top' | String ('top' or 'bottom') | | spinnerSize | The size of the diameter of the loading circle. This value does nothing if the loading value is false. | 24 | String | Number | | spinnerColor | The color of the loading circle. This value does nothing if the loading value is false. | #ffffff | String (hex value, 140 supported color names) | | text | This is the text that will appear in the snackbar. There is no limit to how long it can be, but the maximum width of the entire snackbar is 500px so anything beyond that will wrap around onto a new line. | '' | String | | timeout | A number in milliseconds that the snackbar will persist before it will self-dismiss. Important: set this value to 0 if you want the snackbar to persist indefinitely (until the user closes it). | 3000 | Number (milliseconds) | | onClick | The method that should be run when the button on the snackbar is pressed. Clicking this button will always dismiss the snackbar in addition to whatever other action you mandate it to perform. Remember: If you are passing in a predefined method, you must wrap that method in a parent method otherwise the method will be called whenever the object is examined. Examples below. | () => {} | Function |

doSomeSuperForbiddenThing () {
	if (personIsAwesome) {
		this.$snackbard.show({ text: 'Congratulations! You are awesome. Enjoy this 10 second appreciation of your awesomeness', color: 'success', buttonText: 'OK!', timeout: 10000 })
	} else if (!personIsAwesome) {
		this.$snackbard.show({ text: 'You are not awesome. Admit it, and then learn how to become awesome.', color: 'error', buttonText: 'teach me', onClick: () => { this.teachUser() }, timeout: 0 })
	}
}
teachUser () {
	this.teachUserHowToBeAwesomeDialog = true
}

The above information should be most of what you need to know in order to operate the plugin. The following methods are subsets of that method made available for convenience.

snackbard.loading()

This method is a quick and easy way to display a loading snackbar with default text (Loading...) and a spinner. Programatically, the following two expressions are identical:

this.$snackbard.loading() === this.$snackbard.show({ text: 'Loading...', loading: true })

If you are satisfied with default, then you can simply call this.$snackbard.loading() to display it.

However, you can modify the loading snackbar with any of the above parameters in a payload. For example, if you wanted to change the text that is displayed when loading, you would run:

$snackbard.loading({ text: 'Fetching your info...' })

Or, if you wanted to keep the default text, but wanted the spinner to be larger and the background color to be different, you would run:

$snackbard.loading({ spinnerSize: 50, color: 'darkgrey' })

Important notes:

  • When you call loading, the timeout parameter is nullified. Setting loading = true will override any value you pass in for timeout. As such...
  • Loading snackbars must always be manually closed programmatically using this.$snackbard.cancel()

snackbard.cancel()

The purpose of this method is to cancel a loading snackbar that is called earlier in the code. An example of what this would look like is as follows:

created () {
	this.$snackbard.loading()
	this.$axios.get('/some/info/from/api').then(response => {
		this.$snackbard.cancel()
		this.foo = response.data.foo
		this.bar = response.data.bar
	})
}

There might be times when you want to notify the user after their information is done loading. In these instances, you can pass the text parameter into an optional payload, along with a color parameter, and when the loading is complete, the information in the snackbar will change to show the color and text provided, and then the snackbar will self-dismiss after the default 3000 milliseconds.

For example, in addition to code above, if you wanted to notify the user that there was actually an error downloading your information, you might add something like this:

	this.$snackbard.loading()
	this.$axios.get('/some/info/from/api').then(response => {
		this.$snackbard.cancel()
		this.foo = response.data.foo
		this.bar = response.data.bar
	}).catch(err => {
		this.$snackbard.cancel({ text: 'There was a problem getting your info!', color: 'error' })
		console.log(err)
	})
}

Important notes:

  • The only parameters you can pass to a $snackbard.cancel payload are text and color, all others will be ignored.

$snackbard.success()

$snackbard.success() === $snackbard.show({ text: 'Success!', color: 'success' })

$snackbard.error()

$snackbard.error() === $snackbard.show({ text: 'Error!', color: 'error' })

Gotchas

onClick()

parameter As mentioned above, you should not pass a predefined method directly as a value for this parameter. Doing so will cause that method to be run whenever the payload object is used at all. Instead, you should wrap it in a parent method.

For example, this will cause unexpected results:


created () {
	this.$snackbard.show({ text: 'Click here for more info.', buttonText: 'INFO', onClick: this.showMoreInfo() })
}
methods: {
	showMoreInfo () {
		console.log('These are not the droids you\'re looking for')
	}
}

Instead, you should pass the method in as such:


created () {
	this.$snackbard.show({ text: 'Click here for more info.', buttonText: 'INFO', onClick: () => { this.showMoreInfo() } })
}
methods: {
	showMoreInfo () {
		console.log('These are not the droids you\'re looking for')
	}
}

Contributing

yarn install yarn build

An informal list of things that need to be done:

  • Write tests & integrate with TravisCI
  • The plugin currently has one dependency -- the loading spinner. I'd love to build that out natively and remove all dependencies.
  • Clean up design a little bit

Author

Hi, that's me, Josh Menden. Feel free to reach out to me with any questions.

Contributors

  • Bryan Muller
  • David DeGraw