1.0.4 • Published 2 years ago

toast-for-web v1.0.4

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

Toast for Web

npm version License: MIT

Show toast messages in your web application easily, with a simple package.

That means, you can show an element with a message in your web application, which will disappear after a certain amount of time.

Features

  • Show toast messages in your web application easily
  • Show toast messages with different levels
  • Show toast messages with different durations
  • Click on the toast to dismiss it

Installation

npm i toast-for-web

Usage

import showToast from "https://unpkg.com/toast-for-web@1.0.3/dist/index.js";
showToast(message, level, duration);

Parameters

ParameterTypeDescription
messagestringMessage to show in the toast
levelstringLevel of the toast, can be success, warning or error
durationnumberDuration of the toast in milliseconds

Example

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Toast for Web</title>
    <!-- CSS and JavaScript for the package -->
    <link rel="stylesheet" href="https://unpkg.com/toast-for-web@1.0.3/dist/style.css" />
    <script type="module" src="index.js"></script>
  </head>

  <body>
    <button id="success-toast">Success Toast</button>
    <button id="warning-toast">Warning Toast</button>
    <button id="error-toast">Error Toast</button>
  </body>
</html>

index.js

import showToast from "https://unpkg.com/toast-for-web@1.0.3/dist/index.js";

const successToast = document.getElementById("success-toast");
const warningToast = document.getElementById("warning-toast");
const errorToast = document.getElementById("error-toast");

document.addEventListener("click", (event) => {
  if (event.target === successToast)
    showToast("This is an info toast", "info", 3000);

  if (event.target === warningToast)
    showToast("This is a warning toast", "warning", 3000);

  if (event.target === errorToast)
    showToast("This is an error toast", "error", 3000);
});

Demo

View demo here: Demo

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Author

Coder Suresh

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago