GithubHelp home page GithubHelp logo

aoricom / paper-snackbar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from justinribeiro/paper-snackbar

1.0 2.0 0.0 24 KB

Polymer 2 web component providing brief feedback about an operation through a message at the bottom of the screen that is loosely based on the Material Design spec.

License: MIT License

HTML 100.00%

paper-snackbar's Introduction

<paper-snackbar>

Published on webcomponents.org

Providing brief feedback about an operation through a message at the bottom of the screen that is loosely based on the Material Design spec.

Usage

<paper-snackbar> sits at the top level of your application and listens for a custom event called paper-snackbar-notify. The basic steps for using it are:

  1. Find a nice place to put it in your application. I usually choose my top level app element.

  2. Call paper-snackbar-notify via this.dispatchEvent(new CustomEvent('paper-snackbar-notify', ...));.

  3. Yipee, snackbar shows up!

Demo

<style is="custom-style">
  paper-snackbar {
    --paper-snackbar-background:     #323232;
    --paper-snackbar-text:           #ffffff;
    --paper-snackbar-link:           #f4cb1e;
  }
</style>

<paper-snackbar></paper-snackbar>

<button onclick="test()">Click Me</button>

<script>
  function test() {
    document.dispatchEvent(new CustomEvent('paper-snackbar-notify', {
        bubbles: true, 
        composed: true,
        detail: { 
          message: 'Hi! I am a paper-snackbar!', 
          targetTitle: 'Magic Link',
          targetUrl: '#'
        }
    }));
  }
</script>

Styling

The following custom properties and mixins are available for styling:

Custom property Description Default
--paper-snackbar-background Background color to entire element #323232
--paper-snackbar-text Color applied to element text #ffffff
--paper-snackbar-link Color applied to link element text #f4cb1e

Using the mixin

Presuming you have a lot of forms or elements that just want to send snackbar messages all day long, you can also use the class mixin.

  1. Import paper-snackbar-mixin.html into your element:
<link rel="import" href="../bower_components/paper-snackbar/paper-snackbar-mixin.html">
  1. Extend from PaperSnackbarNotify():
class MyMagicalElement extends PaperSnackbarNotify(Polymer.Element) {}
  1. When you want to use the snackbar, just call this.paperSnackbarNotify():
this.paperSnackbarNotify('Your record was added.', 'view', '/some/link/you/want');

Why?

This is largely based on what was in the Polymer SHOP demo. Then I decided I wanted this more global thing I could just call when shuffling forms in and out, so it got a little API. Then it was because I keep recreating this and over again in various ways and I'm really tired of copy and paste.

If you're looking for something with less of an opinion and more on the Material spec, you may also want to take a look at paper-toast.

paper-snackbar's People

Contributors

justinribeiro avatar

Stargazers

Keyth M Citizen  avatar

Watchers

James Cloos avatar Makha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.