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

snackbar-popup

v0.1.4

Published

This component is built on top of the Material UI Snackbar and implemented using a custom hook and React Context provider for reusability. Material UI, as well as many other public front-end libraries, is exceptionally developed and well documented, but w

Downloads

6

Readme

Snackbar-Popup

This component is built on top of the Material UI Snackbar and implemented using a custom hook and React Context provider for reusability. Material UI, as well as many other public front-end libraries, is exceptionally developed and well documented, but whenever we go to implement a component, a snackbar in this case, the developer needs to write too much boilerplate to make it work every single time.

The solution

The premise of this snackbar is to reduce the code necessary to implement the same Material UI Snackbar you know and love by defining a global provider using just a base React Context, so we can link snackbars and trigger notifications with simple function call.

Example:

// index.js
import React from 'react'
import { SnackbarProvider } from 'snackbar-popup'

import App from './components/App'

ReactDOM.render(
  <React.StrictMode>
    <SnackbarProvider>
    <App />
    </SnackbarProvider>
  </React.StrictMode>,
  document.getElementById('root')
);


// App.js
import React from 'react'
import { useSnackbar } from 'snackbar-popup'

const App = () => {
    const snackbar = useSnackbar()

    return (
        <div>
            <button onClick={() => snackbar({type: 'success', message: 'Successfully completed'})} />
            <button onClick={() => snackbar({type: 'error', message: 'There was an error when updating'})} />
        </div>
    )
}

As you can see in the example above, once your app has been wrapped with <SnackbarProvder /> you can use the useSnackbar hook anywhere in order to implement the function call to render the success or error notification.

Getting Started

This is a React component (built for hooks) and it is built on top of the Material UI Dialog so it uses the following dependencies:

  1. React 16.8 or higher.
  2. Material UI (latest).

To install, make sure your .npm config file is pointing to the Genesis Professional Group artifact registry so that Yarn/NPM know to look there before going to the public NPM registry.

In your cli run:

Using yarn yarn add snackbar-popup

Using npm npm i snackbar-popup

Features

The snackbar will simply display a 3-second notification at the bottom center of the screen. When passing a type success or error it will toggle the color green or red and allow you to send in a custom message.

Overriding the default icons

To have the snackbar override the default success and error icons, all you need to do is define the specified className in the useSnackbar hook (first argument is for the success and second is for the error):

const Component = () => {
  const snackbar = useSnackBar("fas fa-thumbs-up", "fas fa-times")
/*...*/

The code above will simply override the default fontawesome icon, that is originally set.

Original classNames set by default are: "fas fa-check-circle" and "fas fa-exclamation-circle"

Options

  • useSnackBar returns a function that allows you to render the snackbar notification. The function takes in an objects wil the following keys:

    • type string: Passing "success" will render the snackbar green with the success icon and error will render the snackbar red and error icon.
    • message string: Passing a custom message to render inside of the snackbar when rendered.
    • autoHideDuration number: Option to override the original auto hide duration of 3 seconds.

Contribute

All committed code must be 100% covered by unit tests and it's subject to review and approval by David Colatti.