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

js-snackbar

v1.1.2

Published

Custom Material Design inspired SnackBar notifications

Downloads

452

Readme

js-snackbar

Custom SnackBar notifications inspired by Material Design and node-snackbar

Installation

$ npm install js-snackbar -P

Usage

import 'js-snackbar/snackbar.css';
import { show, ACTION_TYPE } from 'js-snackbar';

// basic example
show({ text: 'My Message' });

// add a custom class to override styles, use the icon close button, display a face notify icon
show({
  text: 'Some Custom Text!',
  pos: 'top-right',
  customClass: 'custom-class',
  notifyIcon: 'face',
  actionType: ACTION_TYPE.CLOSE,
});

// override background
show({ text: 'Custom Error Message!', backgroundColor: '#F44336' });

// override onActionClick
show({
  text: 'Override!',
  actionType: ACTION_TYPE.TEXT,
  onActionClick: element => {
    element.style.opacity = 0;
    console.log('dang!');
  },
});

Find additional examples in src/App.js

Requirements

In order to display the notify icons and icon close button, we rely on Material Design icons, Google fonts, and Material Design Lite stylesheets.

If your project is not already referencing these, you can add the following to the <head> section of your index.html file.

    <link rel="stylesheet"
          href="https://fonts.googleapis.com/css?family=Roboto:regular,bold,italic,thin,light,bolditalic,black,medium&amp;lang=en">
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.indigo-pink.min.css">

Please note these are only required to use notifyIcon = 'some_md_icon' and actionType = ACTION_TYPE.CLOSE

Configuration

The following attributes can be customized

{
  // The SnackBar message to display
  text: 'Default Text',

  // Color of the SnackBar text
  textColor: '#ffffff',

  // The SnackBar container width
  width: 'auto',

  /**
   * The type of action button
   *  NONE: no button TEXT: text button CLOSE: close icon button
   */
  actionType: ACTION_TYPE.NONE,

  // Sets the button text when ACTION_TYPE.TEXT
  actionText: 'Dismiss',

  // Color of the action text
  actionTextColor: '#ffffff',

  // SnackBar background color
  backgroundColor: '#323232',

  /**
   * SnackBar display position
   *   'bottom-left', 'bottom-center', 'bottom-right', 'top-left', 'top-center', 'top-right'
   */
  pos: 'bottom-right',

  // milliseconds to display the SnackBar
  duration: 5000,

  // pause and restart duration after mouse hover
  pauseOnHover: false,

  // Class to apply to the SnackBar - this can be used to override all styles
  customClass: '',

  // Material Design icon to display to the left of the SnackBar text
  notifyIcon: null,

  // Url of an image to display to the left of the SnackBar text (beta)
  imgSrc: null,

  // Invoked when the SnackBar action button is clicked
  onActionClick: (element) => {
    element.style.opacity = 0;
  },

  // Invoked when the SnackBar itself is clicked
  onSnackbarClick: (element) => {
    element.style.opacity = 0;
  },

  // Invoked when the SnackBar closed via timing out
  onTimeout: (element) => {
    alert('Snackbar closed due to timeout!');
  },
}

Run Locally

start local server @ http://localhost:8080. The start script copies the index.js file to src/snackbar.js.

$ npm start

Build updated css

$ npm run build-css

Inspiration

This repo was lovingly forked and hacked from the awesome node-snackbar

A few of the changes:

  • Ability to use an action icon button
  • Ability to display a notify icon
  • Ability to display a notify image
  • Local React hacking environment