Git Product home page Git Product logo

toast's Introduction

Toast - A Bootstrap 5.0 jQuery plugin

About

As of Bootstrap 4.2, toasts have been introduced and the aim of this plugin is to make them easier to use. (original)

Updates

As Bootstrap was updated to version 5.0(beta), the usage of the toast component changed. So, we fixed some code that was not compatible with Bootstrap 4 and added some new features.

  • Bootstrap Core updated to 5.0(beta)
  • Deleted incompatible codes and fixed
  • jQuery updated to latest version
  • Icon and more background colors are supported
  • Minor code errors and mistakes fixed

Usage

Global Variables (or default values)

Modify the global variables to apply specific rules/styles to all your toasts.

// default option values
$.toastDefaults = {
    position: "top-right",
    dismissible: true,
    stackable: true, // stackable & pauseDelayOnHover options are incompatible
    pauseDelayOnHover: false,
    style: {
        // user custom style classname
        toast: "",
        info: "",
        success: "",
        warning: "",
        error: "",
        primary: "",
        secondary: "",
        light: "",
        dark: "",
    },
};

Initializing Global Variables

Option Name Type Description Values
$.toastDefaults.position String Set toast & snack position from the container(or viewport). 'top-right' | 'top-center' | 'top-left' | 'bottom-right' | 'bottom-center' | 'bottom-left' (middle option currently not-supported)
$.toastDefaults.dismissible Boolean Enables toast & snack dismissible with dismiss button. true | false
$.toastDefaults.stackable Boolean Enables toast & snack stackable. (not compatible with 'pauseDelayOnHover' option.) true | false
$.toastDefaults.pauseDelayOnHover Boolean Enables toast & snack to stop auto-hide when hover mouse pointer on specific toast or snack. (not compatible with 'stackable' option.) true | false
// plugin initializing function
$.toastInit = function (opts) {
    const { position, dismissible, stackable, pauseDelayOnHover } = opts;

    // set values
    $.toastDefaults.position = position ?? $.toastDefaults.position;
    $.toastDefaults.dismissible = dismissible ?? $.toastDefaults.dismissible;
    $.toastDefaults.stackable = stackable ?? $.toastDefaults.stackable;
    $.toastDefaults.pauseDelayOnHover = pauseDelayOnHover ?? $.toastDefaults.pauseDelayOnHover;

    // check incompatible variables
    if ($.toastDefaults.stackable) {
        $.toastDefaults.pauseDelayOnHover = false;
    } else {
        $.toastDefaults.pauseDelayOnHover = true;
    }
};
// initializing example in sample.html
$.toastInit({
    position: "bottom-center",
    dismissible: true,
    stackable: true, // stackable & pauseDelayOnHover options are incompatible
    pauseDelayOnHover: false,
});

Snack (customized toast)

$.snack = function (type, content, delay) {
    return render({
        type,
        content,
        delay,
    });
};

Note: The final argument delay is omittable (optional). If omitted, the toast will remain forever.

Toast

$.toast({
    type: type,
    title: title,
    subtitle: "11 mins ago",
    content: content,
    delay: 5000,
    icon: "fab fa-github", // font-awesome6 icon class
    img: {
        src: IMG_URL,
        alt: "Image",
    },
});

Note: The icon and img options are compatible but not recommended to use them together.


Live Example (from Netlify)

Live Demo

live-demo


Contributing

Feel free to contribute in any of the ways outlined:

  • Submit issues/pull requests
  • Tell us how you're using this plugin in your project

@Script47/Toast

Contributors

Thanks to all contributors.

@yuiopna, @shd5632, @Phudal

toast's People

Contributors

script47 avatar soyanyan avatar shd5632 avatar phudal avatar yuiopna avatar draane avatar tip2tail avatar lolhens avatar lhns avatar

Watchers

James Cloos avatar  avatar

Forkers

yuiopna

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.