1.0.0 • Published 2 years ago

@firstfleet/toastedjs v1.0.0

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Introduction

toastedjs is heir of vue-toasted it is responsive, touch compatible, easy to use, attractive and feature rich with icons, actions etc...

Interactive demo

demo here

Installation

SourceInfo
npmnpm install toastedjs --save
yarnyarn add toastedjs
unpkg (js)https://unpkg.com/toastedjs/dist/toasted.min.js
unpkg (css)https://unpkg.com/toastedjs/dist/toasted.min.css
jsdelivrhttps://jsdelivr.com/package/npm/toastedjs

Basic Usage

ES6

import Toasted from 'toastedjs'

import 'toastedjs/dist/toastedjs.min.css'  
//import 'toastedjs/src/sass/toast.scss'

let toasted = new Toasted({ /* your options.. */ })
toasted.show('yo, toasted here !!')

Direct

<!-- pull the css -->
<link rel="stylesheet" href="https://unpkg.com/toastedjs/dist/toasted.min.css">

<!-- pull the js file -->
<script src="https://unpkg.com/toastedjs/dist/toasted.min.js"></script>

<script>
    var toasted = new Toasted({ /* your options.. */ })
    toasted.show('yo, toasted is directly here !!')
</script>

Guide

Actions

Actions are used to make the toasts interactive (save, undo, cancel, close), you can have one or more options on a single toast.

// you can pass multiple actions as an array of actions
action : {
     text : 'Save',
     onClick : (e, toasted) => {
        toasted.delete()
     }
}

⬇ check action api below

Icons

Material Icons supported. you will have to import the icon packs into your project.

{
    // pass the icon name as string
    icon : 'check'
    
    // or you can pass an object
    icon : {
        name : 'watch',
        after : true // this will append the icon to the end of content
    }
}

⬇ check icons api below

Api

Options

below are the options you can pass to create a toast or you can set these options globally.

// you can pass options either
let toasted = new Toasted({
    position : 'top-center',
    theme : 'alive',
    onComplete : () => {
        console.log('i am done !')
    }
})
OptionType'sDefaultDescription
positionString'top-right'Position of the toast container  'top-right', 'top-center', 'top-left', 'bottom-right', 'bottom-center', 'bottom-left'
durationNumbernullDisplay time of the toast in millisecond
actionObject, Arraynull⬇ check action api below
fullWidthBooleanFALSEEnable Full Width
fitToScreenBooleanFALSEFits to Screen on Full Width
classNameString, ArraynullCustom css class name of the toast
containerClassString, ArraynullCustom css classes for toast container
IconString, Objectnull⬇ check icons api below
typeString'default'Type of the Toast  'success', 'info', 'error'
themeString'primary'Theme of the toast you prefer 'primary', 'outline', 'bubble'
onCompleteFunctionnullTrigger when toast is completed

Actions

ParametersType'sDefaultDescription
text*String-name of action
hrefStringnullurl of action
iconStringnullname of material for action
classString/Arraynullcustom css class for the action
onClickFunction(e,toastObject)nullonClick Function of action

Icons

ParametersType'sDefaultDescription
name*String-name of the icon
colorStringnullcolor of the icon
afterBooleannullappend the icon to end of the toast

Methods

Methods available under ToastedJS

// you can pass string or html to message
let toasted = new Toasted({ /* global options */ })
toasted.show( 'my message', { /* some new option */ })
MethodParameter'sDescription
showmessage*, optionsShow a toast
successmessage*, optionsShow a toast success style
infomessage*, optionsShow a toast info style
errormessage*, optionsShow a toast error style
registername, messagestring,function(payload)* , optionsRegister your own toast with options explained here
groupoptionsCreate a new group of toasts (new toast container with its options)
clear-Clear all toasts

Toast Instance (Single toast instance)

Each Toast Returns a Toast Instance where you can manipulate the toast.

let toasted = new Toasted()

let myToast = toasted.show("Holla !!")
myToast.text("Changing the text !!!").delete(1500)

let anotherToast = toasted.error("Oopss.. my bad !")
anotherToast.text("Oopss.. it's okey..")
OptionType'sDescription
optionsObjectOptions of the toast instance
toastHTMLElementHtml Element of the toast
textFunction(message)Change text of the toast
deleteFunction(delay = 300)Delete the toast with animation and delay
destroyFunctionDestroy the toast unregister from parent instance

Browsers support

IE / EdgeFirefoxChromeSafariOperaiOS SafariChrome for Android
IE10, IE11, Edgelast 7 versionslast 7 versionslast 7 versionslast 7 versionslast 3 versionslast 3 versions

Please Open and issue If You have Found any Issues.

Mobile Responsiveness

On Mobile Toasts will be on full width. according to the position the toast will either be on top or bottom.

Credits

  • Inspired and developed from materialize-css toast.
  • Uses hammerjs for touch events
  • Uses lightweight and fast animejs for animations.
  • Whoever contributes to this project :wink:

Enjoy Toasting !!