Coder Social home page Coder Social logo

abukaka / ion-snackbar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from flaviocolonna/ion-snackbar

0.0 2.0 0.0 18 KB

The new type of Android notification in Ionic.

License: GNU Affero General Public License v3.0

CSS 28.77% HTML 4.64% JavaScript 66.59%

ion-snackbar's Introduction

ion-snackbar

Example

View example in my Plunker Desk

Description

The new type of Android notification in Ionic. This component is new in the material design and it is supposed to be an alternative of the Toasts. Its style is really simple but in the same time complicated if you want to follow the material design guidelines written in Google Material Design, as I did. This component is optimized both for mobile and tablet. You can customize message text, message color, button text, button color, button function and then, thanks to promises, you are able to detect when the Snackbar disappears in order to call your own function.

How to use:

First of all load the javascript file of the snackbar and related stylesheet:

<link href="pathToLib/snackbar.css" rel="stylesheet" type="text/css"/>
<script src="pathToLib/snackbar.js"></script>

Then add snackbar into your module as a dependency:

var myapp = angular.module('myapp',['snackbar'])

Then add the service $snackbar to the controller on which you want to use the snackbar functions.

myapp.controller("mycontroller", function($snackbar) {
    //my logic
})

Now let's see how to use properly the snackbar. To call the snackbar simply write this:

var options = {
    message: 'Hello World!',
    time: 'SHORT',
    buttonName: 'Close',
    messageColor: 'red',
    buttonColor: 'white',
    buttonFunction: helloWorld
}
$snackbar.show(options).then(function(value){
    console.log("Snackbar disappeared");
    // here you can call another function
})

/**
* Example of function you can call
*/
function helloWorld() {
    console.log("Hello world!")
}

In order to close the snackbar:

$snackbar.hide().

Here there are the options available for the 'show' function:

  • message (compulsory)
  • buttonName (optional)
  • buttonColor (optional but default #a1c2fa)
  • messageColor (optional but default WHITE)
  • time (optional but default SHORT)
  • buttonFunction (optional but default snackbar.hide())

The 'message' parameter inside the options object is compulsory and without it snackbar doesn't work, firing an exception. $snackbar it is also a promise so you can call:

$snackbar.show({message : 'hello'}).then(function(success){},function(error){})

to execute something after the snackbar disappears. Timing in snackbar is expressed by a string that could be ['SHORT','LONG','INDETERMINATE']; SHORT will be 3000 MS, LONG will be 8000 MS and INDETERMINATE will not close automatically the snackbar. When buttonName is not defined you will have a simple snackbar without button. Remember that usually snackbar allows multi-line in mobile but just one line in tablet. Don't put too large text in snackbar due to has not been created for that at the start.

Animation

Each animation use GPU acceleration to give a smoother movement, essential for hybrid apps like Ionic apps.

Dependecies

  • Roboto font style
  • Ng Animate

License

The code is licensed under MIT license. Check license.txt for further details.

Contacts

For any bug or improvement don't hesitate to contact me at my page here

DONE WITH ❤️

ion-snackbar's People

Contributors

flaviocolonna avatar abukaka avatar

Watchers

 avatar James Cloos 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.