# promise-confirmation-dialog

> Custom confirmation dialogue, implemented using promise

Latest version **1.0.10** (published 2023-02-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install promise-confirmation-dialog
pnpm add promise-confirmation-dialog
yarn add promise-confirmation-dialog
bun add promise-confirmation-dialog
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2023-02-28 |
| First published | 2022-09-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Beso Kakulia |
| Maintainers | besokakulia |
| Keywords | react, confirmation, dialog, popup, javascript, confirmation-dialog |

## Links

- npm: https://www.npmjs.com/package/promise-confirmation-dialog
- Repository: https://github.com/BesoKakulia/confirmation-dialog
- Homepage: https://github.com/BesoKakulia/confirmation-dialog#readme
- Issues: https://github.com/BesoKakulia/confirmation-dialog/issues
- npm.io page: https://npm.io/package/promise-confirmation-dialog

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.10 (latest) — 2023-02-28
- 1.0.9 — 2022-09-29
- 1.0.8 — 2022-09-28
- 1.0.7 — 2022-09-28
- 1.0.6 — 2022-09-28
- 1.0.5 — 2022-09-28
- 1.0.4 — 2022-09-28
- 1.0.3 — 2022-09-28
- 1.0.2 — 2022-09-28
- 1.0.1 — 2022-09-28
- 1.0.0 — 2022-09-28

## README

## **_React Confirmation Dialog_**

Custom React confirmation dialog, that implements similar functionality to window.confirm. <br>

<br>

### Installation

`npm i promise-confirmation-dialog`

<br>

<br>

### 💩 Native

<br>

```jsx
function Component() {

    function delete() {
        const confirmed = window.confirm("Do you really want to delete 📦?")

        if(confirmed){
            ...process..
        }
    }

}

```

<br>

### 🚀 Custom

<br>

```jsx
import { useDialog } from "promise-confirmation-dialog";

function Component() {
    const { showDialog } = useDialog();

    async function delete() {
        const confirmed = await showDialog("Do you really want to delete 📦"?)

        if(confirmed){
            ...process..
        }
    }

}

```

<br>

### 📚 Interface

`useDialog()` returns two properties, `showDialog` and `dialog`.

<br>

`showDialog` method takes message as argument, sets dialog state and returns promise.

`dialog` is confirmation dialog state, which has following interface

```jsx
{
    isOpen: boolean,
    message: string,
    confirm: resolve,
    cancel: reject
}
```

<br>

### 🚚 To use the custom confirmation dialog, you must wrap your app with context provider.

```jsx
import { ConfirmationDialogProvider } from "promise-confirmation-dialog";

const root = ReactDOM.createRoot(
  document.getElementById("root") as HTMLElement
);

root.render(
  <React.StrictMode>
    <ConfirmationDialogProvider>
      <App />
    </ConfirmationDialogProvider>
  </React.StrictMode>
);

```

<br>

### 🤸 Example

```jsx
import React from "react";
import "./App.scss";
import { useDialog } from "promise-confirmation-dialog";
import Modal from "react-modal";

const customStyles = {
  content: {
    top: "50%",
    left: "50%",
    right: "auto",
    bottom: "auto",
    marginRight: "-50%",
    transform: "translate(-50%, -50%)",
  },
};
function App() {
  const { showDialog, dialog } = useDialog();

  const handleDownload = async () => {
    const confirmed = await showDialog(
      "Are you sure, you want to download page"
    );

    if (confirmed) {
      window.alert("Download...");
    }
  };

  return (
    <div className="App">
      <button className="button trigger" onClick={handleDownload}>
        Download Page
      </button>
      <Modal
        isOpen={dialog.isOpen}
        onRequestClose={dialog.cancel}
        style={customStyles}
      >
        <div className="dialog">
          {dialog.message}
          <div className="dialog-footer">
            <button className="button cancel" onClick={dialog.cancel}>
              Cancel
            </button>
            <button className="button confirm" onClick={dialog.confirm}>
              Confirm
            </button>
          </div>
        </div>
      </Modal>
    </div>
  );
}

export default App;
```

---
_Source: https://npm.io/package/promise-confirmation-dialog · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
