Battledash-2 / Notifications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No name yet 😥

Notifications

Notifications is a customizable, appealing, and stylistic notification system.
Using Fontawesome, you can use tons of clean icons.

Usage

To use Notifications, first import the stylesheets in the head, like this:

<link rel="stylesheet" href="https://Battledash-2.github.io/Notifications/src/styles.css" />
<!-- or href="https://cdn.jsdelivr.net/gh/Battledash-2/Notifications@latest/src/styles.css" /> -->

To send notifications, import the file using the ES6 import syntax. Remember that you can only import scripts within modules, so on your script tag you have to use type="module"!

<script type="module">
	import * as Notifications from 'https://Battledash-2.github.io/Notifications/src/script.js'; // or 'https://cdn.jsdelivr.net/gh/Battledash-2/Notifications@latest/src/script.js';

	Notifications.ShowNotification(null, 'warning', Infinity, 'Hello!', 'INFO');
</script>

API

Notifications will be referred to as API.

API.remove(elm: HTMLElement): void;

  • Removes notification elm from the screen, while still showing the transition out.

API.ShowNotification(icon = 'fa-regular fa-bell', color = 'info', duration = 5000, text = 'Unknown', caption = 'Unknown', closable = true): HTMLElement;

  • Creates a new notifications and adds it to the screen.
    Returns the created element.

API.NotifExists(icon: string, color: string, text: string, caption: string): HTMLElement | null;

  • Checks if a notifications with the provided properties exists.
    Returns null or the element found.

Configuration

function Max(max?: number): number;

  • Sets the max amount of notifications on the screen at once if provided.
    Returns the new max.

function CounterMax(max?: number): number;

  • Sets the max amount for the small counter if provided.
    Returns the new counter max.

    function Types(typs?: Object): Object;

  • Sets the default types object if provided. The types object is a set of key/values, and each key is a type of notification. For example:

	info: {
		icon: 'fa-solid fa-circle-info',
		color: '#333333',
		caption: 'INFO',
	},
  • . With that, if you pass 'info' into the color parameter of the API.ShowNotification, it will set the color to the color from the object. If the icon parameter is null, it will also use the icon from the object. Same goes for the caption. When color is null or undefined, it will default to primary.
    Returns the new colors object.
  • Default types are: 'info', 'primary', 'success', 'error', 'warning' (all types must be lowercase)

You can find an example in ./test/index.html! 🧪

Pictures:

example picture
example picture

About


Languages

Language:JavaScript 62.8%Language:CSS 29.1%Language:HTML 8.2%