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-bootstrap-easy-dialog

v0.3.3

Published

React Bootstrap Dialog made easy

Downloads

52

Readme

React Bootstrap Easy Dialog

React Bootstrap Dialog made easy!

Introduction

Based on react-bootstrap modal, this package created a set of apis, which are similar to the standard window.alert, window.confirm and window.prompt, which cover 80% of dialog usage.

Demo

Demo

demo

Installation

npm i react-bootstrap-easy-dialog

You also need the depended packages:

npm i react react-bootstrap

Usage

Use hook style

import { DialogProvider, useDialog } from "react-bootstrap-easy-dialog";

function App() {
  return (
    <DialogProvider>
      <Page />
    </DialogProvider>
  );
}

function Page() {
  const dialog = useDialog();

  function handleClick() {
    dialog.alert("Awesome!");
  }

  return <button onClick={handleClick}>Alert</button>;
}

Render prop style

import { Dialog } from "react-bootstrap-easy-dialog";

function App() {
  return (
    <Dialog>
      {dialog => {
        async function handleClick() {
          const confirmed = await dialog.confirm("Buy a Huawei Mate 30 pro?");
          console.log(confirmed);
        }
        return <button onClick={handleClick}>Confirm</button>;
      }}
    </Dialog>
  );
}

Context style

import { DialogProvider, DialogConsumer } from "react-bootstrap-easy-dialog";

function App() {
  return (
    <DialogProvider>
      <DialogConsumer>
        {dialog => {
          async function handleClick() {
            const reason = await dialog.prompt("Why do you like it?", {
              title: "The Reason",
              defaultValue: "It has 5G."
            });
            console.log(reason);
          }
          return <button onClick={handleClick}>Prompt</button>;
        }}
      </DialogConsumer>
    </DialogProvider>
  );
}

Advanced Usage

Wait until hidden

Generally, dialog would return as soon as canceling or confirming gets triggered, by this time, the dialog is still in the animation, so calling another dialog would fail directly.

However, you can explicitly wait until it gets hidden completely.

const confirmed = await dialog.confirm('Delete your home?').hidden; // it would resolve after the dialog is completely hidden
const inputName = await dialog.prompt('Confirm the home name'); // or await dialog.prompt(...).done

APIs

  • dialog.alert : async (text, options?) => boolean

    Generally it would returns true, but if stubborn is set to false and the dialog is closed by clicking the background, it would return false

  • dialog.confirm : async (text, options?) => boolean
  • dialog.prompt : async (text, options?) => string | null

    If the user confirm or submit the dialog, it returns a string, otherwise it returns null

Options

The following options can be passed into Dialog, DialogProvider as the props, or dialog.alert, dialog.confirm, dialog.prompt as the second argument.

  • title? : string
  • inputProps? : object // options passed into the underlining Form.Control
  • cancelButtonProps? : object // options passed into the underlining Button
  • confirmButtonProps? : object // options passed into the underlining Button
  • autoFocus = 'select' : boolean | 'select'
  • stubborn = false : boolean // if true, clicking the background would not trigger canceling

Advanced Usage

See Demo.

License

MIT