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

react-async-modal

v0.2.0

Published

React Async Modal

Downloads

61

Readme

React Async Modal

A simple tool for creating modals with Promise style usage based on react-responsive-modal

Install

  • yarn: yarn add react-async-modal
  • npm: npm i react-async-modal --save

Usage example

// Importing
import asyncModal from 'react-async-modal';
import 'react-responsive-modal/styles.css';

// Setup default modal settings (optional)
asyncModal.setDefaultModalProps({
  showCloseIcon: false,
  style: {
    modal: {
      width: 500
    }
  }
});

// Defining modal component
class MyConfirm extends React.Component<{question: string, resolve(boolean): void, close(): void}> {
  render() {
    return <div>
      <h1>{this.props.question}</h1>
      <button onClick={()=>this.props.resolve(true)}>Confirm</button>
      <button onClick={()=>this.props.close()}>Close</button>
    </div>  
  }
}

// Calling modal with async/await style
const result = await asyncModal(MyConfirm, { question: 'Delete file?' }, { showCloseIcon: false });
console.log(result);

// Or with Promise style
asyncModal(MyConfirm, { question: 'Delete file?' }, { showCloseIcon: false }).then((payload) => {
  if(payload) {
      console.log('File was deleted!');
  }
});

There are two methods will be injected to props of MyConfirm component:

  • resolve method to send payload and close modal
  • close method to send null as payload and close modal

Modal customization

Use modalProps argument or asyncModal.setDefaultModalProps() method to pass props to react-responsive-modal

Available props: https://react-responsive-modal.leopradel.com/#props