diff --git a/ignite-html-toast.js b/ignite-html-toast.js index c078e2f..ae899d7 100644 --- a/ignite-html-toast.js +++ b/ignite-html-toast.js @@ -1,22 +1,60 @@ -import { IgniteProperty } from "../ignite-html/ignite-html.js"; - +/** + * A utility class to create and show toast messages. + */ class Toast { + /** + * Creates and shows an info toast. + * @param {String} content The content of the toast. + * @param {Number} timeout The amount of time in miliseconds to show the message, -1 means forever. Default is 4000. + * @param {Boolean} closable Whether or not to show a close button. Default is true. + * @returns {HTMLElement} The toast html element. + */ static info(content, timeout = 4000, closable = true) { return this.makeToast("?", content, "info", timeout, closable); } + /** + * Creates and shows an warning toast. + * @param {String} content The content of the toast. + * @param {Number} timeout The amount of time in miliseconds to show the message, -1 means forever. Default is 4000. + * @param {Boolean} closable Whether or not to show a close button. Default is true. + * @returns {HTMLElement} The toast html element. + */ static warning(content, timeout = 4000, closable = true) { return this.makeToast("!", content, "warning", timeout, closable); } + /** + * Creates and shows an error toast. + * @param {String} content The content of the toast. + * @param {Number} timeout The amount of time in miliseconds to show the message, -1 means forever. Default is 4000. + * @param {Boolean} closable Whether or not to show a close button. Default is true. + * @returns {HTMLElement} The toast html element. + */ static error(content, timeout = 4000, closable = true) { return this.makeToast("×", content, "error", timeout, closable); } + /** + * Creates and shows an success toast. + * @param {String} content The content of the toast. + * @param {Number} timeout The amount of time in miliseconds to show the message, -1 means forever. Default is 4000. + * @param {Boolean} closable Whether or not to show a close button. Default is true. + * @returns {HTMLElement} The toast html element. + */ static success(content, timeout = 4000, closable = true) { return this.makeToast("✔", content, "success", timeout, closable); } + /** + * Creates a toast message with an icon, content, type, and timeout and closable settings. + * @param {String} icon The icon to display if any. + * @param {String} content The content of the toast. + * @param {String} type The type of toast being shown, error, warning, info, success, or default. + * @param {Number} timeout The amount of time in miliseconds to show the toast. -1 is forever. + * @param {Boolean} closable Whether or not this toast can be closed. + * @returns {HTMLElement} The toast html element. + */ static makeToast(icon, content, type, timeout, closable) { var color = ""; if (type == "error") { @@ -27,6 +65,8 @@ class Toast { color = "#2196f3"; } else if (type == "success") { color = "#10c469"; + } else { + color = "#000000"; } document.querySelectorAll(".ignite-html-toast").forEach(element => element.remove());