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

async-modals-lib.js

v0.0.30

Published

Async Modals Lib

Downloads

39

Readme

Async Modals Library

This library provides simple API, and highly customizable way to implement modals in your application. With built-in handling for asynchronous actions, it supports alert modals with customizable success and error states, a user confirmation step with customizable OK and Cancel buttons, a prompt modal component which allows users to enter data. image

No dependencies

Live demo

gzip

Installation

Use the package manager npm or yarn to install Async Modals Library.

npm install async-modals-lib.js
# or
yarn add async-modals-lib.js

Usage

Alert

import alertModal from 'async-modals-lib.js';

const options = {
  title: 'Your Title',
  message: 'Your Message',
  type: 'success', // or 'error'
  timeout: 3000, // in milliseconds, optional
  okText: 'OK', // text for the OK button, optional
  root: document.body, // the parent for the modal, optional
  closable: true, // whether the modal can be closed by user interaction, optional
  animation: 'slide', // type of animation for the modal display, optional 'ease' | 'slide' | 'verticalSlide'
  width: '400px' // width of the modal, optional
};

const result = await alertModal(options)
// return true

Confirm

import confirmModal from 'async-modals-lib.js';

const options = {
  title: 'Your Title',
  message: 'Your Message',
  okText: 'Yes', // text for the Yes button, optional
  cancelText: 'No', // text for the No button, optional
  root: document.body, // the parent for the modal, optional
  closable: true, // whether the modal can be closed by user interaction, optional
  animation: 'slide', // type of animation for the modal display, optional 'ease' | 'slide' | 'verticalSlide'
  width: '400px' // width of the modal, optional
};

const isConfirmed = await confirmModal(options)
// return true or false 

Prompt

import promptModal from 'async-modals-lib.js';

const options = {
  title: 'Your Title',
  message: 'Your Message',
  okText: 'Submit', // text for the Submit button, optional
  defaultValue: '', // default input value, optional
  placeholder: 'Your Placeholder', // placeholder for the input, optional
  root: document.body, // the parent for the modal, optional
  closable: true, // whether the modal can be closed by user interaction, optional
  animation: 'slide', // type of animation for the modal display, optional 'ease' | 'slide' | 'verticalSlide'
  width: '400px' // width of the modal, optional
};

const inputText = await promptModal(options)

Custom Styles

You can easily customize the look and feel of your modals by overriding the styles. Each element of the modals has a specific class assigned, and you can target these classes in your CSS to apply custom styles. The CSS classes are:

  • Alert Modal: .amljs-alert-title, .amljs-alert-icon, .amljs-alert-message, .amljs-alert-button, .amljs-button, .amljs-button--ok, .amljs-button--cancel, .amljs-alert-message--error, .amljs-alert-message--success
  • Confirm Modal: .amljs-confirm-title, .amljs-confirm-message, .amljs-button, .amljs-confirm-button, .amljs-button--ok, .amljs-button--cancel
  • Prompt Modal: .amljs-prompt-title, .amljs-prompt-message, .amljs-prompt-input, .amljs-button, .amljs-prompt-button, .amljs-button--ok

Please note that your custom styles should be loaded after the library styles to ensure they take precedence. If you are using CSS modules or a similar methodology, you may need to apply a higher specificity or use !important to override the default styles.

Here is an example of how you can override the styles:

.amljs-alert-button {
  background-color: #ff6347;
  color: white;
}

.amljs-alert-title {
  font-size: 2em;
}

.amljs-prompt-input {
  border: 2px solid #ff6347;
}

In the above example, the alert button is styled with a tomato background and white text. The alert title font size is increased, and the prompt input field has a tomato border.

Feel free to style your modals as you see fit to match your project's design!

License

MIT

Contributing

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

Support

If you encounter any problems or have suggestions, please open an issue.