Git Product home page Git Product logo

sheeptoasts's Introduction

SheepToasts

Light weight and simple custom alerts (toasts) in pure JavaScript. You have to use Animate.css, to use animations of toasts.

Version 1.1

  • Added zIndex for SheepToasts's root.
  • Corrected appending toasts and their buttons.

Constructor

var SheepToasts = new SheepToasts(options);
  • options - The configuration. [object]

Options

  • animation - Names of animations for "In" and "Out". [object] [Default: none]
{
  in: 'fadeIn', //Default: none
  out: 'fadeOut', //Default: none
  duration: '1s' //Default: 0.5s
}
  • sort - This have to set on "top" (new toasts on top) or "bottom (new toasts on bottom) [string] [Default: bottom]
  • toastMargin - Space between toasts in pixels [integer] [Default: 4]
  • delayRemove - The time (in ms) after which toast will be removed (Not working, if toast have buttons) [function] [Default: 5000]
  • zIndex - Layer [integer] [Default: 1000]
  • cssMain - Basic CSS of toasts. [object] [Default: below]
{
  display: 'inline-block',
  maxWidth: '320px',
  padding: '5px 8px',
  position: 'fixed',
  top: 'auto',
  right: '32px',
  bottom: '32px',
  left: 'auto',
  borderRadius: '3px',
  wordBreak: 'break-all',
  fontFamily: 'cursive, sans-serif',
  fontSize: '13px',
  cursor: 'pointer',
  transition: 'top 0.32s, bottom 0.32s'
}
  • cssButtons - Basic CSS of buttons. [object] [Default: below]
{
  display: 'inline-block',
  height: '20px',
  margin: '-3px 0 0 3px',
  padding: '0 5px',
  verticalAlign: 'middle',
  whiteSpace: 'nowrap',
  border: 'none',
  borderRadius: '10px',
  fontFamily: 'inherit',
  fontSize: '11px',
  cursor: 'pointer'
}
  • cssModes - Can you add custom mode or edit existing. [object] [Default: success/info/warning]
//Simple example on "success" mode:
success: {
  color: '#fafeff',
  background: '#27ae60',
  textShadow: '#1e7744 1px 2px 1px',
  _buttons: {
    color: '#fafeff',
    textShadow: '#185833 0px 0px 3px',
    background: '#5ac17f'
  }
}

##Methods

###show(mode, message, animation, buttons)

  • mode - success, info, warning or your custom modes. [string] [Required]
  • message - message [string] [Required]
  • animation - Name of animation for show toast. [string] [Default: Using animation from global options]
  • buttons - Buttons [object] [Default: none]
//Example:
SheepToasts.show('info', 'We use cookies to give you the best experience on our website.', null, {
  ok: { //Id of button: SheepToast-button-ok
    value: 'Accept', //Text in button
    callback: function(){
      console.log(this.id+' has been clicked!');
      SheepToasts.close(this.toastid);
    }
  }
});

###success(message, animation, buttons) Alias for show() with set mode on "success".

###info(message, animation, buttons) Alias for show() with set mode on "info".

###warning(message, animation, buttons) Alias for show() with set mode on "warning".

###close(id, animation)

  • id - Id of toast. Each toast have id "SheepToast-NumberOfToast", for example "SheepToast-1". [string] [Required]
  • animation - Name of animation for close toast. [string] [Default: Using animation from global options]

##Some examples

###Show success toast:

SheepToasts.success('All right.');

###"Are you sure?" toast

SheepToasts.warning('Are you sure?', null, {
  yes: {
    value: 'Yes',
    callback: function(){
    	alert('You are sure!');
      SheepToasts.close(this.toastId);
    }
  },
  no: {
  	value: 'No',
    callback: function(){
    	SheepToasts.close(this.toastId);
    }
  }
});

##License MIT License

Copyright (c) 2017 Kysune

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

sheeptoasts's People

Contributors

szymonlisowiec avatar

Watchers

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