npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@easylibs/flash

v1.1.20

Published

Flash is a lightweight, easy-to-use library for displaying Flash messages in your web application. It provides a simple API for creating and displaying Flash messages, and it comes with a variety of built-in templates that you can use to customize the loo

Downloads

80

Readme

Flash: A JavaScript Library for Creating Flash Messages

Flash is a lightweight, easy-to-use library for displaying Flash messages in your web application. It provides a simple API for creating and displaying Flash messages, and it comes with a variety of built-in templates that you can use to customize the look and feel of your messages.

GitHub stars GitHub issues npm version License jsDelivr downloads

Installation

To install Flash, simply add the following script tag to your HTML document:

<!--MINIFIED-->
<script src="https://cdn.jsdelivr.net/npm/@easylibs/flash@latest/dist/flash.min.js"></script>
<script src="https://unpkg.com/@easylibs/flash@latest/dist/flash.min.js"></script>
<!-- OR UNMINIFIED-->
<script src="https://cdn.jsdelivr.net/npm/@easylibs/flash@latest/dist/flash.js"></script>
<script src="https://unpkg.com/@easylibs/flash@latest/dist/flash.js"></script>

Or using npm, pnpm or yarn:

npm install @easylibs/flash
# OR
pnpm add @easylibs/flash
# OR
yarn add @easylibs/flash

Usage

To use Flash, simply call the Flash.add() method and pass in the options for your Flash message. The following code shows how to create a simple Flash message:

import Flash from '@easylibs/flash';

Flash.add({
  message: 'Hi, i am your success message',
  title: "Successful",
  type: 'success',
  icon:true,
  closeButton:true
});

This will create a Flash message with the text "Hi, i am your success message" and display it in a green box.

Hello world init flash message

You can also pass in additional options to the Flash.add() method to customize the look and feel of your Flash message. The following table lists all of the available options:

| Option | Description | |---|---| | message | The text of the Flash message. | | type | The type of Flash message. Can be one of the following: success, danger, warning, or info. | | duration | The duration of the Flash message in milliseconds. | | title | The title of the Flash message. | | closeButton | Whether or not to show a close button on the Flash message. | | container | The container in which to display the Flash message. | | icon | Whether or not to show an icon on the Flash message. | | tone | Whether or not to use a tone on the Flash message. |

Customizing Flash Messages

You can customize the appearance of flash messages by overriding the default CSS styles. The default CSS styles are located in the flash.css file.

Templates

The Flash message library offers two main approaches for displaying flash messages in your application. Below, you'll find an overview of each method along with a code snippet for implementation.

Using the Default Templates

Flash comes with a variety of built-in templates that you can use to customize the look and feel of your Flash messages. To use a template, simply set the template number to the TEMPLATE variable of the Flash class. The following code shows how to use the default template:

import Flash from '@easylibs/flash';

Flash.TEMPLATE = 2;
Flash.add({
  message: 'Hi, i am your danger message',
  type: 'danger',
  title: "failed !",
  icon:true
});

flash message appearance

Overriding the Default Template

You can customize the appearance of your flash messages by overriding the default template. This involves providing your own HTML structure and specifying locations for the title and message. Additionally, you can manage the close button functionality by adding the _close_ attribute to the desired element. Note that this approach allows you to override the default CSS, provided you use the same class names as in the default template.

body{
  background-color: #F2F3F5;
  box-sizing: border-box;
  padding:0;
  margin: 0;
}
.flash-box{
  width:200px;
  background-color: #FFFFFF;
  padding: 15px;
  margin:15px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.400);
  border-radius: 3px;
}
.custom-flash-header {
    display: flex;
    justify-content: center;
    align-items: center;
}
.custom-flash-header span{
  display: flex;
  justify-content: center;
  align-items: center;

}
svg{
  width:20px;
  height:20px;
}
.flash-box, .custom-body{
  display:flex;
  flex-direction:column;
  justify-content:center;
}
.custom-body h3, .custom-body p{
  text-align:center;
  color:#333;
  font-size:20px;
  font-weight:600;
}
button{
  width:100%;
  height:35px;
  color:#FFFFFF;
  background-color:#720026;
  border:none;
  border-radius:3px;
  outline:none;
  cursor:pointer;
}
import Flash from '@easylibs/flash';

Flash.TEMPLATE = `
<div class="custom-body">
    <div class="custom-flash-header">
        <h3>{{title}}</h3>
        <span>{{icon}}</span>
    </div>
    <p>{{message}}</p>
</div>
<button type="button" _close_>Close</button>`;

Flash.add({
  message: 'Hi, I am your info message',
  type: 'info',
  duration: 5000,
  title: 'Alert !',
  icon: true,
});

This will create a Flash message and display it in your custom templates.

flash message appearance

Attention

the order of execution is important in this case. If you want to override or change the default template, make sure that you set Flash.TEMPLATE before. In addition, two types of default templates are available and the title property is not supported by template 2 but only by template 1 and the custom template.

or add this code directly to your html, with the desired attributes. You will just need to execute the Flash.add() method without passing any parameters

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Flash</title>
</head>
<body>
  <flash 
    message="Hi, I am your warning message" 
    type="warning" 
    title="Ooops !" 
    duration="5000" 
    icon="true">
  </flash>
  </body>
</html>

Javascript

import Flash from "@easylibs/flash";
Flash.add()

flash message appearance